Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: third_party/xdg-utils/scripts/xdg-desktop-icon

Issue 151098: Patch from mdm@google.com... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Name: svn:executable
+ *
OLDNEW
(Empty)
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
34 usage()
35 {
36 cat << _USAGE
37 xdg-desktop-icon - command line tool for (un)installing icons to the desktop
38
39 Synopsis
40
41 xdg-desktop-icon install [--novendor] FILE
42
43 xdg-desktop-icon uninstall FILE
44
45 xdg-desktop-icon { --help | --manual | --version }
46
47 _USAGE
48 }
49
50 manualpage()
51 {
52 cat << _MANUALPAGE
53 Name
54
55 xdg-desktop-icon - command line tool for (un)installing icons to the desktop
56
57 Synopsis
58
59 xdg-desktop-icon install [--novendor] FILE
60
61 xdg-desktop-icon uninstall FILE
62
63 xdg-desktop-icon { --help | --manual | --version }
64
65 Description
66
67 The xdg-desktop-icon program can be used to install an application launcher or
68 other file on the desktop of the current user.
69
70 An application launcher is represented by a *.desktop file. Desktop files are
71 defined by the freedesktop.org Desktop Entry Specification. The most important
72 aspects of *.desktop files are summarized below.
73
74 Commands
75
76 install
77 Installs FILE to the desktop of the current user. FILE can be a *.desktop
78 file or any other type of file.
79 uninstall
80 Removes FILE from the desktop of the current user.
81
82 Options
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
103 Desktop Files
104
105 An application launcher can be added to the desktop by installing a *.desktop
106 file. A *.desktop file consists of a [Desktop Entry] header followed by several
107 Key=Value lines.
108
109 A *.desktop file can provide a name and description for an application in
110 several different languages. This is done by adding a language code as used by
111 LC_MESSAGES in square brackets behind the Key. This way one can specify
112 different values for the same Key depending on the currently selected language.
113
114 The following keys are often used:
115
116 Value=1.0
117 This is a mandatory field to indicate that the *.desktop file follows the
118 1.0 version of the specification.
119 Type=Application
120 This is a mandatory field that indicates that the *.desktop file describes
121 an application launcher.
122 Name=Application Name
123 The name of the application. For example Mozilla
124 GenericName=Generic Name
125 A generic description of the application. For example Web Browser
126 Comment=Comment
127 Optional field to specify a tooltip for the application. For example Visit
128 websites on the Internet
129 Icon=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.
137 Exec=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
146 For a complete oveview of the *.desktop file format please visit http://
147 www.freedesktop.org/wiki/Standards/desktop-entry-spec
148
149 Environment Variables
150
151 xdg-desktop-icon honours the following environment variables:
152
153 XDG_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
158 Exit Codes
159
160 An exit code of 0 indicates success while a non-zero exit code indicates
161 failure. The following failure codes can be returned:
162
163 1
164 Error in command line syntax.
165 2
166 One of the files passed on the command line did not exist.
167 3
168 A required tool could not be found.
169 4
170 The action failed.
171 5
172 No permission to read one of the files passed on the command line.
173
174 See Also
175
176 xdg-icon-resource(1)
177
178 Examples
179
180 The company ShinyThings Inc. has developed an application named "WebMirror" and
181 would 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
183 there needs to be a .desktop file for the application:
184
185 shinythings-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
197 Now the xdg-desktop-icon tool can be used to add the webmirror.desktop file to
198 the desktop:
199
200 xdg-desktop-icon install ./shinythings-webmirror.desktop
201
202 To add a README file to the desktop as well, the following command can be used:
203
204 xdg-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
215 DEBUG()
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
226 exit_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
242 exit_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 addi tional info."
250 fi
251
252 exit 1
253 }
254
255 #-------------------------------------------------------------
256 # Exit script on missing file specified on command line
257
258 exit_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
270 exit_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
282 exit_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
294 exit_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
306 exit_failure_file_permission_write()
307 {
308 if [ $# -gt 0 ]; then
309 echo "xdg-desktop-icon: $@" >&2
310 fi
311
312 exit 6
313 }
314
315 check_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
325 check_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 pr efix" >&2
337 echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is termina ted' >&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 addition al info." >&2
340 exit 1
341 }
342
343 check_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
362 check_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
388 check_common_commands "$@"
389
390 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
391 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
392 # Be silent
393 xdg_redirect_output=" > /dev/null 2> /dev/null"
394 else
395 # All output to stderr
396 xdg_redirect_output=" >&2"
397 fi
398
399 #--------------------------------------
400 # Checks for known desktop environments
401 # set variable DE to the desktop environments name, lowercase
402
403 detectDE()
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
416 kfmclient_fix_exit_code()
417 {
418 version=`kde${KDE_SESSION_VERSION}-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
430 action=
431 desktop_file=
432
433 case $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 ;;
445 esac
446
447 shift
448
449 vendor=true
450 while [ $# -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
473 done
474
475 # Shouldn't happen
476 if [ -z "$action" ] ; then
477 exit_failure_syntax "command argument missing"
478 fi
479
480 if [ -z "$desktop_file" ] ; then
481 exit_failure_syntax "FILE argument missing"
482 fi
483
484 filetype=
485 case $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 ;;
495 esac
496
497 my_umask=077
498 desktop_dir="$HOME/Desktop"
499 desktop_dir_kde=`kde${KDE_SESSION_VERSION}-config --userpath desktop 2> /dev/nul l`
500 if 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=
504 fi
505 if [ -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"` ]; t hen
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
519 fi
520 desktop_dir="$desktop_dir $desktop_dir_kde $desktop_dir_gnome"
521
522 basefile=`basename $desktop_file`
523
524 DEBUG 1 "$action $desktop_file in $desktop_dir"
525
526 case $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 ;;
545 esac
546
547 exit_success
548
549
OLDNEW
« no previous file with comments | « third_party/xdg-utils/scripts/xdg-copy.in ('k') | third_party/xdg-utils/scripts/xdg-desktop-icon.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698