| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# icon-theme-installer |
| 4 |
# Copyright (C) 2006 Novell, Inc. |
| 5 |
# Written by Aaron Bockover <abock@gnome.org> |
| 6 |
# Licensed under the MIT/X11 license |
| 7 |
# |
| 8 |
# This script is meant to be invoked from within a Makefile/Makefile.am |
| 9 |
# in the install-data-local and uninstall-data sections. It handles the |
| 10 |
# task of properly installing icons into the icon theme. It requires a |
| 11 |
# few arguments to set up its environment, and a list of files to be |
| 12 |
# installed. The format of the file list is critical: |
| 13 |
# |
| 14 |
# <category>,<local-src-file-name> |
| 15 |
# |
| 16 |
# apps,music-player-banshee.svg |
| 17 |
# apps,music-player-banshee-16.png |
| 18 |
# apps,music-player-banshee-22.png |
| 19 |
# |
| 20 |
# <category> is the icon theme category, for instance, apps, devices, |
| 21 |
# actions, emblems... |
| 22 |
# |
| 23 |
# <local-src-file-name> must have a basename in the form of: |
| 24 |
# |
| 25 |
# proper-theme-name[-<SIZE>].<EXTENSION> |
| 26 |
# |
| 27 |
# Where <SIZE> should be either nothing, which will default to scalable |
| 28 |
# or \-[0-9]{2}, which will expand to <SIZE>x<SIZE>. For example: |
| 29 |
# |
| 30 |
# music-player-banshee-16.png |
| 31 |
# |
| 32 |
# The <SIZE> here is -16 and will expand to 16x16 per the icon theme spec |
| 33 |
# |
| 34 |
# What follows is an example Makefile.am for icon theme installation: |
| 35 |
# |
| 36 |
# --------------- |
| 37 |
# theme=hicolor |
| 38 |
# themedir=$(datadir)/icons/$(theme) |
| 39 |
# theme_icons = \ |
| 40 |
# apps,music-player-banshee.svg \ |
| 41 |
# apps,music-player-banshee-16.png \ |
| 42 |
# apps,music-player-banshee-22.png \ |
| 43 |
# apps,music-player-banshee-24.png \ |
| 44 |
# apps,music-player-banshee-32.png |
| 45 |
# |
| 46 |
# install_icon_exec = $(top_srcdir)/build/icon-theme-installer -t $(theme) -s $(srcdir) -d "x$(DESTDIR)" -b $(themedir) -m "$(mkinstalldirs)" -x "$(INSTALL_DATA)" |
| 47 |
# install-data-local: |
| 48 |
# $(install_icon_exec) -i $(theme_icons) |
| 49 |
# |
| 50 |
# uninstall-hook: |
| 51 |
# $(install_icon_exec) -u $(theme_icons) |
| 52 |
# |
| 53 |
# MAINTAINERCLEANFILES = Makefile.in |
| 54 |
# EXTRA_DIST = $(wildcard *.svg *.png) |
| 55 |
# --------------- |
| 56 |
# |
| 57 |
# Arguments to this program: |
| 58 |
# |
| 59 |
# -i : Install |
| 60 |
# -u : Uninstall |
| 61 |
# -t <theme> : Theme name (hicolor) |
| 62 |
# -b <dir> : Theme installation dest directory [x$(DESTDIR)] - Always prefix |
| 63 |
# this argument with x; it will be stripped but will act as a |
| 64 |
# placeholder for zero $DESTDIRs (only set by packagers) |
| 65 |
# -d <dir> : Theme installation directory [$(hicolordir)] |
| 66 |
# -s <dir> : Source directory [$(srcdir)] |
| 67 |
# -m <exec> : Command to exec for directory creation [$(mkinstalldirs)] |
| 68 |
# -x <exec> : Command to exec for single file installation [$(INSTALL_DATA)] |
| 69 |
# <remainging> : All remainging should be category,filename pairs |
| 70 |
|
| 71 |
while getopts "iut:b:d:s:m:x:" flag; do |
| 72 |
case "$flag" in |
| 73 |
i) INSTALL=yes ;; |
| 74 |
u) UNINSTALL=yes ;; |
| 75 |
t) THEME_NAME=$OPTARG ;; |
| 76 |
d) INSTALL_DEST_DIR=${OPTARG##x} ;; |
| 77 |
b) INSTALL_BASE_DIR=$OPTARG ;; |
| 78 |
s) SRC_DIR=$OPTARG ;; |
| 79 |
m) MKINSTALLDIRS_EXEC=$OPTARG ;; |
| 80 |
x) INSTALL_DATA_EXEC=$OPTARG ;; |
| 81 |
esac |
| 82 |
done |
| 83 |
|
| 84 |
shift $(($OPTIND - 1)) |
| 85 |
|
| 86 |
if test "x$INSTALL" = "xyes" -a "x$UNINSTALL" = "xyes"; then |
| 87 |
echo "Cannot pass both -i and -u" |
| 88 |
exit 1 |
| 89 |
elif test "x$INSTALL" = "x" -a "x$UNINSTALL" = "x"; then |
| 90 |
echo "Must path either -i or -u" |
| 91 |
exit 1 |
| 92 |
fi |
| 93 |
|
| 94 |
if test -z "$THEME_NAME"; then |
| 95 |
echo "Theme name required (-t hicolor)" |
| 96 |
exit 1 |
| 97 |
fi |
| 98 |
|
| 99 |
if test -z "$INSTALL_BASE_DIR"; then |
| 100 |
echo "Base theme directory required [-d \$(hicolordir)]" |
| 101 |
exit 1 |
| 102 |
fi |
| 103 |
|
| 104 |
if test ! -x $(echo "$MKINSTALLDIRS_EXEC" | cut -f1 -d' '); then |
| 105 |
echo "Cannot find '$MKINSTALLDIRS_EXEC'; You probably want to pass -m \$(mkinstalldirs)" |
| 106 |
exit 1 |
| 107 |
fi |
| 108 |
|
| 109 |
if test ! -x $(echo "$INSTALL_DATA_EXEC" | cut -f1 -d' '); then |
| 110 |
echo "Cannot find '$INSTALL_DATA_EXEC'; You probably want to pass -x \$(INSTALL_DATA)" |
| 111 |
exit 1 |
| 112 |
fi |
| 113 |
|
| 114 |
if test -z "$SRC_DIR"; then |
| 115 |
SRC_DIR=. |
| 116 |
fi |
| 117 |
|
| 118 |
for icon in $@; do |
| 119 |
size=$(echo $icon | sed s/[^0-9]*//g) |
| 120 |
category=$(echo $icon | cut -d, -f1) |
| 121 |
build_name=$(echo $icon | cut -d, -f2) |
| 122 |
install_name=$(echo $build_name | sed "s/[0-9]//g; s/-\././") |
| 123 |
install_name=$(basename $install_name) |
| 124 |
|
| 125 |
if test -z $size; then |
| 126 |
size=scalable; |
| 127 |
else |
| 128 |
size=${size}x${size}; |
| 129 |
fi |
| 130 |
|
| 131 |
install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$size/$category |
| 132 |
install_path=$install_dir/$install_name |
| 133 |
|
| 134 |
if test "x$INSTALL" = "xyes"; then |
| 135 |
echo "Installing $size $install_name into $THEME_NAME icon theme" |
| 136 |
|
| 137 |
$($MKINSTALLDIRS_EXEC $install_dir) || { |
| 138 |
echo "Failed to create directory $install_dir" |
| 139 |
exit 1 |
| 140 |
} |
| 141 |
|
| 142 |
$($INSTALL_DATA_EXEC $SRC_DIR/$build_name $install_path) || { |
| 143 |
echo "Failed to install $SRC_DIR/$build_name into $install_path" |
| 144 |
exit 1 |
| 145 |
} |
| 146 |
|
| 147 |
if test ! -e $install_path; then |
| 148 |
echo "Failed to install $SRC_DIR/$build_name into $install_path" |
| 149 |
exit 1 |
| 150 |
fi |
| 151 |
else |
| 152 |
if test -e $install_path; then |
| 153 |
echo "Removing $size $install_name from $THEME_NAME icon theme" |
| 154 |
|
| 155 |
rm $install_path || { |
| 156 |
echo "Failed to remove $install_path" |
| 157 |
exit 1 |
| 158 |
} |
| 159 |
fi |
| 160 |
fi |
| 161 |
done |
| 162 |
|
| 163 |
if test "x$INSTALL" = "xyes"; then |
| 164 |
gtk_update_icon_cache_bin="$((which gtk-update-icon-cache || echo /opt/gnome/bin/gtk-update-icon-cache)2>/dev/null)" |
| 165 |
gtk_update_icon_cache="$gtk_update_icon_cache_bin -f -t $INSTALL_BASE_DIR" |
| 166 |
|
| 167 |
if test -z "$INSTALL_DEST_DIR"; then |
| 168 |
if test -x $gtk_update_icon_cache_bin; then |
| 169 |
echo "Updating GTK icon cache" |
| 170 |
$gtk_update_icon_cache |
| 171 |
else |
| 172 |
echo "*** Icon cache not updated. Could not execute $gtk_update_icon_cache_bin" |
| 173 |
fi |
| 174 |
else |
| 175 |
echo "*** Icon cache not updated. After install, run this:" |
| 176 |
echo "*** $gtk_update_icon_cache" |
| 177 |
fi |
| 178 |
fi |