| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 #--------------------------------------------- | 2 #--------------------------------------------- |
| 3 # xdg-icon-resource | 3 # xdg-icon-resource |
| 4 # | 4 # |
| 5 # Utility script to install icons on a Linux desktop. | 5 # Utility script to install icons on a Linux desktop. |
| 6 # | 6 # |
| 7 # Refer to the usage() function below for usage. | 7 # Refer to the usage() function below for usage. |
| 8 # | 8 # |
| 9 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> | 9 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> |
| 10 # Copyright 2006, Jeremy White <jwhite@codeweavers.com> | 10 # Copyright 2006, Jeremy White <jwhite@codeweavers.com> |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 exit_failure_file_permission_read() | 286 exit_failure_file_permission_read() |
| 287 { | 287 { |
| 288 if [ $# -gt 0 ]; then | 288 if [ $# -gt 0 ]; then |
| 289 echo "xdg-icon-resource: $@" >&2 | 289 echo "xdg-icon-resource: $@" >&2 |
| 290 fi | 290 fi |
| 291 | 291 |
| 292 exit 5 | 292 exit 5 |
| 293 } | 293 } |
| 294 | 294 |
| 295 #------------------------------------------------------------ | 295 #------------------------------------------------------------ |
| 296 # Exit script on insufficient permission to read a specified file | 296 # Exit script on insufficient permission to write a specified file |
| 297 | 297 |
| 298 exit_failure_file_permission_write() | 298 exit_failure_file_permission_write() |
| 299 { | 299 { |
| 300 if [ $# -gt 0 ]; then | 300 if [ $# -gt 0 ]; then |
| 301 echo "xdg-icon-resource: $@" >&2 | 301 echo "xdg-icon-resource: $@" >&2 |
| 302 fi | 302 fi |
| 303 | 303 |
| 304 exit 6 | 304 exit 6 |
| 305 } | 305 } |
| 306 | 306 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 echo "Use 'man xdg-icon-resource' or 'xdg-icon-resource --manual' fo
r additional info." | 363 echo "Use 'man xdg-icon-resource' or 'xdg-icon-resource --manual' fo
r additional info." |
| 364 exit_success | 364 exit_success |
| 365 ;; | 365 ;; |
| 366 | 366 |
| 367 --manual) | 367 --manual) |
| 368 manualpage | 368 manualpage |
| 369 exit_success | 369 exit_success |
| 370 ;; | 370 ;; |
| 371 | 371 |
| 372 --version) | 372 --version) |
| 373 echo "xdg-icon-resource 1.0.1" | 373 echo "xdg-icon-resource 1.0.2" |
| 374 exit_success | 374 exit_success |
| 375 ;; | 375 ;; |
| 376 esac | 376 esac |
| 377 done | 377 done |
| 378 } | 378 } |
| 379 | 379 |
| 380 check_common_commands "$@" | 380 check_common_commands "$@" |
| 381 | 381 |
| 382 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; | 382 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; |
| 383 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then | 383 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then |
| 384 # Be silent | 384 # Be silent |
| 385 xdg_redirect_output=" > /dev/null 2> /dev/null" | 385 xdg_redirect_output=" > /dev/null 2> /dev/null" |
| 386 else | 386 else |
| 387 # All output to stderr | 387 # All output to stderr |
| 388 xdg_redirect_output=" >&2" | 388 xdg_redirect_output=" >&2" |
| 389 fi | 389 fi |
| 390 | 390 |
| 391 #-------------------------------------- | 391 #-------------------------------------- |
| 392 # Checks for known desktop environments | 392 # Checks for known desktop environments |
| 393 # set variable DE to the desktop environments name, lowercase | 393 # set variable DE to the desktop environments name, lowercase |
| 394 | 394 |
| 395 detectDE() | 395 detectDE() |
| 396 { | 396 { |
| 397 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; | 397 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
| 398 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; | 398 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
| 399 elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then
DE=xfce; | 399 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; |
| 400 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; |
| 400 fi | 401 fi |
| 401 } | 402 } |
| 402 | 403 |
| 403 #---------------------------------------------------------------------------- | 404 #---------------------------------------------------------------------------- |
| 404 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 | 405 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 |
| 405 # It also always returns 1 in KDE 3.4 and earlier | 406 # It also always returns 1 in KDE 3.4 and earlier |
| 406 # Simply return 0 in such case | 407 # Simply return 0 in such case |
| 407 | 408 |
| 408 kfmclient_fix_exit_code() | 409 kfmclient_fix_exit_code() |
| 409 { | 410 { |
| 410 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` | 411 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` |
| 411 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` | 412 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` |
| 412 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` | 413 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` |
| 413 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` | 414 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` |
| 414 test "$major" -gt 3 && return $1 | 415 test "$major" -gt 3 && return $1 |
| 415 test "$minor" -gt 5 && return $1 | 416 test "$minor" -gt 5 && return $1 |
| 416 test "$release" -gt 4 && return $1 | 417 test "$release" -gt 4 && return $1 |
| 417 return 0 | 418 return 0 |
| 418 } | 419 } |
| 419 | 420 |
| 420 # Set GTK_UPDATE_ICON_CACHE to gtk-update-icon-cache executable path or | 421 # Set GTK_UPDATE_ICON_CACHE to gtk-update-icon-cache executable path or |
| 421 # to "-" if not found. | 422 # to "-" if not found. |
| 422 GTK_UPDATE_ICON_CACHE= | 423 GTK_UPDATE_ICON_CACHE= |
| 423 find_gtk_update_icon_cache() | 424 find_gtk_update_icon_cache() |
| 424 { | 425 { |
| 425 [ -n "$GTK_UPDATE_ICON_CACHE" ] && return; | 426 [ -n "$GTK_UPDATE_ICON_CACHE" ] && return; |
| 426 | 427 |
| 427 GTK_UPDATE_ICON_CACHE="-" | 428 GTK_UPDATE_ICON_CACHE="-" |
| 428 for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do | 429 for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do |
| 429 DEBUG 3 "Checking $x for gtk-update-icon-cache" | 430 DEBUG 3 "Checking $x for gtk-update-icon-cache" |
| 430 if [ -x "$x/gtk-update-icon-cache" ] ; then | 431 if [ -x "$x/gtk-update-icon-cache" ] ; then |
| 431 DEBUG 1 "Found $x/gtk-update-icon-cache" | 432 DEBUG 1 "Found $x/gtk-update-icon-cache" |
| 432 GTK_UPDATE_ICON_CACHE="$x/gtk-update-icon-cache" | 433 GTK_UPDATE_ICON_CACHE="$x/gtk-update-icon-cache" |
| 433 return | 434 return |
| 434 fi | 435 fi |
| 435 done | 436 done |
| 436 } | 437 } |
| 437 | 438 |
| 438 # Start GNOME legacy workaround section | 439 # Start GNOME legacy workaround section |
| 439 need_dot_icon_path() | 440 need_dot_icon_path() |
| 440 { | 441 { |
| 441 # GTK < 2.6 uses ~/.icons but not XDG_DATA_HOME/icons | 442 # GTK < 2.6 uses ~/.icons but not XDG_DATA_HOME/icons |
| 442 # The availability of gtk-update-icon-cache is used as indication | 443 # The availability of gtk-update-icon-cache is used as indication |
| 443 # of whether the system is using GTK 2.6 or later | 444 # of whether the system is using GTK 2.6 or later |
| 444 find_gtk_update_icon_cache | 445 find_gtk_update_icon_cache |
| 445 [ "$GTK_UPDATE_ICON_CACHE" != "-" ] && return 1; | 446 [ "$GTK_UPDATE_ICON_CACHE" != "-" ] && return 1; |
| 446 return 0; | 447 return 0; |
| 447 } | 448 } |
| 448 | 449 |
| 449 update_icon_database() | 450 update_icon_database() |
| 450 { | 451 { |
| 451 # Touch me, I'm dirty | 452 # Touch me, I'm dirty |
| 452 touch "$1/.xdg-icon-resource-dummy" | 453 touch "$1/.xdg-icon-resource-dummy" |
| 453 rm -f "$1/.xdg-icon-resource-dummy" | 454 rm -f "$1/.xdg-icon-resource-dummy" |
| 454 | 455 |
| 455 # Don't create a cache if there wan't one already | 456 # Don't create a cache if there wan't one already |
| 456 if [ -f "$1/icon-theme.cache" ] ; then | 457 if [ -f "$1/icon-theme.cache" ] ; then |
| 457 find_gtk_update_icon_cache | 458 find_gtk_update_icon_cache |
| 458 if [ "$GTK_UPDATE_ICON_CACHE" != "-" ] ; then | 459 if [ "$GTK_UPDATE_ICON_CACHE" != "-" ] ; then |
| 459 DEBUG 1 "Running $GTK_UPDATE_ICON_CACHE -f -t \"$1\"" | 460 DEBUG 1 "Running $GTK_UPDATE_ICON_CACHE -f -t \"$1\"" |
| 460 eval '$GTK_UPDATE_ICON_CACHE -f -t "$1"'$xdg_redirect_output | 461 eval '$GTK_UPDATE_ICON_CACHE -f -t "$1"'$xdg_redirect_output |
| 461 return | 462 return |
| 462 fi | 463 fi |
| 463 fi | 464 fi |
| 464 } | 465 } |
| 465 | 466 |
| 466 [ x"$1" != x"" ] || exit_failure_syntax | 467 [ x"$1" != x"" ] || exit_failure_syntax |
| 467 | 468 |
| 468 mode= | 469 mode= |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 exit_failure_syntax "mode argument missing for --mode" | 510 exit_failure_syntax "mode argument missing for --mode" |
| 510 fi | 511 fi |
| 511 case "$1" in | 512 case "$1" in |
| 512 user) | 513 user) |
| 513 mode="user" | 514 mode="user" |
| 514 ;; | 515 ;; |
| 515 | 516 |
| 516 system) | 517 system) |
| 517 mode="system" | 518 mode="system" |
| 518 ;; | 519 ;; |
| 519 | 520 |
| 520 *) | 521 *) |
| 521 exit_failure_syntax "unknown mode '$1'" | 522 exit_failure_syntax "unknown mode '$1'" |
| 522 ;; | 523 ;; |
| 523 esac | 524 esac |
| 524 shift | 525 shift |
| 525 ;; | 526 ;; |
| 526 | 527 |
| 527 --theme) | 528 --theme) |
| 528 if [ -z "$1" ] ; then | 529 if [ -z "$1" ] ; then |
| 529 exit_failure_syntax "theme argument missing for --theme" | 530 exit_failure_syntax "theme argument missing for --theme" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 [ $needed -eq "1" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (not needed)
" | 728 [ $needed -eq "1" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (not needed)
" |
| 728 [ $needed -eq "0" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (needed)" | 729 [ $needed -eq "0" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (needed)" |
| 729 return $needed | 730 return $needed |
| 730 } | 731 } |
| 731 | 732 |
| 732 kde_dir= | 733 kde_dir= |
| 733 if [ x"$mode" = x"user" ] ; then | 734 if [ x"$mode" = x"user" ] ; then |
| 734 xdg_dir="$xdg_base_dir/$xdg_size_name/$context" | 735 xdg_dir="$xdg_base_dir/$xdg_size_name/$context" |
| 735 #KDE 3.x doesn't support XDG_DATA_HOME for icons | 736 #KDE 3.x doesn't support XDG_DATA_HOME for icons |
| 736 #Check if xdg_dir prefix is listed by kde-config --path icon | 737 #Check if xdg_dir prefix is listed by kde-config --path icon |
| 737 #If not, install additional symlink to kdedir | 738 #If not, install additional symlink to kdedir |
| 738 if need_kde_icon_path "$xdg_user_prefix" ; then | 739 if need_kde_icon_path "$xdg_user_prefix" ; then |
| 739 kde_user_dir="$HOME/.kde/share/icons/$theme" | 740 kde_user_icon_dir=`kde${KDE_SESSION_VERSION}-config --path icon | cut -d
':' -f 1` |
| 741 kde_user_dir="$kde_user_icon_dir/$theme" |
| 740 kde_dir="$kde_user_dir/$xdg_size_name/$context" | 742 kde_dir="$kde_user_dir/$xdg_size_name/$context" |
| 741 fi | 743 fi |
| 742 #Gnome 2.8 supports ~/.icons but not XDG_DATA_HOME | 744 #Gnome 2.8 supports ~/.icons but not XDG_DATA_HOME |
| 743 if [ -n "$dot_icon_dir" ] ; then | 745 if [ -n "$dot_icon_dir" ] ; then |
| 744 if [ -L "$dot_icon_dir" ] ; then | 746 if [ -L "$dot_icon_dir" ] ; then |
| 745 # Don't do anything | 747 # Don't do anything |
| 746 dot_icon_dir= | 748 dot_icon_dir= |
| 747 elif [ ! -d "$dot_icon_dir/" ] ; then | 749 elif [ ! -d "$dot_icon_dir/" ] ; then |
| 748 # Symlink if it doesn't exist | 750 # Symlink if it doesn't exist |
| 749 eval 'ln -s ".local/share/icons" "$dot_icon_dir"'$xdg_redirect_outpu
t | 751 eval 'ln -s ".local/share/icons" "$dot_icon_dir"'$xdg_redirect_outpu
t |
| 750 dot_icon_dir= | 752 dot_icon_dir= |
| 751 else | 753 else |
| 752 dot_icon_dir="$dot_icon_dir/$theme/$xdg_size_name/$context" | 754 dot_icon_dir="$dot_icon_dir/$theme/$xdg_size_name/$context" |
| 753 fi | 755 fi |
| 754 fi | 756 fi |
| 755 my_umask=077 | 757 my_umask=077 |
| 756 else | 758 else |
| 757 xdg_dir="$xdg_base_dir/$xdg_size_name/$context" | 759 xdg_dir="$xdg_base_dir/$xdg_size_name/$context" |
| 758 #KDE 3.x doesn't support XDG_DATA_DIRS for icons | 760 #KDE 3.x doesn't support XDG_DATA_DIRS for icons |
| 759 #Check if xdg_dir prefix is listed by kde-config --path icon | 761 #Check if xdg_dir prefix is listed by kde-config --path icon |
| 760 #If not, install additional symlink to kdedir | 762 #If not, install additional symlink to kdedir |
| 761 if need_kde_icon_path "$xdg_global_prefix" ; then | 763 if need_kde_icon_path "$xdg_global_prefix" ; then |
| 762 kde_global_dir="$kde_global_prefix/$theme" | 764 kde_global_dir="$kde_global_prefix/$theme" |
| 763 kde_dir="$kde_global_dir/$xdg_size_name/$context" | 765 kde_dir="$kde_global_dir/$xdg_size_name/$context" |
| 764 fi | 766 fi |
| 765 my_umask=022 | 767 my_umask=022 |
| 766 fi | 768 fi |
| 767 # End KDE legacy workaround section | 769 # End KDE legacy workaround section |
| 768 | 770 |
| 769 # Start GNOME legacy workaround section | 771 # Start GNOME legacy workaround section |
| 770 need_gnome_mime= | 772 need_gnome_mime= |
| 771 [ $context = "mimetypes" ] && need_gnome_mime=true | 773 [ $context = "mimetypes" ] && need_gnome_mime=true |
| 772 # End GNOME legacy workaround section | 774 # End GNOME legacy workaround section |
| 773 | 775 |
| 774 [ -n "$icon_name" ] || icon_name=`basename "$icon_file" | sed 's/\.[a-z][a-z][a-
z]$//'` | 776 [ -n "$icon_name" ] || icon_name=`basename "$icon_file" | sed 's/\.[a-z][a-z][a-
z]$//'` |
| 775 | 777 |
| 776 if [ "$vendor" = "true" -a "$action" = "install" -a "$context" = "apps" ] ; then | 778 if [ "$vendor" = "true" -a "$action" = "install" -a "$context" = "apps" ] ; then |
| 777 check_vendor_prefix "$icon_name" "icon name" | 779 check_vendor_prefix "$icon_name" "icon name" |
| 778 fi | 780 fi |
| 779 | 781 |
| 780 icon_icon_file=`echo "$icon_file" | sed 's/\.[a-z][a-z][a-z]$/.icon/'` | 782 icon_icon_file=`echo "$icon_file" | sed 's/\.[a-z][a-z][a-z]$/.icon/'` |
| 781 icon_icon_name="$icon_name.icon" | 783 icon_icon_name="$icon_name.icon" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 807 fi | 809 fi |
| 808 | 810 |
| 809 umask $save_umask | 811 umask $save_umask |
| 810 ;; | 812 ;; |
| 811 | 813 |
| 812 uninstall) | 814 uninstall) |
| 813 for icon_dir in $xdg_dir $dot_icon_dir; do | 815 for icon_dir in $xdg_dir $dot_icon_dir; do |
| 814 rm -f "$icon_dir/$icon_name.xpm" "$icon_dir/$icon_name.png" | 816 rm -f "$icon_dir/$icon_name.xpm" "$icon_dir/$icon_name.png" |
| 815 rm -f "$icon_dir/$icon_icon_name" | 817 rm -f "$icon_dir/$icon_icon_name" |
| 816 if [ -n "$need_gnome_mime" ] ; then | 818 if [ -n "$need_gnome_mime" ] ; then |
| 817 rm -f "$icon_dir/gnome-mime-$icon_name.xpm" | 819 rm -f "$icon_dir/gnome-mime-$icon_name.xpm" |
| 818 rm -f "$icon_dir/gnome-mime-$icon_name.png" | 820 rm -f "$icon_dir/gnome-mime-$icon_name.png" |
| 819 fi | 821 fi |
| 820 done | 822 done |
| 821 if [ -n "$kde_dir" ] ; then | 823 if [ -n "$kde_dir" ] ; then |
| 822 rm -f "$kde_dir/$icon_name.xpm" "$kde_dir/$icon_name.png" | 824 rm -f "$kde_dir/$icon_name.xpm" "$kde_dir/$icon_name.png" |
| 823 fi | 825 fi |
| 824 | 826 |
| 825 ;; | 827 ;; |
| 826 esac | 828 esac |
| 827 | 829 |
| 828 if [ x"$update" = x"yes" ] ; then | 830 if [ x"$update" = x"yes" ] ; then |
| 829 update_icon_database "$xdg_base_dir" | 831 update_icon_database "$xdg_base_dir" |
| 830 if [ -n "$dot_icon_dir" ] ; then | 832 if [ -n "$dot_icon_dir" ] ; then |
| 831 if [ -d "$dot_icon_dir/" -a ! -L "$dot_icon_dir" ] ; then | 833 if [ -d "$dot_icon_dir/" -a ! -L "$dot_icon_dir" ] ; then |
| 832 update_icon_database $dot_base_dir | 834 update_icon_database $dot_base_dir |
| 833 fi | 835 fi |
| 834 fi | 836 fi |
| 835 fi | 837 fi |
| 836 | 838 |
| 837 exit_success | 839 exit_success |
| OLD | NEW |