~saiarcot895/ubuntu/wily/xdg-utils/fix-multiple-execs

« back to all changes in this revision

Viewing changes to .pc/bashisms.diff/scripts/xdg-desktop-menu

  • Committer: Package Import Robot
  • Author(s): Per Olofsson
  • Date: 2011-12-12 12:04:25 UTC
  • mfrom: (1.2.8)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: package-import@ubuntu.com-20111212120425-0rdnrl8tn45vz171
Tags: 1.1.0~rc1+git20111210-1
* New upstream git snapshot b961235b197647d6649ef3d48d7cc2cecafe3d47.
* Drop patches applied upstream:
  - xdg-mime-follow-symlinks.diff
  - x-www-browser.diff
  - xdg-mime-generic-use-mimetype.diff
  - bashisms.diff
  - xdg-screensaver-check-gnome.diff
* Modify patches to make changes to scripts/xdg-*.in, instead of the
  generated scripts.
* Also check for ~/.mutt/muttrc when deciding whether to use mutt as
  MUA or not. Thanks to martin f krafft. Closes: #648733.
* Build scripts/xdg-* from *.in files.
* Build-depend on xmlto and awk, as they are needed when building the
  scripts.
* Also build the manual pages.
* Bump Standards-Version to 3.9.2. No changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#---------------------------------------------
3
 
#   xdg-desktop-menu
4
 
#
5
 
#   Utility script to install menu items on a Linux desktop.
6
 
#   Refer to the usage() function below for usage.
7
 
#
8
 
#   Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
9
 
#   Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
10
 
#   Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
11
 
#   Copyright 2006, Jeremy White <jwhite@codeweavers.com>
12
 
#
13
 
#   LICENSE:
14
 
#
15
 
#   Permission is hereby granted, free of charge, to any person obtaining a
16
 
#   copy of this software and associated documentation files (the "Software"),
17
 
#   to deal in the Software without restriction, including without limitation
18
 
#   the rights to use, copy, modify, merge, publish, distribute, sublicense,
19
 
#   and/or sell copies of the Software, and to permit persons to whom the
20
 
#   Software is furnished to do so, subject to the following conditions:
21
 
#
22
 
#   The above copyright notice and this permission notice shall be included
23
 
#   in all copies or substantial portions of the Software.
24
 
#
25
 
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26
 
#   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
 
#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28
 
#   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
29
 
#   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30
 
#   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31
 
#   OTHER DEALINGS IN THE SOFTWARE.
32
 
#
33
 
#---------------------------------------------
34
 
 
35
 
manualpage()
36
 
{
37
 
cat << _MANUALPAGE
38
 
Name
39
 
 
40
 
xdg-desktop-menu - command line tool for (un)installing desktop menu items
41
 
 
42
 
Synopsis
43
 
 
44
 
xdg-desktop-menu install [--noupdate] [--novendor] [--mode mode] directory-file
45
 
(s) desktop-file(s)
46
 
 
47
 
xdg-desktop-menu uninstall [--noupdate] [--mode mode] directory-file(s)
48
 
desktop-file(s)
49
 
 
50
 
xdg-desktop-menu forceupdate [--mode mode]
51
 
 
52
 
xdg-desktop-menu { --help | --manual | --version }
53
 
 
54
 
Description
55
 
 
56
 
The xdg-desktop-menu program can be used to install new menu entries to the
57
 
desktop's application menu.
58
 
 
59
 
The application menu works according to the XDG Desktop Menu Specification at
60
 
http://www.freedesktop.org/Standards/menu-spec
61
 
 
62
 
Commands
63
 
 
64
 
install
65
 
 
66
 
    Install one or more applications in a submenu of the desktop menu system.
67
 
 
68
 
    desktop-file: A desktop file represents a single menu entry in the menu.
69
 
    Desktop files are defined by the freedesktop.org Desktop Entry
70
 
    Specification. The most important aspects of *.desktop files are summarized
71
 
    below.
72
 
 
73
 
    Menu entries can be added to the menu system in two different ways. They
74
 
    can either be added to a predefined submenu in the menu system based on one
75
 
    or more category keywords, or they can be added to a new submenu.
76
 
 
77
 
    To add a menu entry to a predefined submenu the desktop file that
78
 
    represents the menu entry must have a Categories= entry that lists one or
79
 
    more keywords. The menu item will be included in an appropriate submenu
80
 
    based on the included keywords.
81
 
 
82
 
    To add menu items to a new submenu the desktop-files must be preceded by a
83
 
    directory-file that describes the submenu. If multiple desktop-files are
84
 
    specified, all entries will be added to the same menu. If entries are
85
 
    installed to a menu that has been created with a previous call to 
86
 
    xdg-desktop-menu the entries will be installed in addition to any already
87
 
    existing entries.
88
 
 
89
 
    directory-file: The *.directory file indicated by directory-file represents
90
 
    a submenu. The directory file provides the name and icon for a submenu. The
91
 
    name of the directory file is used to identify the submenu.
92
 
 
93
 
    If multiple directory files are provided each file will represent a submenu
94
 
    within the menu that preceeds it, creating a nested menu hierarchy
95
 
    (sub-sub-menus). The menu entries themselves will be added to the last
96
 
    submenu.
97
 
 
98
 
    Directory files follow the syntax defined by the freedesktop.org Desktop
99
 
    Entry Specification.
100
 
 
101
 
uninstall
102
 
 
103
 
    Remove applications or submenus from the desktop menu system previously
104
 
    installed with xdg-desktop-menu install.
105
 
 
106
 
    A submenu and the associated directory file is only removed when the
107
 
    submenu no longer contains any menu entries.
108
 
 
109
 
forceupdate
110
 
 
111
 
    Force an update of the menu system.
112
 
 
113
 
    This command is only useful if the last call to xdg-desktop-menu included
114
 
    the --noupdate option.
115
 
 
116
 
Options
117
 
 
118
 
--noupdate
119
 
    Postpone updating the menu system. If multiple updates to the menu system
120
 
    are made in sequence this flag can be used to indicate that additional
121
 
    changes will follow and that it is not necassery to update the menu system
122
 
    right away.
123
 
--novendor
124
 
 
125
 
    Normally, xdg-desktop-menu checks to ensure that any *.directory and
126
 
    *.desktop files to be installed has a vendor prefix. This option can be
127
 
    used to disable that check.
128
 
 
129
 
    A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated
130
 
    with a dash ("-"). Companies and organizations are encouraged to use a word
131
 
    or phrase, preferably the organizations name, for which they hold a
132
 
    trademark as their vendor prefix. The purpose of the vendor prefix is to
133
 
    prevent name conflicts.
134
 
 
135
 
--mode mode
136
 
 
137
 
    mode can be user or system. In user mode the file is (un)installed for the
138
 
    current user only. In system mode the file is (un)installed for all users
139
 
    on the system. Usually only root is allowed to install in system mode.
140
 
 
141
 
    The default is to use system mode when called by root and to use user mode
142
 
    when called by a non-root user.
143
 
 
144
 
--help
145
 
    Show command synopsis.
146
 
--manual
147
 
    Show this manualpage.
148
 
--version
149
 
    Show the xdg-utils version information.
150
 
 
151
 
Desktop Files
152
 
 
153
 
An application item in the application menu is represented by a *.desktop file.
154
 
A *.desktop file consists of a [Desktop Entry] header followed by several Key=
155
 
Value lines.
156
 
 
157
 
A *.desktop file can provide a name and description for an application in
158
 
several different languages. This is done by adding a language code as used by
159
 
LC_MESSAGES in square brackets behind the Key. This way one can specify
160
 
different values for the same Key depending on the currently selected language.
161
 
 
162
 
The following keys are often used:
163
 
 
164
 
Value=1.0
165
 
    This is a mandatory field to indicate that the *.desktop file follows the
166
 
    1.0 version of the specification.
167
 
Type=Application
168
 
    This is a mandatory field that indicates that the *.desktop file describes
169
 
    an application launcher.
170
 
Name=Application Name
171
 
    The name of the application. For example Mozilla
172
 
GenericName=Generic Name
173
 
    A generic description of the application. For example Web Browser
174
 
Comment=Comment
175
 
    Optional field to specify a tooltip for the application. For example Visit
176
 
    websites on the Internet
177
 
Icon=Icon File
178
 
    The icon to use for the application. This can either be an absolute path to
179
 
    an image file or an icon-name. If an icon-name is provided an image lookup
180
 
    by name is done in the user's current icon theme. The xdg-icon-resource
181
 
    command can be used to install image files into icon themes. The advantage
182
 
    of using an icon-name instead of an absolute path is that with an icon-name
183
 
    the application icon can be provided in several different sizes as well as
184
 
    in several differently themed styles.
185
 
Exec=Command Line
186
 
    The command line to start the application. If the application can open
187
 
    files the %f placeholder should be specified. When a file is dropped on the
188
 
    application launcher the %f is replaced with the file path of the dropped
189
 
    file. If multiple files can be specified on the command line the %F
190
 
    placeholder should be used instead of %f. If the application is able to
191
 
    open URLs in addition to local files then %u or %U can be used instead of
192
 
    %f or %F.
193
 
Categories=Categories
194
 
 
195
 
    A list of categories separated by semi-colons. A category is a keyword that
196
 
    describes and classifies the application. By default applications are
197
 
    organized in the application menu based on category. When menu entries are
198
 
    explicitly assigned to a new submenu it is not necassery to list any
199
 
    categories.
200
 
 
201
 
    When using categories it is recommended to include one of the following
202
 
    categories: AudioVideo, Development, Education, Game, Graphics, Network,
203
 
    Office, Settings, System, Utility.
204
 
 
205
 
    See Appendix A of the XDG Desktop Menu Specification for information about
206
 
    additional categories. http://standards.freedesktop.org/menu-spec/
207
 
    menu-spec-1.0.html
208
 
 
209
 
MimeType=Mimetypes
210
 
    A list of mimetypes separated by semi-colons. This field is used to
211
 
    indicate which file types the application is able to open.
212
 
 
213
 
For a complete oveview of the *.desktop file format please visit http://
214
 
www.freedesktop.org/wiki/Standards/desktop-entry-spec
215
 
 
216
 
Directory Files
217
 
 
218
 
The appearance of submenu in the application menu is provided by a *.directory
219
 
file. In particular it provides the title of the submenu and a possible icon. A
220
 
*.directory file consists of a [Desktop Entry] header followed by several Key=
221
 
Value lines.
222
 
 
223
 
A *.directory file can provide a title (name) for the submenu in several
224
 
different languages. This is done by adding a language code as used by
225
 
LC_MESSAGES in square brackets behind the Key. This way one can specify
226
 
different values for the same Key depending on the currently selected language.
227
 
 
228
 
The following keys are relevqnt for submenus:
229
 
 
230
 
Value=1.0
231
 
    This is a mandatory field to indicate that the *.directory file follows the
232
 
    1.0 version of the Desktop Entry specification.
233
 
Type=Directory
234
 
    This is a mandatory field that indicates that the *.directory file
235
 
    describes a submenu.
236
 
Name=Menu Name
237
 
    The title of submenu. For example Mozilla
238
 
Comment=Comment
239
 
    Optional field to specify a tooltip for the submenu.
240
 
Icon=Icon File
241
 
    The icon to use for the submenu. This can either be an absolute path to an
242
 
    image file or an icon-name. If an icon-name is provided an image lookup by
243
 
    name is done in the user's current icon theme. The xdg-icon-resource
244
 
    command can be used to install image files into icon themes. The advantage
245
 
    of using an icon-name instead of an absolute path is that with an icon-name
246
 
    the submenu icon can be provided in several different sizes as well as in
247
 
    several differently themed styles.
248
 
 
249
 
Environment Variables
250
 
 
251
 
xdg-desktop-menu honours the following environment variables:
252
 
 
253
 
XDG_UTILS_DEBUG_LEVEL
254
 
    Setting this environment variable to a non-zero numerical value makes
255
 
    xdg-desktop-menu do more verbose reporting on stderr. Setting a higher
256
 
    value increases the verbosity.
257
 
XDG_UTILS_INSTALL_MODE
258
 
    This environment variable can be used by the user or administrator to
259
 
    override the installation mode. Valid values are user and system.
260
 
 
261
 
Exit Codes
262
 
 
263
 
An exit code of 0 indicates success while a non-zero exit code indicates
264
 
failure. The following failure codes can be returned:
265
 
 
266
 
1
267
 
    Error in command line syntax.
268
 
2
269
 
    One of the files passed on the command line did not exist.
270
 
3
271
 
    A required tool could not be found.
272
 
4
273
 
    The action failed.
274
 
5
275
 
    No permission to read one of the files passed on the command line.
276
 
 
277
 
See Also
278
 
 
279
 
xdg-desktop-icon(1), xdg-icon-resource(1), xdg-mime(1)
280
 
 
281
 
Examples
282
 
 
283
 
The company ShinyThings Inc. has developed an application named "WebMirror" and
284
 
would like to add it to the application menu. The company will use
285
 
"shinythings" as its vendor id. In order to add the application to the menu
286
 
there needs to be a .desktop file with a suitable Categories entry:
287
 
 
288
 
shinythings-webmirror.desktop:
289
 
 
290
 
  [Desktop Entry]
291
 
  Encoding=UTF-8
292
 
  Type=Application
293
 
 
294
 
  Exec=webmirror
295
 
  Icon=webmirror
296
 
 
297
 
  Name=WebMirror
298
 
  Name[nl]=WebSpiegel
299
 
 
300
 
  Categories=Network;WebDevelopment;
301
 
 
302
 
Now the xdg-desktop-menu tool can be used to add the
303
 
shinythings-webmirror.desktop file to the desktop application menu:
304
 
 
305
 
xdg-desktop-menu install ./shinythings-webmirror.desktop
306
 
 
307
 
Note that for the purpose of this example the menu items are available in two
308
 
languages, English and Dutch. The language code for Dutch is nl.
309
 
 
310
 
In the next example the company ShinyThings Inc. will add its own submenu to
311
 
the desktop application menu consisting of a "WebMirror" menu item and a
312
 
"WebMirror Admin Tool" menu item.
313
 
 
314
 
First the company needs to create two .desktop files that describe the two menu
315
 
items. Since the items are to be added to a new submenu it is not necassery to
316
 
include a Categories= line:
317
 
 
318
 
shinythings-webmirror.desktop:
319
 
 
320
 
  [Desktop Entry]
321
 
  Encoding=UTF-8
322
 
  Type=Application
323
 
 
324
 
  Exec=webmirror
325
 
  Icon=shinythings-webmirror
326
 
 
327
 
  Name=WebMirror
328
 
  Name[nl]=WebSpiegel
329
 
 
330
 
 
331
 
shinythings-webmirror-admin.desktop:
332
 
 
333
 
  [Desktop Entry]
334
 
  Encoding=UTF-8
335
 
  Type=Application
336
 
 
337
 
  Exec=webmirror-admintool
338
 
  Icon=shinythings-webmirror-admintool
339
 
 
340
 
  Name=WebMirror Admin Tool
341
 
  Name[nl]=WebSpiegel Administratie Tool
342
 
 
343
 
In addition a .directory file needs to be created to provide a title and icon
344
 
for the sub-menu itself:
345
 
 
346
 
shinythings-webmirror.directory:
347
 
 
348
 
  [Desktop Entry]
349
 
  Encoding=UTF-8
350
 
 
351
 
  Icon=shinythings-webmirror-menu
352
 
 
353
 
  Name=WebMirror
354
 
  Name[nl]=WebSpiegel
355
 
 
356
 
These file can now be installed with:
357
 
 
358
 
xdg-desktop-menu install ./shinythings-webmirror.directory \
359
 
      ./shinythings-webmirror.desktop ./shinythings-webmirror-admin.desktop
360
 
 
361
 
The menu entries could also be installed one by one:
362
 
 
363
 
xdg-desktop-menu install --noupdate ./shinythings-webmirror.directory \
364
 
      ./shinythings-webmirror.desktop
365
 
xdg-desktop-menu install --noupdate ./shinythings-webmirror.directory \
366
 
      ./shinythings-webmirror-admin.desktop
367
 
xdg-desktop-menu forceupdate
368
 
 
369
 
Although the result is the same it is slightly more efficient to install all
370
 
files at the same time.
371
 
 
372
 
The *.desktop and *.directory files reference icons with the names webmirror,
373
 
webmirror-admin and webmirror-menu which should also be installed. In this
374
 
example the icons are installed in two different sizes, once with a size of
375
 
22x22 pixels and once with a size of 64x64 pixels:
376
 
 
377
 
xdg-icon-resource install --size 22 ./wmicon-22.png shinythings-webmirror
378
 
xdg-icon-resource install --size 22 ./wmicon-menu-22.png shinythings-webmirror-menu
379
 
xdg-icon-resource install --size 22 ./wmicon-admin-22.png shinythings-webmirror-admin
380
 
xdg-icon-resource install --size 64 ./wmicon-64.png shinythings-webmirror
381
 
xdg-icon-resource install --size 64 ./wmicon-menu-64.png shinythings-webmirror-menu
382
 
xdg-icon-resource install --size 64 ./wmicon-admin-64.png shinythings-webmirror-admin
383
 
 
384
 
_MANUALPAGE
385
 
}
386
 
 
387
 
usage()
388
 
{
389
 
cat << _USAGE
390
 
xdg-desktop-menu - command line tool for (un)installing desktop menu items
391
 
 
392
 
Synopsis
393
 
 
394
 
xdg-desktop-menu install [--noupdate] [--novendor] [--mode mode] directory-file
395
 
(s) desktop-file(s)
396
 
 
397
 
xdg-desktop-menu uninstall [--noupdate] [--mode mode] directory-file(s)
398
 
desktop-file(s)
399
 
 
400
 
xdg-desktop-menu forceupdate [--mode mode]
401
 
 
402
 
xdg-desktop-menu { --help | --manual | --version }
403
 
 
404
 
_USAGE
405
 
}
406
 
 
407
 
#@xdg-utils-common@
408
 
 
409
 
#----------------------------------------------------------------------------
410
 
#   Common utility functions included in all XDG wrapper scripts
411
 
#----------------------------------------------------------------------------
412
 
 
413
 
DEBUG()
414
 
{
415
 
  [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
416
 
  [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
417
 
  shift
418
 
  echo "$@" >&2
419
 
}
420
 
 
421
 
#-------------------------------------------------------------
422
 
# Exit script on successfully completing the desired operation
423
 
 
424
 
exit_success()
425
 
{
426
 
    if [ $# -gt 0 ]; then
427
 
        echo "$@"
428
 
        echo
429
 
    fi
430
 
 
431
 
    exit 0
432
 
}
433
 
 
434
 
 
435
 
#-----------------------------------------
436
 
# Exit script on malformed arguments, not enough arguments
437
 
# or missing required option.
438
 
# prints usage information
439
 
 
440
 
exit_failure_syntax()
441
 
{
442
 
    if [ $# -gt 0 ]; then
443
 
        echo "xdg-desktop-menu: $@" >&2
444
 
        echo "Try 'xdg-desktop-menu --help' for more information." >&2
445
 
    else
446
 
        usage
447
 
        echo "Use 'man xdg-desktop-menu' or 'xdg-desktop-menu --manual' for additional info."
448
 
    fi
449
 
 
450
 
    exit 1
451
 
}
452
 
 
453
 
#-------------------------------------------------------------
454
 
# Exit script on missing file specified on command line
455
 
 
456
 
exit_failure_file_missing()
457
 
{
458
 
    if [ $# -gt 0 ]; then
459
 
        echo "xdg-desktop-menu: $@" >&2
460
 
    fi
461
 
 
462
 
    exit 2
463
 
}
464
 
 
465
 
#-------------------------------------------------------------
466
 
# Exit script on failure to locate necessary tool applications
467
 
 
468
 
exit_failure_operation_impossible()
469
 
{
470
 
    if [ $# -gt 0 ]; then
471
 
        echo "xdg-desktop-menu: $@" >&2
472
 
    fi
473
 
 
474
 
    exit 3
475
 
}
476
 
 
477
 
#-------------------------------------------------------------
478
 
# Exit script on failure returned by a tool application
479
 
 
480
 
exit_failure_operation_failed()
481
 
{
482
 
    if [ $# -gt 0 ]; then
483
 
        echo "xdg-desktop-menu: $@" >&2
484
 
    fi
485
 
 
486
 
    exit 4
487
 
}
488
 
 
489
 
#------------------------------------------------------------
490
 
# Exit script on insufficient permission to read a specified file
491
 
 
492
 
exit_failure_file_permission_read()
493
 
{
494
 
    if [ $# -gt 0 ]; then
495
 
        echo "xdg-desktop-menu: $@" >&2
496
 
    fi
497
 
 
498
 
    exit 5
499
 
}
500
 
 
501
 
#------------------------------------------------------------
502
 
# Exit script on insufficient permission to write a specified file
503
 
 
504
 
exit_failure_file_permission_write()
505
 
{
506
 
    if [ $# -gt 0 ]; then
507
 
        echo "xdg-desktop-menu: $@" >&2
508
 
    fi
509
 
 
510
 
    exit 6
511
 
}
512
 
 
513
 
check_input_file()
514
 
{
515
 
    if [ ! -e "$1" ]; then
516
 
        exit_failure_file_missing "file '$1' does not exist"
517
 
    fi
518
 
    if [ ! -r "$1" ]; then
519
 
        exit_failure_file_permission_read "no permission to read file '$1'"
520
 
    fi
521
 
}
522
 
 
523
 
check_vendor_prefix()
524
 
{
525
 
    file_label="$2"
526
 
    [ -n "$file_label" ] || file_label="filename"
527
 
    file=`basename "$1"`
528
 
    case "$file" in
529
 
       [a-zA-Z]*-*)
530
 
         return
531
 
         ;;
532
 
    esac
533
 
 
534
 
    echo "xdg-desktop-menu: $file_label '$file' does not have a proper vendor prefix" >&2
535
 
    echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
536
 
    echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
537
 
    echo "Use --novendor to override or 'xdg-desktop-menu --manual' for additional info." >&2
538
 
    exit 1
539
 
}
540
 
 
541
 
check_output_file()
542
 
{
543
 
    # if the file exists, check if it is writeable
544
 
    # if it does not exists, check if we are allowed to write on the directory
545
 
    if [ -e "$1" ]; then
546
 
        if [ ! -w "$1" ]; then
547
 
            exit_failure_file_permission_write "no permission to write to file '$1'"
548
 
        fi
549
 
    else
550
 
        DIR=`dirname "$1"`
551
 
        if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
552
 
            exit_failure_file_permission_write "no permission to create file '$1'"
553
 
        fi
554
 
    fi
555
 
}
556
 
 
557
 
#----------------------------------------
558
 
# Checks for shared commands, e.g. --help
559
 
 
560
 
check_common_commands()
561
 
{
562
 
    while [ $# -gt 0 ] ; do
563
 
        parm="$1"
564
 
        shift
565
 
 
566
 
        case "$parm" in
567
 
            --help)
568
 
            usage
569
 
            echo "Use 'man xdg-desktop-menu' or 'xdg-desktop-menu --manual' for additional info."
570
 
            exit_success
571
 
            ;;
572
 
 
573
 
            --manual)
574
 
            manualpage
575
 
            exit_success
576
 
            ;;
577
 
 
578
 
            --version)
579
 
            echo "xdg-desktop-menu 1.0.2"
580
 
            exit_success
581
 
            ;;
582
 
        esac
583
 
    done
584
 
}
585
 
 
586
 
check_common_commands "$@"
587
 
 
588
 
[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
589
 
if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
590
 
    # Be silent
591
 
    xdg_redirect_output=" > /dev/null 2> /dev/null"
592
 
else
593
 
    # All output to stderr
594
 
    xdg_redirect_output=" >&2"
595
 
fi
596
 
 
597
 
#--------------------------------------
598
 
# Checks for known desktop environments
599
 
# set variable DE to the desktop environments name, lowercase
600
 
 
601
 
detectDE()
602
 
{
603
 
    if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
604
 
    elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
605
 
    elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
606
 
    elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
607
 
    elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
608
 
    else DE=""
609
 
    fi
610
 
}
611
 
 
612
 
#----------------------------------------------------------------------------
613
 
# kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
614
 
# It also always returns 1 in KDE 3.4 and earlier
615
 
# Simply return 0 in such case
616
 
 
617
 
kfmclient_fix_exit_code()
618
 
{
619
 
    version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep '^KDE'`
620
 
    major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
621
 
    minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
622
 
    release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
623
 
    test "$major" -gt 3 && return $1
624
 
    test "$minor" -gt 5 && return $1
625
 
    test "$release" -gt 4 && return $1
626
 
    return 0
627
 
}
628
 
 
629
 
update_desktop_database()
630
 
{
631
 
#    echo Update desktop database: $mode
632
 
    if [ "$mode" = "system" ] ; then
633
 
        for x in `echo $PATH | sed 's/:/ /g'` /opt/gnome/bin; do
634
 
           if [ -x $x/update-desktop-database ] ; then
635
 
              DEBUG 1 "Running $x/update-desktop-database"
636
 
              eval '$x/update-desktop-database'$xdg_redirect_output
637
 
              return
638
 
           fi
639
 
        done
640
 
    fi
641
 
}
642
 
 
643
 
# Make application $1/$2 the default for all the mimetypes it support,
644
 
# iff such mimetype didn't had a default application already.
645
 
# $1 Install dir for desktop file
646
 
# $2 base name of desktop file
647
 
make_lazy_default()
648
 
{
649
 
    local mimetypes
650
 
    local xdg_user_dir
651
 
    local xdg_default_dirs
652
 
 
653
 
    DEBUG 1 "make_lazy_default $1/$2"
654
 
    mimetypes=`awk '
655
 
{
656
 
    if (match($0,/MimeType=/)) {
657
 
        split(substr($0,RSTART+9),mimetypes,";")
658
 
        for (n in mimetypes)
659
 
        {
660
 
               if (mimetypes[n])
661
 
                 print mimetypes[n]
662
 
        }
663
 
    }
664
 
}' "$1/$2" 2> /dev/null`
665
 
 
666
 
    for MIME in $mimetypes ; do
667
 
        xdg_default_dirs="$XDG_DATA_DIRS"
668
 
        [ -n "$xdg_default_dirs" ] || xdg_default_dirs=/usr/local/share/:/usr/share/
669
 
        if [ x"$mode" = x"user" ] ; then
670
 
            xdg_user_dir="$XDG_DATA_HOME"
671
 
            [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
672
 
            xdg_default_dirs="$xdg_user_dir:$xdg_default_dirs"
673
 
        fi
674
 
        local default_app
675
 
        for x in `echo "$xdg_default_dirs" | sed 's/:/ /g'`; do
676
 
            DEBUG 2 "Checking $x/applications/defaults.list"
677
 
            default_app=`grep "$MIME=" $x/applications/defaults.list 2> /dev/null | cut -d '=' -f 2`
678
 
            if [ -n "$default_app" ] ; then
679
 
                DEBUG 2 "Found default apps for $MIME: $default_app"
680
 
                default_app="$default_app;"
681
 
                break;
682
 
            fi
683
 
        done
684
 
        DEBUG 2 "Current default apps for $MIME: $default_app"
685
 
        if echo "$default_app" | grep "$2" > /dev/null 2> /dev/null; then
686
 
            # App already listed as default
687
 
            continue;
688
 
        fi
689
 
        default_file="$1/defaults.list"
690
 
        DEBUG 1 "Updating $default_file"
691
 
        grep -v "$MIME=" $default_file > ${default_file}.new 2> /dev/null
692
 
        if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then
693
 
            echo "[Default Applications]" >> ${default_file}.new
694
 
        fi
695
 
        echo $MIME="$default_app$2" >> ${default_file}.new
696
 
        mv ${default_file}.new $default_file
697
 
    done
698
 
}
699
 
 
700
 
update_submenu()
701
 
{
702
 
    DEBUG 1 "update_submenu $1"
703
 
    menu_file="$1"
704
 
 
705
 
    xdg_dir_name=menus
706
 
    xdg_user_dir="$XDG_CONFIG_HOME"
707
 
    [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.config"
708
 
    xdg_user_dir="$xdg_user_dir/$xdg_dir_name"
709
 
 
710
 
    xdg_system_dirs="$XDG_CONFIG_DIRS"
711
 
    [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/etc/xdg
712
 
    xdg_global_dir=
713
 
    for x in `echo $xdg_system_dirs | sed 's/:/ /g'` ; do
714
 
        if [ -w $x/$xdg_dir_name ] ; then
715
 
            xdg_global_dir="$x/$xdg_dir_name"
716
 
            break
717
 
        fi
718
 
    done
719
 
    xdg_user_dir="$xdg_user_dir/applications-merged"
720
 
    xdg_global_dir="$xdg_global_dir/applications-merged"
721
 
 
722
 
    DEBUG 3 "Install locations for *.menu file:"
723
 
    DEBUG 3 "xdg_user_dir: $xdg_user_dir"
724
 
    DEBUG 3 "xdg_global_dir: $xdg_global_dir"
725
 
    DEBUG 3 "kde_user_dir: $kde_user_dir"
726
 
    DEBUG 3 "kde_global_dir: $kde_global_dir"
727
 
    DEBUG 3 "gnome_user_dir: $gnome_user_dir"
728
 
    DEBUG 3 "gnome_global_dir: $gnome_global_dir"
729
 
 
730
 
    if [ x"$mode" = x"user" ] ; then
731
 
        xdg_dir="$xdg_user_dir"
732
 
        kde_dir="$kde_user_dir"
733
 
        gnome_dir="$gnome_user_dir"
734
 
        my_umask=077
735
 
        my_chmod=0600
736
 
    else
737
 
        xdg_dir="$xdg_global_dir"
738
 
        kde_dir="$kde_global_dir"
739
 
        gnome_dir="$gnome_global_dir"
740
 
        my_umask=022
741
 
        my_chmod=0644
742
 
        if [ -z "${xdg_dir}${kde_dir}${gnome_dir}" ] ; then
743
 
            exit_failure_operation_impossible "No writable system menu directory found."
744
 
        fi
745
 
    fi
746
 
 
747
 
    if [ -z "$menu_file" ] ; then
748
 
        # Work around for SUSE/gnome 2.12 to pick up new ~/.local/share/applications
749
 
        save_umask=`umask`
750
 
        umask $my_umask
751
 
 
752
 
        mkdir -p $xdg_dir
753
 
        touch $xdg_dir/xdg-desktop-menu-dummy.menu
754
 
 
755
 
        umask $save_umask
756
 
        return
757
 
    fi
758
 
 
759
 
    if [ $action = "install" -a -f "/etc/xdg/menus/gnome-applications.menu" ] ; then
760
 
        # Work around for Debian Gnome
761
 
        gnome_xdg_dir=`echo "$xdg_dir" | sed -e 's^/applications-merged^/gnome-applications-merged^'`
762
 
        if [ ! -e "$gnome_xdg_dir" ] ; then
763
 
            DEBUG 1 "Debian Workaround: Link '$xdg_dir' to '$gnome_xdg_dir'"
764
 
            mkdir -p `dirname "$gnome_xdg_dir"`
765
 
            eval 'ln -s "applications-merged" "$gnome_xdg_dir"'$xdg_redirect_output
766
 
        fi
767
 
    fi
768
 
    if [ $action = "install" -a -f "/etc/mandrake-release" ] ; then
769
 
        # Work around for Mandriva 2006
770
 
        mandrake_xdg_dir=`echo "$xdg_dir" | sed -e 's^/applications-merged^/applications-mdk-merged^'`
771
 
        if [ ! -e "$mandrake_xdg_dir" ] ; then
772
 
            DEBUG 1 "Mandriva Workaround: Link '$xdg_dir' to '$mandrake_xdg_dir'"
773
 
            mkdir -p `dirname "$mandrake_xdg_dir"`
774
 
            eval 'ln -s "applications-merged" "$mandrake_xdg_dir"'$xdg_redirect_output
775
 
        fi
776
 
    fi
777
 
    if [ $action = "install" -a x"$mode" = x"user" -a -d "/etc/xdg/menus/kde-applications-merged" ] ; then
778
 
        # Work around for Fedora Core 5 + patched KDE
779
 
        kde_xdg_dir=`echo "$xdg_dir" | sed -e 's^/applications-merged^/kde-applications-merged^'`
780
 
        if [ ! -e "$kde_xdg_dir" ] ; then
781
 
            DEBUG 1 "Fedora Workaround: Link '$xdg_dir' to '$kde_xdg_dir'"
782
 
            mkdir -p `dirname "$kde_xdg_dir"`
783
 
            eval 'ln -s "applications-merged" "$kde_xdg_dir"'$xdg_redirect_output
784
 
        fi
785
 
    fi
786
 
    if [ $action = "install" -a x"$mode" = x"system" -a -d "/etc/xdg/menus/kde-applications-merged" -a ! -d "/etc/xdg/menus/applications-merged" ] ; then
787
 
        # Work around for Kubuntu 6.06
788
 
        kde_xdg_dir=`echo "$xdg_dir" | sed -e 's^/applications-merged^/kde-applications-merged^'`
789
 
        DEBUG 1 "Kubuntu Workaround: Link '$xdg_dir' to 'kde-applications-merged'"
790
 
        eval 'ln -s "kde-applications-merged" "$xdg_dir"'$xdg_redirect_output
791
 
    fi
792
 
 
793
 
    orig_menu_file=$xdg_dir/$menu_file
794
 
 
795
 
    DEBUG 1 "Updating $orig_menu_file ($action)"
796
 
 
797
 
    test "${TMPDIR+set}" = set || TMPDIR=/tmp
798
 
    tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX`
799
 
    orig_desktop_files=
800
 
    if [ -r "$orig_menu_file" ] ; then
801
 
        awk '
802
 
# List all files within <Filename> tags
803
 
BEGIN {
804
 
  RS="<"
805
 
}
806
 
/^Filename/ {
807
 
  if (match($0,/>/)) {
808
 
     print substr($0,RSTART+1)
809
 
  }
810
 
}' $orig_menu_file > $tmpfile
811
 
    fi
812
 
 
813
 
    orig_desktop_files=`cat $tmpfile`
814
 
    new_desktop_files=
815
 
    if [ $action = "install" ] ; then
816
 
        for desktop_file in $desktop_files; do
817
 
            basefile=`basename "$desktop_file"`
818
 
            if ! grep '^'$basefile'$' $tmpfile > /dev/null 2> /dev/null ; then
819
 
                # Append
820
 
                echo "$basefile" >> $tmpfile
821
 
            fi
822
 
        done
823
 
        new_desktop_files=`cat $tmpfile`
824
 
    fi
825
 
    if [ $action = "uninstall" ] ; then
826
 
        echo > $tmpfile
827
 
        for desktop_file in $desktop_files; do
828
 
            echo "$desktop_file" >> $tmpfile
829
 
        done
830
 
        # Files to uninstall are listed in $tmpfile
831
 
        # Existing files are in $orig_desktop_files
832
 
        for desktop_file in $orig_desktop_files; do
833
 
            if ! grep '^'$desktop_file'$' $tmpfile > /dev/null 2> /dev/null; then
834
 
                # Keep this file, it's not in the uninstall list
835
 
                new_desktop_files="$new_desktop_files $desktop_file"
836
 
            fi
837
 
        done
838
 
    fi
839
 
    rm -f "$tmpfile"
840
 
 
841
 
    DEBUG 3 "Files to list in $menu_file: $new_desktop_files"
842
 
 
843
 
    if [ -n "$new_desktop_files" ] ; then
844
 
        # Install/update
845
 
        test "${TMPDIR+set}" = set || TMPDIR=/tmp
846
 
        tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX`
847
 
        (
848
 
            echo '<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"'
849
 
            echo '    "http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">'
850
 
            echo '<!-- Do not edit manually - generated and managed by xdg-desktop-menu -->'
851
 
            echo '<Menu>'
852
 
            echo '    <Name>Applications</Name>'
853
 
 
854
 
            for desktop_file in $directory_files; do
855
 
                basefile=`basename "$desktop_file"`
856
 
                basefilename=`echo "$basefile"|cut -d '.' -f 1`
857
 
                echo "<Menu>"
858
 
                echo "    <Name>$basefilename</Name>"
859
 
                echo "    <Directory>$basefile</Directory>"
860
 
            done
861
 
 
862
 
            echo "    <Include>"
863
 
            for desktop_file in $new_desktop_files; do
864
 
                echo "        <Filename>$desktop_file</Filename>"
865
 
            done
866
 
            echo "    </Include>"
867
 
 
868
 
            for desktop_file in $directory_files; do
869
 
                echo "</Menu>"
870
 
            done
871
 
 
872
 
            echo '</Menu>'
873
 
        ) > $tmpfile
874
 
        chmod $my_chmod $tmpfile
875
 
 
876
 
        save_umask=`umask`
877
 
        umask $my_umask
878
 
 
879
 
        mkdir -p $xdg_dir
880
 
        eval 'cp $tmpfile $xdg_dir/$menu_file'$xdg_redirect_output
881
 
 
882
 
        umask $save_umask
883
 
        rm -f "$tmpfile"
884
 
    else
885
 
        # Uninstall
886
 
        rm -f $xdg_dir/$menu_file
887
 
    fi
888
 
 
889
 
    # Uninstall .directory files only if no longer referenced
890
 
    if [ $action = "uninstall" ] ; then
891
 
        test "${TMPDIR+set}" = set || TMPDIR=/tmp
892
 
        tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX`
893
 
        for menu_file in $xdg_dir/*; do
894
 
            if grep 'generated and managed by xdg-desktop-menu' $menu_file > /dev/null 2> /dev/null; then
895
 
                awk '
896
 
# List all files within <Directory> tags
897
 
BEGIN {
898
 
  RS="<"
899
 
}
900
 
/^Directory/ {
901
 
  if (match($0,/>/)) {
902
 
     print substr($0,RSTART+1)
903
 
  }
904
 
}' $menu_file >> $tmpfile
905
 
            fi
906
 
        done
907
 
        orig_directory_files="$directory_files"
908
 
        directory_files=
909
 
        for desktop_file in $orig_directory_files; do
910
 
            if ! grep '^'$desktop_file'$' $tmpfile > /dev/null 2> /dev/null; then
911
 
                # No longer in use, safe to delete
912
 
               directory_files="$directory_files $desktop_file"
913
 
            fi
914
 
        done
915
 
        rm -f "$tmpfile"
916
 
    fi
917
 
}
918
 
 
919
 
 
920
 
[ x"$1" != x"" ] || exit_failure_syntax
921
 
 
922
 
mode=
923
 
action=
924
 
update=yes
925
 
desktop_files=
926
 
directory_files=
927
 
 
928
 
case $1 in
929
 
  install)
930
 
    action=install
931
 
    ;;
932
 
 
933
 
  uninstall)
934
 
    action=uninstall
935
 
    ;;
936
 
 
937
 
  forceupdate)
938
 
    action=forceupdate
939
 
    ;;
940
 
 
941
 
  *)
942
 
    exit_failure_syntax "unknown command '$1'"
943
 
    ;;
944
 
esac
945
 
 
946
 
shift
947
 
 
948
 
vendor=true
949
 
while [ $# -gt 0 ] ; do
950
 
    parm="$1"
951
 
    shift
952
 
 
953
 
    case "$parm" in
954
 
      --noupdate)
955
 
        update=no
956
 
        ;;
957
 
 
958
 
      --mode)
959
 
        if [ -z "$1" ] ; then
960
 
            exit_failure_syntax "mode argument missing for --mode"
961
 
        fi
962
 
        case "$1" in
963
 
          user)
964
 
            mode="user"
965
 
            ;;
966
 
 
967
 
          system)
968
 
            mode="system"
969
 
            ;;
970
 
 
971
 
          *)
972
 
            exit_failure_syntax "unknown mode '$1'"
973
 
            ;;
974
 
        esac
975
 
        shift
976
 
        ;;
977
 
 
978
 
      --novendor)
979
 
        vendor=false
980
 
        ;;
981
 
 
982
 
      -*)
983
 
        exit_failure_syntax "unexpected option '$parm'"
984
 
        ;;
985
 
 
986
 
      *)
987
 
        if [ "$action" = "install" ] ; then
988
 
            check_input_file "$parm"
989
 
        fi
990
 
        case "$parm" in
991
 
           *.directory)
992
 
              if [ -n "$desktop_files" ] ; then
993
 
                  exit_failure_syntax "'$parm' must preceed any *.desktop file"
994
 
              fi
995
 
              directory_files="$directory_files $parm"
996
 
              ;;
997
 
           *.desktop)
998
 
              desktop_files="$desktop_files $parm"
999
 
              ;;
1000
 
           *)
1001
 
              exit_failure_syntax "file to $action must be a *.directory or *.desktop file"
1002
 
              ;;
1003
 
        esac
1004
 
        ;;
1005
 
    esac
1006
 
done
1007
 
 
1008
 
# Shouldn't happen
1009
 
if [ -z "$action" ] ; then
1010
 
    exit_failure_syntax "command argument missing"
1011
 
fi
1012
 
 
1013
 
if [ -n "$XDG_UTILS_INSTALL_MODE" ] ; then
1014
 
    if [ "$XDG_UTILS_INSTALL_MODE" = "system" ] ; then
1015
 
        mode="system"
1016
 
    elif [ "$XDG_UTILS_INSTALL_MODE" = "user" ] ; then
1017
 
        mode="user"
1018
 
    fi
1019
 
fi
1020
 
 
1021
 
if [ -z "$mode" ] ; then
1022
 
    if [ `whoami` = "root" ] ; then
1023
 
       mode="system"
1024
 
    else
1025
 
       mode="user"
1026
 
    fi
1027
 
fi
1028
 
 
1029
 
if [ x"$action" = x"forceupdate" ] ; then
1030
 
    update_desktop_database
1031
 
    exit_success
1032
 
fi
1033
 
 
1034
 
if [ -z "$desktop_files" ] ; then
1035
 
    exit_failure_syntax "desktop-file argument missing"
1036
 
fi
1037
 
 
1038
 
menu_name=
1039
 
for desktop_file in $directory_files; do
1040
 
    if [ "$vendor" =  "true" -a "$action" = "install" ] ; then
1041
 
        check_vendor_prefix "$desktop_file"
1042
 
    fi
1043
 
 
1044
 
    basefilename=`basename "$desktop_file" | cut -d '.' -f 1`
1045
 
    if [ -z "$menu_name" ] ; then
1046
 
        menu_name="$basefilename"
1047
 
    else
1048
 
        menu_name="$menu_name-$basefilename"
1049
 
    fi
1050
 
done
1051
 
 
1052
 
if [ -n "$menu_name" ] ; then
1053
 
    if [ x"$mode" = x"user" ] ; then
1054
 
        update_submenu "user-$menu_name.menu"
1055
 
    else
1056
 
        update_submenu "$menu_name.menu"
1057
 
    fi
1058
 
else
1059
 
    # Work around for SUSE/gnome 2.12 to pick up new ~/.local/share/applications
1060
 
    if [ x"$mode" = x"user" ] ; then
1061
 
        update_submenu
1062
 
    fi
1063
 
fi
1064
 
 
1065
 
# Install *.directory files
1066
 
 
1067
 
xdg_dir_name=desktop-directories
1068
 
 
1069
 
xdg_user_dir="$XDG_DATA_HOME"
1070
 
[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
1071
 
xdg_user_dir="$xdg_user_dir/$xdg_dir_name"
1072
 
 
1073
 
xdg_system_dirs="$XDG_DATA_DIRS"
1074
 
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
1075
 
xdg_global_dir=
1076
 
for x in `echo $xdg_system_dirs | sed 's/:/ /g'` ; do
1077
 
    if [ -w $x/$xdg_dir_name ] ; then
1078
 
        xdg_global_dir="$x/$xdg_dir_name"
1079
 
        break
1080
 
    fi
1081
 
done
1082
 
 
1083
 
DEBUG 3 "Install locations for *.directory files:"
1084
 
DEBUG 3 "xdg_user_dir: $xdg_user_dir"
1085
 
DEBUG 3 "xdg_global_dir: $xdg_global_dir"
1086
 
DEBUG 3 "kde_user_dir: $kde_user_dir"
1087
 
DEBUG 3 "kde_global_dir: $kde_global_dir"
1088
 
DEBUG 3 "gnome_user_dir: $gnome_user_dir"
1089
 
DEBUG 3 "gnome_global_dir: $gnome_global_dir"
1090
 
 
1091
 
if [ x"$mode" = x"user" ] ; then
1092
 
    xdg_dir="$xdg_user_dir"
1093
 
    kde_dir="$kde_user_dir"
1094
 
    gnome_dir="$gnome_user_dir"
1095
 
    my_umask=077
1096
 
else
1097
 
    xdg_dir="$xdg_global_dir"
1098
 
    kde_dir="$kde_global_dir"
1099
 
    gnome_dir="$gnome_global_dir"
1100
 
    my_umask=022
1101
 
    if [ -z "${xdg_dir}${kde_dir}${gnome_dir}" ] ; then
1102
 
        exit_failure_operation_impossible "No writable system menu directory found."
1103
 
    fi
1104
 
fi
1105
 
 
1106
 
for desktop_file in $directory_files; do
1107
 
    basefile=`basename "$desktop_file"`
1108
 
 
1109
 
    DEBUG 1 "$action $desktop_file in $xdg_dir $kde_dir $gnome_dir"
1110
 
 
1111
 
    case $action in
1112
 
        install)
1113
 
            save_umask=`umask`
1114
 
            umask $my_umask
1115
 
 
1116
 
            for x in $xdg_dir $kde_dir $gnome_dir ; do
1117
 
                mkdir -p $x
1118
 
                eval 'cp $desktop_file $x/$basefile'$xdg_redirect_output
1119
 
            done
1120
 
 
1121
 
            umask $save_umask
1122
 
            ;;
1123
 
 
1124
 
        uninstall)
1125
 
            for x in $xdg_dir $kde_dir $gnome_dir ; do
1126
 
                rm -f $x/$basefile
1127
 
            done
1128
 
 
1129
 
            ;;
1130
 
    esac
1131
 
done
1132
 
 
1133
 
# Install *.desktop files
1134
 
xdg_dir_name=applications
1135
 
 
1136
 
xdg_user_dir="$XDG_DATA_HOME"
1137
 
[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
1138
 
xdg_user_dir="$xdg_user_dir/$xdg_dir_name"
1139
 
 
1140
 
xdg_system_dirs="$XDG_DATA_DIRS"
1141
 
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
1142
 
xdg_global_dir=
1143
 
for x in `echo $xdg_system_dirs | sed 's/:/ /g'` ; do
1144
 
    if [ -w $x/$xdg_dir_name ] ; then
1145
 
        xdg_global_dir="$x/$xdg_dir_name"
1146
 
        break
1147
 
    fi
1148
 
done
1149
 
 
1150
 
kde_user_dir=`kde${KDE_SESSION_VERSION}-config --path apps 2> /dev/null | cut -d ':' -f 1`
1151
 
kde_global_dir=`kde${KDE_SESSION_VERSION}-config --path apps 2> /dev/null | cut -d ':' -f 2`
1152
 
[ -w $kde_global_dir ] || kde_global_dir=
1153
 
 
1154
 
gnome_user_dir="$HOME/.gnome/apps"
1155
 
gnome_global_dir="/usr/share/gnome/apps"
1156
 
[ -w $gnome_global_dir ] || gnome_global_dir=
1157
 
 
1158
 
DEBUG 3 "Install locations for *.desktop files:"
1159
 
DEBUG 3 "xdg_user_dir: $xdg_user_dir"
1160
 
DEBUG 3 "xdg_global_dir: $xdg_global_dir"
1161
 
DEBUG 3 "kde_user_dir: $kde_user_dir"
1162
 
DEBUG 3 "kde_global_dir: $kde_global_dir"
1163
 
DEBUG 3 "gnome_user_dir: $gnome_user_dir"
1164
 
DEBUG 3 "gnome_global_dir: $gnome_global_dir"
1165
 
 
1166
 
if [ x"$mode" = x"user" ] ; then
1167
 
    xdg_dir="$xdg_user_dir"
1168
 
    kde_dir="$kde_user_dir"
1169
 
    gnome_dir="$gnome_user_dir"
1170
 
    my_umask=077
1171
 
else
1172
 
    xdg_dir="$xdg_global_dir"
1173
 
    kde_dir="$kde_global_dir"
1174
 
    gnome_dir="$gnome_global_dir"
1175
 
    my_umask=022
1176
 
    if [ -z "${xdg_dir}${kde_dir}${gnome_dir}" ] ; then
1177
 
        exit_failure_operation_impossible "No writable system menu directory found."
1178
 
    fi
1179
 
fi
1180
 
 
1181
 
for desktop_file in $desktop_files; do
1182
 
    if [ "$vendor" =  "true" -a "$action" = "install" ] ; then
1183
 
        check_vendor_prefix "$desktop_file"
1184
 
    fi
1185
 
 
1186
 
    basefile=`basename "$desktop_file"`
1187
 
 
1188
 
    DEBUG 1 "$action $desktop_file in $xdg_dir $kde_dir $gnome_dir"
1189
 
 
1190
 
    case $action in
1191
 
        install)
1192
 
            save_umask=`umask`
1193
 
            umask $my_umask
1194
 
 
1195
 
            for x in $xdg_dir $kde_dir $gnome_dir ; do
1196
 
                mkdir -p $x
1197
 
                eval 'cp $desktop_file $x/$basefile'$xdg_redirect_output
1198
 
            done
1199
 
 
1200
 
            if [ -f $kde_dir/$basefile ] ; then
1201
 
                echo "OnlyShowIn=Old;" >> $kde_dir/$basefile
1202
 
            fi
1203
 
 
1204
 
            if [ -f $gnome_dir/$basefile ] ; then
1205
 
                echo "OnlyShowIn=Old;" >> $gnome_dir/$basefile
1206
 
            fi
1207
 
 
1208
 
            make_lazy_default "$xdg_dir" "$basefile"
1209
 
 
1210
 
            umask $save_umask
1211
 
            ;;
1212
 
 
1213
 
        uninstall)
1214
 
            for x in $xdg_dir $kde_dir $gnome_dir ; do
1215
 
                rm -f $x/$basefile
1216
 
            done
1217
 
 
1218
 
            ;;
1219
 
    esac
1220
 
done
1221
 
 
1222
 
if [ x"$update" = x"yes" ] ; then
1223
 
    update_desktop_database
1224
 
fi
1225
 
 
1226
 
exit_success