/build/icon-theme-installer

http://github.com/hbons/SparkleShare · #! · 187 lines · 166 code · 21 blank · 0 comment · 0 complexity · b284d8c6be2e21377d2fd5fccf4155bf MD5 · raw file

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