source: trunk/puppet/modules/puppet-escritorio/files/xdg/xdg-desktop-icon @ 695

Last change on this file since 695 was 695, checked in by josx@…, 14 years ago

Poniendo los iconos en el Escritorio #82

  • Property svn:executable set to *
File size: 14.5 KB
Line 
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 2006, Kevin Krammer <kevin.krammer@gmx.at>
10#   Copyright 2006, Jeremy White <jwhite@codeweavers.com>
11#
12#   LICENSE:
13#
14#   Permission is hereby granted, free of charge, to any person obtaining a
15#   copy of this software and associated documentation files (the "Software"),
16#   to deal in the Software without restriction, including without limitation
17#   the rights to use, copy, modify, merge, publish, distribute, sublicense,
18#   and/or sell copies of the Software, and to permit persons to whom the
19#   Software is furnished to do so, subject to the following conditions:
20#
21#   The above copyright notice and this permission notice shall be included
22#   in all copies or substantial portions of the Software.
23#
24#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25#   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27#   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28#   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29#   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30#   OTHER DEALINGS IN THE SOFTWARE.
31#
32#---------------------------------------------
33
34usage()
35{
36cat << _USAGE
37xdg-desktop-icon - command line tool for (un)installing icons to the desktop
38
39Synopsis
40
41xdg-desktop-icon install [--novendor] FILE
42
43xdg-desktop-icon uninstall FILE
44
45xdg-desktop-icon { --help | --manual | --version }
46
47_USAGE
48}
49
50manualpage()
51{
52cat << _MANUALPAGE
53Name
54
55xdg-desktop-icon - command line tool for (un)installing icons to the desktop
56
57Synopsis
58
59xdg-desktop-icon install [--novendor] FILE
60
61xdg-desktop-icon uninstall FILE
62
63xdg-desktop-icon { --help | --manual | --version }
64
65Description
66
67The xdg-desktop-icon program can be used to install an application launcher or
68other file on the desktop of the current user.
69
70An application launcher is represented by a *.desktop file. Desktop files are
71defined by the freedesktop.org Desktop Entry Specification. The most important
72aspects of *.desktop files are summarized below.
73
74Commands
75
76install
77    Installs FILE to the desktop of the current user. FILE can be a *.desktop
78    file or any other type of file.
79uninstall
80    Removes FILE from the desktop of the current user.
81
82Options
83
84--novendor
85
86    Normally, xdg-desktop-icon checks to ensure that a *.desktop file to be
87    installed has a vendor prefix. This option can be used to disable that
88    check.
89
90    A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated
91    with a dash ("-"). Companies and organizations are encouraged to use a word
92    or phrase, preferably the organizations name, for which they hold a
93    trademark as their vendor prefix. The purpose of the vendor prefix is to
94    prevent name conflicts.
95
96--help
97    Show command synopsis.
98--manual
99    Show this manualpage.
100--version
101    Show the xdg-utils version information.
102
103Desktop Files
104
105An application launcher can be added to the desktop by installing a *.desktop
106file. A *.desktop file consists of a [Desktop Entry] header followed by several
107Key=Value lines.
108
109A *.desktop file can provide a name and description for an application in
110several different languages. This is done by adding a language code as used by
111LC_MESSAGES in square brackets behind the Key. This way one can specify
112different values for the same Key depending on the currently selected language.
113
114The following keys are often used:
115
116Value=1.0
117    This is a mandatory field to indicate that the *.desktop file follows the
118    1.0 version of the specification.
119Type=Application
120    This is a mandatory field that indicates that the *.desktop file describes
121    an application launcher.
122Name=Application Name
123    The name of the application. For example Mozilla
124GenericName=Generic Name
125    A generic description of the application. For example Web Browser
126Comment=Comment
127    Optional field to specify a tooltip for the application. For example Visit
128    websites on the Internet
129Icon=Icon File
130    The icon to use for the application. This can either be an absolute path to
131    an image file or an icon-name. If an icon-name is provided an image lookup
132    by name is done in the user's current icon theme. The xdg-icon-resource
133    command can be used to install image files into icon themes. The advantage
134    of using an icon-name instead of an absolute path is that with an icon-name
135    the application icon can be provided in several different sizes as well as
136    in several differently themed styles.
137Exec=Command Line
138    The command line to start the application. If the application can open
139    files the %f placeholder should be specified. When a file is dropped on the
140    application launcher the %f is replaced with the file path of the dropped
141    file. If multiple files can be specified on the command line the %F
142    placeholder should be used instead of %f. If the application is able to
143    open URLs in addition to local files then %u or %U can be used instead of
144    %f or %F.
145
146For a complete oveview of the *.desktop file format please visit http://
147www.freedesktop.org/wiki/Standards/desktop-entry-spec
148
149Environment Variables
150
151xdg-desktop-icon honours the following environment variables:
152
153XDG_UTILS_DEBUG_LEVEL
154    Setting this environment variable to a non-zero numerical value makes
155    xdg-desktop-icon do more verbose reporting on stderr. Setting a higher
156    value increases the verbosity.
157
158Exit Codes
159
160An exit code of 0 indicates success while a non-zero exit code indicates
161failure. The following failure codes can be returned:
162
1631
164    Error in command line syntax.
1652
166    One of the files passed on the command line did not exist.
1673
168    A required tool could not be found.
1694
170    The action failed.
1715
172    No permission to read one of the files passed on the command line.
173
174See Also
175
176xdg-icon-resource(1)
177
178Examples
179
180The company ShinyThings Inc. has developed an application named "WebMirror" and
181would like to add a launcher for for on the desktop. The company will use
182"shinythings" as its vendor id. In order to add the application to the desktop
183there needs to be a .desktop file for the application:
184
185shinythings-webmirror.desktop:
186
187  [Desktop Entry]
188  Encoding=UTF-8
189  Type=Application
190
191  Exec=webmirror
192  Icon=shinythings-webmirror
193
194  Name=WebMirror
195  Name[nl]=WebSpiegel
196
197Now the xdg-desktop-icon tool can be used to add the webmirror.desktop file to
198the desktop:
199
200xdg-desktop-icon install ./shinythings-webmirror.desktop
201
202To add a README file to the desktop as well, the following command can be used:
203
204xdg-desktop-icon install ./shinythings-README
205
206_MANUALPAGE
207}
208
209#@xdg-utils-common@
210
211#----------------------------------------------------------------------------
212#   Common utility functions included in all XDG wrapper scripts
213#----------------------------------------------------------------------------
214
215DEBUG()
216{
217  [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
218  [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
219  shift
220  echo "$@" >&2
221}
222
223#-------------------------------------------------------------
224# Exit script on successfully completing the desired operation
225
226exit_success()
227{
228    if [ $# -gt 0 ]; then
229        echo "$@"
230        echo
231    fi
232
233    exit 0
234}
235
236
237#-----------------------------------------
238# Exit script on malformed arguments, not enough arguments
239# or missing required option.
240# prints usage information
241
242exit_failure_syntax()
243{
244    if [ $# -gt 0 ]; then
245        echo "xdg-desktop-icon: $@" >&2
246        echo "Try 'xdg-desktop-icon --help' for more information." >&2
247    else
248        usage
249        echo "Use 'man xdg-desktop-icon' or 'xdg-desktop-icon --manual' for additional info."
250    fi
251
252    exit 1
253}
254
255#-------------------------------------------------------------
256# Exit script on missing file specified on command line
257
258exit_failure_file_missing()
259{
260    if [ $# -gt 0 ]; then
261        echo "xdg-desktop-icon: $@" >&2
262    fi
263
264    exit 2
265}
266
267#-------------------------------------------------------------
268# Exit script on failure to locate necessary tool applications
269
270exit_failure_operation_impossible()
271{
272    if [ $# -gt 0 ]; then
273        echo "xdg-desktop-icon: $@" >&2
274    fi
275
276    exit 3
277}
278
279#-------------------------------------------------------------
280# Exit script on failure returned by a tool application
281
282exit_failure_operation_failed()
283{
284    if [ $# -gt 0 ]; then
285        echo "xdg-desktop-icon: $@" >&2
286    fi
287
288    exit 4
289}
290
291#------------------------------------------------------------
292# Exit script on insufficient permission to read a specified file
293
294exit_failure_file_permission_read()
295{
296    if [ $# -gt 0 ]; then
297        echo "xdg-desktop-icon: $@" >&2
298    fi
299
300    exit 5
301}
302
303#------------------------------------------------------------
304# Exit script on insufficient permission to read a specified file
305
306exit_failure_file_permission_write()
307{
308    if [ $# -gt 0 ]; then
309        echo "xdg-desktop-icon: $@" >&2
310    fi
311
312    exit 6
313}
314
315check_input_file()
316{
317    if [ ! -e "$1" ]; then
318        exit_failure_file_missing "file '$1' does not exist"
319    fi
320    if [ ! -r "$1" ]; then
321        exit_failure_file_permission_read "no permission to read file '$1'"
322    fi
323}
324
325check_vendor_prefix()
326{
327    file_label="$2"
328    [ -n "$file_label" ] || file_label="filename"
329    file=`basename "$1"`
330    case "$file" in
331       [a-zA-Z]*-*)
332         return
333         ;;
334    esac
335
336    echo "xdg-desktop-icon: $file_label '$file' does not have a proper vendor prefix" >&2
337    echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
338    echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
339    echo "Use --novendor to override or 'xdg-desktop-icon --manual' for additional info." >&2
340    exit 1
341}
342
343check_output_file()
344{
345    # if the file exists, check if it is writeable
346    # if it does not exists, check if we are allowed to write on the directory
347    if [ -e "$1" ]; then
348        if [ ! -w "$1" ]; then
349            exit_failure_file_permission_write "no permission to write to file '$1'"
350        fi
351    else
352        DIR=`dirname "$1"`
353        if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
354            exit_failure_file_permission_write "no permission to create file '$1'"
355        fi
356    fi
357}
358
359#----------------------------------------
360# Checks for shared commands, e.g. --help
361
362check_common_commands()
363{
364    while [ $# -gt 0 ] ; do
365        parm="$1"
366        shift
367
368        case "$parm" in
369            --help)
370            usage
371            echo "Use 'man xdg-desktop-icon' or 'xdg-desktop-icon --manual' for additional info."
372            exit_success
373            ;;
374
375            --manual)
376            manualpage
377            exit_success
378            ;;
379
380            --version)
381            echo "xdg-desktop-icon 1.0.1"
382            exit_success
383            ;;
384        esac
385    done
386}
387
388check_common_commands "$@"
389
390[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
391if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
392    # Be silent
393    xdg_redirect_output=" > /dev/null 2> /dev/null"
394else
395    # All output to stderr
396    xdg_redirect_output=" >&2"
397fi
398
399#--------------------------------------
400# Checks for known desktop environments
401# set variable DE to the desktop environments name, lowercase
402
403detectDE()
404{
405    if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
406    elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
407    elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
408    fi
409}
410
411#----------------------------------------------------------------------------
412# kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
413# It also always returns 1 in KDE 3.4 and earlier
414# Simply return 0 in such case
415
416kfmclient_fix_exit_code()
417{
418    version=`kde-config --version 2>/dev/null | grep KDE`
419    major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'`
420    minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'`
421    release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
422    test "$major" -gt 3 && return $1
423    test "$minor" -gt 5 && return $1
424    test "$release" -gt 4 && return $1
425    return 0
426}
427
428[ x"$1" != x"" ] || exit_failure_syntax
429
430action=
431desktop_file=
432
433case $1 in
434  install)
435    action=install
436    ;;
437
438  uninstall)
439    action=uninstall
440    ;;
441
442  *)
443    exit_failure_syntax "unknown command '$1'"
444    ;;
445esac
446
447shift
448
449vendor=true
450while [ $# -gt 0 ] ; do
451    parm=$1
452    shift
453
454    case $parm in
455      --novendor)
456        vendor=false
457        ;;
458
459      -*)
460        exit_failure_syntax "unexpected option '$parm'"
461        ;;
462
463      *)
464        if [ -n "$desktop_file" ] ; then
465            exit_failure_syntax "unexpected argument '$parm'"
466        fi
467        if [ "$action" = "install" ] ; then
468            check_input_file "$parm"
469        fi
470        desktop_file=$parm
471        ;;
472    esac
473done
474
475# Shouldn't happen
476if [ -z "$action" ] ; then
477    exit_failure_syntax "command argument missing"
478fi
479
480if [ -z "$desktop_file" ] ; then
481    exit_failure_syntax "FILE argument missing"
482fi
483
484filetype=
485case $desktop_file in
486  *.desktop)
487     filetype=desktop
488     if [ "$vendor" = "true" -a "$action" = "install" ] ; then
489        check_vendor_prefix "$desktop_file"
490     fi
491     ;;
492  *)
493     filetype=other
494     ;;
495esac
496
497my_umask=077
498desktop_dir="$HOME/Escritorio"
499desktop_dir_kde=`kde-config --userpath desktop 2> /dev/null`
500if gconftool-2 -g /apps/nautilus/preferences/desktop_is_home_dir 2> /dev/null | grep true > /dev/null; then
501    desktop_dir_gnome="$HOME"
502    # Don't create $HOME/Desktop if it doesn't exist
503    [ -w $desktop_dir ] || desktop_dir=
504fi
505if [ -n "$desktop_dir_kde" ]; then
506    if [ ! -d "$desktop_dir_kde" ]; then
507        save_umask=`umask`
508        umask $my_umask
509        mkdir -p $desktop_dir_kde
510        umask $save_umask
511    fi
512    # Is the KDE desktop dir != $HOME/Desktop ?
513    if [ x`readlink -f "$desktop_dir"` != x`readlink -f "$desktop_dir_kde"` ]; then
514        # If so, don't create $HOME/Desktop if it doesn't exist
515        [ -w $desktop_dir ] || desktop_dir=
516    else
517        desktop_dir_kde=
518    fi
519fi
520desktop_dir="$desktop_dir $desktop_dir_kde $desktop_dir_gnome"
521
522basefile=`basename $desktop_file`
523
524DEBUG 1 "$action $desktop_file in $desktop_dir"
525
526case $action in
527    install)
528        save_umask=`umask`
529        umask $my_umask
530
531        for x in $desktop_dir ; do
532            mkdir -p $x
533            eval 'cp $desktop_file $x/$basefile'$xdg_redirect_output
534        done
535
536        umask $save_umask
537        ;;
538
539    uninstall)
540        for x in $desktop_dir ; do
541            rm -f $x/$basefile
542        done
543
544        ;;
545esac
546
547exit_success
548
549
Note: See TracBrowser for help on using the repository browser.