icon-theme-installer (5340B)
1 #!/usr/bin/env 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 33 # spec 34 # 35 # What follows is an example Makefile.am for icon theme installation: 36 # 37 # --------------- 38 # theme=hicolor 39 # themedir=$(datadir)/icons/$(theme) 40 # theme_icons = \ 41 # apps,music-player-banshee.svg \ 42 # apps,music-player-banshee-16.png \ 43 # apps,music-player-banshee-22.png \ 44 # apps,music-player-banshee-24.png \ 45 # apps,music-player-banshee-32.png 46 # 47 # install_icon_exec = $(top_srcdir)/build/icon-theme-installer -t 48 # $(theme) -s $(srcdir) -d "x$(DESTDIR)" -b $(themedir) -m 49 #"$(mkinstalldirs)" -x "$(INSTALL_DATA)" 50 # install-data-local: 51 # $(install_icon_exec) -i $(theme_icons) 52 # 53 # uninstall-hook: 54 # $(install_icon_exec) -u $(theme_icons) 55 # 56 # MAINTAINERCLEANFILES = Makefile.in 57 # EXTRA_DIST = $(wildcard *.svg *.png) 58 # --------------- 59 # 60 # Arguments to this program: 61 # 62 # -i : Install 63 # -u : Uninstall 64 # -t <theme> : Theme name (hicolor) 65 # -b <dir> : Theme installation dest directory [x$(DESTDIR)] - Always 66 # prefix 67 # this argument with x; it will be stripped but will act as 68 # placeholder for zero $DESTDIRs (only set by packagers) 69 # -d <dir> : Theme installation directory [$(hicolordir)] 70 # -s <dir> : Source directory [$(srcdir)] 71 # -m <exec> : Command to exec for directory creation [$(mkinstalldirs)] 72 # -x <exec> : Command to exec for single file installation 73 # [$(INSTALL_DATA)] 74 # <remainging> : All remainging should be category,filename pairs 75 76 while getopts "iut:b:d:s:m:x:" flag; do 77 case "$flag" in 78 i) INSTALL=yes ;; 79 u) UNINSTALL=yes ;; 80 t) THEME_NAME=$OPTARG ;; 81 d) INSTALL_DEST_DIR=${OPTARG##x} ;; 82 b) INSTALL_BASE_DIR=$OPTARG ;; 83 s) SRC_DIR=$OPTARG ;; 84 m) MKINSTALLDIRS_EXEC=$OPTARG ;; 85 x) INSTALL_DATA_EXEC=$OPTARG ;; 86 esac 87 done 88 89 shift $(($OPTIND - 1)) 90 91 if test "x$INSTALL" = "xyes" -a "x$UNINSTALL" = "xyes"; then 92 echo "Cannot pass both -i and -u" 93 exit 1 94 elif test "x$INSTALL" = "x" -a "x$UNINSTALL" = "x"; then 95 echo "Must path either -i or -u" 96 exit 1 97 fi 98 99 if test -z "$THEME_NAME"; then 100 echo "Theme name required (-t hicolor)" 101 exit 1 102 fi 103 104 if test -z "$INSTALL_BASE_DIR"; then 105 echo "Base theme directory required [-d \$(hicolordir)]" 106 exit 1 107 fi 108 109 if test ! -x $(echo "$MKINSTALLDIRS_EXEC" | cut -f1 -d' '); then 110 echo "Cannot find '$MKINSTALLDIRS_EXEC'; You probably want to 111 pass -m \$(mkinstalldirs)" 112 exit 1 113 fi 114 115 if test ! -x $(echo "$INSTALL_DATA_EXEC" | cut -f1 -d' '); then 116 echo "Cannot find '$INSTALL_DATA_EXEC'; You probably want to 117 pass -x \$(INSTALL_DATA)" 118 exit 1 119 fi 120 121 if test -z "$SRC_DIR"; then 122 SRC_DIR=. 123 fi 124 125 for icon in $@; do 126 size=$(echo $icon | sed s/[^0-9]*//g) 127 category=$(echo $icon | cut -d, -f1) 128 build_name=$(echo $icon | cut -d, -f2) 129 install_name=$(echo $build_name | sed "s/[0-9]//g; s/-\././") 130 install_name=$(basename $install_name) 131 132 if test -z $size; then 133 size=scalable; 134 else 135 size=${size}x${size}; 136 fi 137 138 139 install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$size/$category 140 install_path=$install_dir/$install_name 141 142 if test "x$INSTALL" = "xyes"; then 143 echo "Installing $size $install_name into $THEME_NAME 144 icon theme" 145 146 $($MKINSTALLDIRS_EXEC $install_dir) || { 147 echo "Failed to create directory $install_dir" 148 exit 1 149 } 150 151 $($INSTALL_DATA_EXEC $SRC_DIR/$build_name $install_path) || { 152 echo "Failed to install $SRC_DIR/$build_name 153 into $install_path" 154 exit 1 155 } 156 157 if test ! -e $install_path; then 158 echo "Failed to install $SRC_DIR/$build_name 159 into $install_path" 160 exit 1 161 fi 162 else 163 if test -e $install_path; then 164 echo "Removing $size $install_name from 165 $THEME_NAME icon theme" 166 167 rm $install_path || { 168 echo "Failed to remove $install_path" 169 exit 1 170 } 171 fi 172 fi 173 done 174 175 if test "x$INSTALL" = "xyes"; then 176 gtk_update_icon_cache_bin="$((which gtk-update-icon-cache || 177 echo /opt/gnome/bin/gtk-update-icon-cache)2>/dev/null)" 178 gtk_update_icon_cache="$gtk_update_icon_cache_bin -f -t 179 $INSTALL_BASE_DIR" 180 181 if test -z "$INSTALL_DEST_DIR"; then 182 if test -x $gtk_update_icon_cache_bin; then 183 echo "Updating GTK icon cache" 184 $gtk_update_icon_cache 185 else 186 echo "*** Icon cache not updated. Could not 187 execute $gtk_update_icon_cache_bin" 188 fi 189 else 190 echo "*** Icon cache not updated. After install, run 191 this:" 192 echo "*** $gtk_update_icon_cache" 193 fi 194 fi