2
#---------------------------------------------
5
# Utility script to install icons on a Linux desktop.
7
# Refer to the usage() function below for usage.
9
# Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
10
# Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
11
# Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
12
# Copyright 2006, Jeremy White <jwhite@codeweavers.com>
16
#---------------------------------------------
32
# Set GTK_UPDATE_ICON_CACHE to gtk-update-icon-cache executable path or
33
# to "-" if not found.
34
GTK_UPDATE_ICON_CACHE=
35
find_gtk_update_icon_cache()
37
[ -n "$GTK_UPDATE_ICON_CACHE" ] && return;
39
GTK_UPDATE_ICON_CACHE="-"
40
for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do
41
DEBUG 3 "Checking $x for gtk-update-icon-cache"
42
if [ -x "$x/gtk-update-icon-cache" ] ; then
43
DEBUG 1 "Found $x/gtk-update-icon-cache"
44
GTK_UPDATE_ICON_CACHE="$x/gtk-update-icon-cache"
50
# Start GNOME legacy workaround section
53
# GTK < 2.6 uses ~/.icons but not XDG_DATA_HOME/icons
54
# The availability of gtk-update-icon-cache is used as indication
55
# of whether the system is using GTK 2.6 or later
56
find_gtk_update_icon_cache
57
[ "$GTK_UPDATE_ICON_CACHE" != "-" ] && return 1;
61
update_icon_database()
64
touch "$1/.@NAME@-dummy"
65
rm -f "$1/.@NAME@-dummy"
67
# Don't create a cache if there wan't one already
68
if [ -f "$1/icon-theme.cache" ] ; then
69
find_gtk_update_icon_cache
70
if [ "$GTK_UPDATE_ICON_CACHE" != "-" ] ; then
71
DEBUG 1 "Running $GTK_UPDATE_ICON_CACHE -f -t \"$1\""
72
eval '$GTK_UPDATE_ICON_CACHE -f -t "$1"'$xdg_redirect_output
78
[ x"$1" != x"" ] || exit_failure_syntax
103
exit_failure_syntax "unknown command '$1'"
110
while [ $# -gt 0 ] ; do
120
if [ -z "$1" ] ; then
121
exit_failure_syntax "mode argument missing for --mode"
133
exit_failure_syntax "unknown mode '$1'"
140
if [ -z "$1" ] ; then
141
exit_failure_syntax "theme argument missing for --theme"
148
if [ -z "$1" ] ; then
149
exit_failure_syntax "size argument missing for --size"
151
if echo "$1" | grep '[^0-9]' > /dev/null 2> /dev/null; then
152
exit_failure_syntax "size argument must be numeric"
159
if [ -z "$1" ] ; then
160
exit_failure_syntax "context argument missing for --context"
171
exit_failure_syntax "unexpected option '$parm'"
175
if [ -n "$icon_name" ] ; then
176
exit_failure_syntax "unexpected argument '$parm'"
177
elif [ -n "$icon_file" ] ; then
180
if [ "$action" = "install" ] ; then
181
check_input_file "$parm"
190
if [ -z "$action" ] ; then
191
exit_failure_syntax "command argument missing"
195
if [ -z "$context" ] ; then
196
exit_failure_syntax "context argument missing"
199
if [ -n "$XDG_UTILS_INSTALL_MODE" ] ; then
200
if [ "$XDG_UTILS_INSTALL_MODE" = "system" ] ; then
202
elif [ "$XDG_UTILS_INSTALL_MODE" = "user" ] ; then
207
if [ -z "$mode" ] ; then
208
if [ `whoami` = "root" ] ; then
215
xdg_dir_name="icons/$theme"
217
xdg_user_dir="$XDG_DATA_HOME"
218
[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
219
xdg_user_prefix="$xdg_user_dir/icons"
220
xdg_user_dir="$xdg_user_dir/$xdg_dir_name"
224
xdg_system_dirs="$XDG_DATA_DIRS"
225
[ -n "$xdg_system_dirs" ] || xdg_system_dirs="/usr/local/share/:/usr/share/"
226
for x in `echo "$xdg_system_dirs" | sed 's/:/ /g'`; do
227
if [ -w $x/$xdg_dir_name ] ; then
228
xdg_global_prefix="$x/icons"
229
xdg_global_dir="$x/$xdg_dir_name"
233
[ -w $xdg_global_dir ] || xdg_global_dir=
237
if [ x"$mode" = x"user" ] ; then
238
xdg_base_dir="$xdg_user_dir"
239
#Gnome 2.8 supports ~/.icons but not XDG_DATA_HOME
240
if need_dot_icon_path ; then
241
dot_icon_dir="$HOME/.icons"
242
dot_base_dir="$dot_icon_dir/$theme"
245
xdg_base_dir="$xdg_global_dir"
246
if [ -z "$xdg_base_dir" ] ; then
247
exit_failure_operation_impossible "No writable system icon directory found."
251
if [ x"$action" = x"forceupdate" ] ; then
252
if [ -n "$icon_file" ] ; then
253
exit_failure_syntax "unexpected argument '$icon_file'"
255
update_icon_database $xdg_base_dir
256
if [ -n "$dot_icon_dir" ] ; then
257
if [ -d "$dot_icon_dir/" ] && [ ! -L "$dot_icon_dir" ] ; then
258
update_icon_database $dot_base_dir
264
if [ -z "$icon_file" ] ; then
265
if [ x"$action" = x"install" ] ; then
266
exit_failure_syntax "icon-file argument missing"
268
exit_failure_syntax "icon-name argument missing"
275
if [ -z "$size" ] ; then
276
exit_failure_syntax "the icon size must be specified with --size"
278
xdg_size_name="${size}x${size}"
280
if [ x"$action" = x"install" ] ; then
289
exit_failure_syntax "icon file to install must be a *.png or *.xpm file"
294
if [ -n "$icon_name" ] ; then
297
exit_failure_syntax "icon name should not include an extension"
300
exit_failure_syntax "icon name should not include an extension"
305
# Start KDE legacy workaround section
309
path=`readlink -f "$1" 2> /dev/null` # Normalize path
310
DEBUG 2 "need_kde_icon_path $path"
311
if [ -z "$path" ] ; then
312
DEBUG 2 "need_kde_icon_path RETURN 1 (not needed, no xdg icon dir)"
313
return 1; # Not needed
316
# if kde-config not found... return 0
317
kde_icon_dirs=`kde${KDE_SESSION_VERSION}-config --path icon 2> /dev/null |sed 's/:/ /g'`
318
DEBUG 3 "kde_icon_dirs: $kde_icon_dirs"
319
if [ -z "$kde_icon_dirs" ] ; then
320
DEBUG 3 "no result from kde${KDE_SESSION_VERSION}-config --path icon"
321
DEBUG 2 "need_kde_icon_path RETURN 1 (not needed, no kde icon path)"
322
return 1; # Not needed
325
for y in $kde_icon_dirs ; do
326
x=`readlink -f "$y"` # Normalize path
327
DEBUG 3 "Normalize $y --> $x"
328
if [ -n "$x" ] ; then
329
if [ "$x" = "$path" ] ; then
330
needed=1 # Not needed
332
if [ -w "$x" ] ; then
333
kde_global_prefix="$x"
334
# Take last writable dir
338
DEBUG 2 "kde_global_prefix: $kde_global_prefix"
339
[ $needed -eq "1" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (not needed)"
340
[ $needed -eq "0" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (needed)"
345
if [ x"$mode" = x"user" ] ; then
346
xdg_dir="$xdg_base_dir/$xdg_size_name/$context"
347
#KDE 3.x doesn't support XDG_DATA_HOME for icons
348
#Check if xdg_dir prefix is listed by kde-config --path icon
349
#If not, install additional symlink to kdedir
350
if need_kde_icon_path "$xdg_user_prefix" ; then
351
kde_user_icon_dir=`kde${KDE_SESSION_VERSION}-config --path icon | cut -d ':' -f 1`
352
kde_user_dir="$kde_user_icon_dir/$theme"
353
kde_dir="$kde_user_dir/$xdg_size_name/$context"
355
#Gnome 2.8 supports ~/.icons but not XDG_DATA_HOME
356
if [ -n "$dot_icon_dir" ] ; then
357
if [ -L "$dot_icon_dir" ] ; then
360
elif [ ! -d "$dot_icon_dir/" ] ; then
361
# Symlink if it doesn't exist
362
eval 'ln -s ".local/share/icons" "$dot_icon_dir"'$xdg_redirect_output
365
dot_icon_dir="$dot_icon_dir/$theme/$xdg_size_name/$context"
370
xdg_dir="$xdg_base_dir/$xdg_size_name/$context"
371
#KDE 3.x doesn't support XDG_DATA_DIRS for icons
372
#Check if xdg_dir prefix is listed by kde-config --path icon
373
#If not, install additional symlink to kdedir
374
if need_kde_icon_path "$xdg_global_prefix" ; then
375
kde_global_dir="$kde_global_prefix/$theme"
376
kde_dir="$kde_global_dir/$xdg_size_name/$context"
380
# End KDE legacy workaround section
382
# Start GNOME legacy workaround section
384
[ $context = "mimetypes" ] && need_gnome_mime=true
385
# End GNOME legacy workaround section
387
[ -n "$icon_name" ] || icon_name=`basename "$icon_file" | sed 's/\.[a-z][a-z][a-z]$//'`
389
if [ "$vendor" = "true" -a "$action" = "install" -a "$context" = "apps" ] ; then
390
check_vendor_prefix "$icon_name" "icon name"
393
icon_icon_file=`echo "$icon_file" | sed 's/\.[a-z][a-z][a-z]$/.icon/'`
394
icon_icon_name="$icon_name.icon"
396
DEBUG 1 "$action icon in $xdg_dir"
397
[ $action = "install" ] && [ -f $icon_icon_file ] && DEBUG 1 "install $icon_icon_name meta file in $xdg_dir"
398
[ -n "$kde_dir" ] && DEBUG 1 "$action symlink in $kde_dir (KDE 3.x support)"
399
[ -n "$need_gnome_mime" ] && DEBUG 1 "$action gnome-mime-$icon_name symlink (GNOME 2.x support)"
400
[ $action = "install" -a -n "$dot_icon_dir" ] && DEBUG 1 "$action ~/.icons symlink (GNOME 2.8 support)"
407
for icon_dir in $xdg_dir $dot_icon_dir; do
409
eval 'cp "$icon_file" "$icon_dir/$icon_name.$extension"'$xdg_redirect_output
410
if [ -f "$icon_icon_file" ] ; then
411
eval 'cp "$icon_icon_file" "$icon_dir/$icon_icon_name"'$xdg_redirect_output
413
if [ -n "$need_gnome_mime" ] ; then
414
eval 'ln -s "$icon_name.$extension" "$icon_dir/gnome-mime-$icon_name.$extension"'$xdg_redirect_output
417
if [ -n "$kde_dir" ] ; then
419
eval 'ln -s "$xdg_dir/$icon_name.$extension" "$kde_dir/$icon_name.$extension"'$xdg_redirect_output
426
for icon_dir in $xdg_dir $dot_icon_dir; do
427
rm -f "$icon_dir/$icon_name.xpm" "$icon_dir/$icon_name.png"
428
rm -f "$icon_dir/$icon_icon_name"
429
if [ -n "$need_gnome_mime" ] ; then
430
rm -f "$icon_dir/gnome-mime-$icon_name.xpm"
431
rm -f "$icon_dir/gnome-mime-$icon_name.png"
434
if [ -n "$kde_dir" ] ; then
435
rm -f "$kde_dir/$icon_name.xpm" "$kde_dir/$icon_name.png"
441
if [ x"$update" = x"yes" ] ; then
442
update_icon_database "$xdg_base_dir"
443
if [ -n "$dot_icon_dir" ] ; then
444
if [ -d "$dot_icon_dir/" ] && [ ! -L "$dot_icon_dir" ] ; then
445
update_icon_database $dot_base_dir