Updated Slovenian translation
[banshee.git] / build / icon-theme-installer
blob02607882f50c473883436071d7141640f6038349
1 #!/usr/bin/env bash
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
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:
14 # <category>,<local-src-file-name>
16 # apps,music-player-banshee.svg
17 # apps,music-player-banshee-16.png
18 # apps,music-player-banshee-22.png
20 # <category> is the icon theme category, for instance, apps, devices,
21 # actions, emblems...
23 # <local-src-file-name> must have a basename in the form of:
25 # proper-theme-name[-<SIZE>].<EXTENSION>
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:
30 # music-player-banshee-16.png
32 # The <SIZE> here is -16 and will expand to 16x16 per the icon theme spec
34 # What follows is an example Makefile.am for icon theme installation:
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
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)
50 # uninstall-hook:
51 # $(install_icon_exec) -u $(theme_icons)
53 # MAINTAINERCLEANFILES = Makefile.in
54 # EXTRA_DIST = $(wildcard *.svg *.png)
55 # ---------------
57 # Arguments to this program:
59 # -i : Install
60 # -u : Uninstall
61 # -t <theme> : Theme name (hicolor)
62 # -d <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 # -b <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
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
84 shift $(($OPTIND - 1))
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
94 if test -z "$THEME_NAME"; then
95 echo "Theme name required (-t hicolor)"
96 exit 1
99 if test -z "$INSTALL_BASE_DIR"; then
100 echo "Base theme directory required [-b \$(hicolordir)]"
101 exit 1
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
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
114 if test -z "$SRC_DIR"; then
115 SRC_DIR=.
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)
125 if test -z $size; then
126 size=scalable;
127 else
128 size=${size}x${size};
131 install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$size/$category
132 install_path=$install_dir/$install_name
134 if test "x$INSTALL" = "xyes"; then
135 echo "Installing $size $install_name into $THEME_NAME icon theme"
137 $($MKINSTALLDIRS_EXEC $install_dir) || {
138 echo "Failed to create directory $install_dir"
139 exit 1
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
147 if test ! -e $install_path; then
148 echo "Failed to install $SRC_DIR/$build_name into $install_path"
149 exit 1
151 else
152 if test -e $install_path; then
153 echo "Removing $size $install_name from $THEME_NAME icon theme"
155 rm $install_path || {
156 echo "Failed to remove $install_path"
157 exit 1
161 done
163 gtk_update_icon_cache_bin="$((which gtk-update-icon-cache || echo /opt/gnome/bin/gtk-update-icon-cache)2>/dev/null)"
164 gtk_update_icon_cache="$gtk_update_icon_cache_bin -f -t $INSTALL_BASE_DIR"
166 if test -z "$INSTALL_DEST_DIR"; then
167 if test -x $gtk_update_icon_cache_bin; then
168 echo "Updating GTK icon cache"
169 $gtk_update_icon_cache
170 else
171 echo "*** Icon cache not updated. Could not execute $gtk_update_icon_cache_bin"
173 else
174 echo "*** Icon cache not updated. After (un)install, run this:"
175 echo "*** $gtk_update_icon_cache"