1#!/bin/sh 2#--------------------------------------------- 3# xdg-desktop-icon 4# 5# Utility script to install desktop items on a Linux desktop. 6# 7# Refer to the usage() function below for usage. 8# 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> 13# 14# LICENSE: 15# 16#--------------------------------------------- 17 18usage() 19{ 20cat << _USAGE 21_USAGE 22} 23 24manualpage() 25{ 26cat << _MANUALPAGE 27_MANUALPAGE 28} 29 30#@xdg-utils-common@ 31 32[ x"$1" != x"" ] || exit_failure_syntax 33 34action= 35desktop_file= 36 37case $1 in 38 install) 39 action=install 40 ;; 41 42 uninstall) 43 action=uninstall 44 ;; 45 46 *) 47 exit_failure_syntax "unknown command '$1'" 48 ;; 49esac 50 51shift 52 53vendor=true 54while [ $# -gt 0 ] ; do 55 parm=$1 56 shift 57 58 case $parm in 59 --novendor) 60 vendor=false 61 ;; 62 63 -*) 64 exit_failure_syntax "unexpected option '$parm'" 65 ;; 66 67 *) 68 if [ -n "$desktop_file" ] ; then 69 exit_failure_syntax "unexpected argument '$parm'" 70 fi 71 if [ "$action" = "install" ] ; then 72 check_input_file "$parm" 73 fi 74 desktop_file=$parm 75 ;; 76 esac 77done 78 79# Shouldn't happen 80if [ -z "$action" ] ; then 81 exit_failure_syntax "command argument missing" 82fi 83 84if [ -z "$desktop_file" ] ; then 85 exit_failure_syntax "FILE argument missing" 86fi 87 88filetype= 89case "$desktop_file" in 90 *.desktop) 91 filetype=desktop 92 if [ "$vendor" = "true" -a "$action" = "install" ] ; then 93 check_vendor_prefix "$desktop_file" 94 fi 95 ;; 96 *) 97 filetype=other 98 ;; 99esac 100 101my_umask=077 102desktop_dir="$HOME/Desktop" 103if xdg-user-dir 2>/dev/null 1>&2; then 104 desktop_dir=`xdg-user-dir DESKTOP` 105fi 106desktop_dir_kde=`kde${KDE_SESSION_VERSION}-config --userpath desktop 2> /dev/null` 107if gconftool-2 -g /apps/nautilus/preferences/desktop_is_home_dir 2> /dev/null | grep true > /dev/null; then 108 desktop_dir_gnome="$HOME" 109 # Don't create $HOME/Desktop if it doesn't exist 110 [ -w "$desktop_dir" ] || desktop_dir= 111fi 112if [ -n "$desktop_dir_kde" ]; then 113 if [ ! -d "$desktop_dir_kde" ]; then 114 save_umask=`umask` 115 umask $my_umask 116 mkdir -p "$desktop_dir_kde" 117 umask $save_umask 118 fi 119 # Is the KDE desktop dir != $HOME/Desktop ? 120 if [ "x`readlink -f "$desktop_dir"`" != "x`readlink -f "$desktop_dir_kde"`" ]; then 121 # If so, don't create $HOME/Desktop if it doesn't exist 122 [ -w "$desktop_dir" ] || desktop_dir= 123 else 124 desktop_dir_kde= 125 fi 126fi 127 128basefile=`basename "$desktop_file"` 129 130DEBUG 1 "$action $desktop_file in $desktop_dir $desktop_dir_kde $desktop_dir_gnome" 131 132case $action in 133 install) 134 save_umask=`umask` 135 umask $my_umask 136 137 for x in "$desktop_dir" "$desktop_dir_kde" "$desktop_dir_gnome" ; do 138 if [ -n "$x" ]; then 139 mkdir -p "$x" 140 eval 'cp "$desktop_file" "$x/$basefile"'$xdg_redirect_output 141 chmod u+x "$x/$basefile" 142 fi 143 done 144 145 umask $save_umask 146 ;; 147 148 uninstall) 149 for x in "$desktop_dir" "$desktop_dir_kde" "$desktop_dir_gnome" ; do 150 if [ -n "$x" ]; then 151 rm -f "$x/$basefile" 152 fi 153 done 154 155 ;; 156esac 157 158exit_success 159 160 161