/build/icon-theme-installer
#! | 187 lines | 166 code | 21 blank | 0 comment | 0 complexity | b284d8c6be2e21377d2fd5fccf4155bf MD5 | raw file
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 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# -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 70 71while 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 82done 83 84shift $(($OPTIND - 1)) 85 86if test "x$INSTALL" = "xyes" -a "x$UNINSTALL" = "xyes"; then 87 echo "Cannot pass both -i and -u" 88 exit 1 89elif test "x$INSTALL" = "x" -a "x$UNINSTALL" = "x"; then 90 echo "Must path either -i or -u" 91 exit 1 92fi 93 94if test -z "$THEME_NAME"; then 95 echo "Theme name required (-t hicolor)" 96 exit 1 97fi 98 99if test -z "$INSTALL_BASE_DIR"; then 100 echo "Base theme directory required [-b \$(hicolordir)]" 101 exit 1 102fi 103 104if 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 107fi 108 109if 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 112fi 113 114if test -z "$SRC_DIR"; then 115 SRC_DIR=. 116fi 117 118for 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=symbolic 127 128 if [[ "${INSTALL_BASE_DIR}" == *ubuntu-mono-* ]]; then 129 install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$category/$size 130 else 131 install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$size/$category 132 fi 133 else 134 if [[ "${INSTALL_BASE_DIR}" == *ubuntu-mono-* ]]; then 135 install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$category/$size 136 else 137 size=${size}x${size}; 138 install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$size/$category 139 fi 140 fi 141 142 install_path=$install_dir/$install_name 143 144 if test "x$INSTALL" = "xyes"; then 145 echo "Installing $size $install_name into $THEME_NAME icon theme" 146 147 $($MKINSTALLDIRS_EXEC $install_dir) || { 148 echo "Failed to create directory $install_dir" 149 exit 1 150 } 151 152 $($INSTALL_DATA_EXEC $SRC_DIR/$build_name $install_path) || { 153 echo "Failed to install $SRC_DIR/$build_name into $install_path" 154 exit 1 155 } 156 157 if test ! -e $install_path; then 158 echo "Failed to install $SRC_DIR/$build_name into $install_path" 159 exit 1 160 fi 161 else 162 if test -e $install_path; then 163 echo "Removing $size $install_name from $THEME_NAME icon theme" 164 165 rm $install_path || { 166 echo "Failed to remove $install_path" 167 exit 1 168 } 169 fi 170 fi 171done 172 173gtk_update_icon_cache_bin="$((which gtk-update-icon-cache || echo /opt/gnome/bin/gtk-update-icon-cache)2>/dev/null)" 174gtk_update_icon_cache="$gtk_update_icon_cache_bin -f -t $INSTALL_BASE_DIR" 175 176if test -z "$INSTALL_DEST_DIR"; then 177 if test -x $gtk_update_icon_cache_bin; then 178 echo "Updating GTK icon cache" 179 $gtk_update_icon_cache 180 else 181 echo "*** Icon cache not updated. Could not execute $gtk_update_icon_cache_bin" 182 fi 183else 184 echo "*** Icon cache not updated. After (un)install, run this:" 185 echo "*** $gtk_update_icon_cache" 186fi 187