2
#---------------------------------------------
5
# Utility script to install menu items on a Linux desktop.
6
# Refer to the usage() function below for usage.
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>
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:
22
# The above copyright notice and this permission notice shall be included
23
# in all copies or substantial portions of the Software.
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.
33
#---------------------------------------------
40
xdg-desktop-menu - command line tool for (un)installing desktop menu items
44
xdg-desktop-menu install [--noupdate] [--novendor] [--mode mode] directory-file
47
xdg-desktop-menu uninstall [--noupdate] [--mode mode] directory-file(s)
50
xdg-desktop-menu forceupdate [--mode mode]
52
xdg-desktop-menu { --help | --manual | --version }
56
The xdg-desktop-menu program can be used to install new menu entries to the
57
desktop's application menu.
59
The application menu works according to the XDG Desktop Menu Specification at
60
http://www.freedesktop.org/Standards/menu-spec
66
Install one or more applications in a submenu of the desktop menu system.
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
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.
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.
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
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.
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
98
Directory files follow the syntax defined by the freedesktop.org Desktop
103
Remove applications or submenus from the desktop menu system previously
104
installed with xdg-desktop-menu install.
106
A submenu and the associated directory file is only removed when the
107
submenu no longer contains any menu entries.
111
Force an update of the menu system.
113
This command is only useful if the last call to xdg-desktop-menu included
114
the --noupdate option.
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
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.
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.
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.
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.
145
Show command synopsis.
147
Show this manualpage.
149
Show the xdg-utils version information.
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=
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.
162
The following keys are often used:
165
This is a mandatory field to indicate that the *.desktop file follows the
166
1.0 version of the specification.
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
175
Optional field to specify a tooltip for the application. For example Visit
176
websites on the Internet
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.
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
193
Categories=Categories
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
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.
205
See Appendix A of the XDG Desktop Menu Specification for information about
206
additional categories. http://standards.freedesktop.org/menu-spec/
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.
213
For a complete oveview of the *.desktop file format please visit http://
214
www.freedesktop.org/wiki/Standards/desktop-entry-spec
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=
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.
228
The following keys are relevqnt for submenus:
231
This is a mandatory field to indicate that the *.directory file follows the
232
1.0 version of the Desktop Entry specification.
234
This is a mandatory field that indicates that the *.directory file
237
The title of submenu. For example Mozilla
239
Optional field to specify a tooltip for the submenu.
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.
249
Environment Variables
251
xdg-desktop-menu honours the following environment variables:
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.
263
An exit code of 0 indicates success while a non-zero exit code indicates
264
failure. The following failure codes can be returned:
267
Error in command line syntax.
269
One of the files passed on the command line did not exist.
271
A required tool could not be found.
275
No permission to read one of the files passed on the command line.
279
xdg-desktop-icon(1), xdg-icon-resource(1), xdg-mime(1)
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:
288
shinythings-webmirror.desktop:
300
Categories=Network;WebDevelopment;
302
Now the xdg-desktop-menu tool can be used to add the
303
shinythings-webmirror.desktop file to the desktop application menu:
305
xdg-desktop-menu install ./shinythings-webmirror.desktop
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.
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.
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:
318
shinythings-webmirror.desktop:
325
Icon=shinythings-webmirror
331
shinythings-webmirror-admin.desktop:
337
Exec=webmirror-admintool
338
Icon=shinythings-webmirror-admintool
340
Name=WebMirror Admin Tool
341
Name[nl]=WebSpiegel Administratie Tool
343
In addition a .directory file needs to be created to provide a title and icon
344
for the sub-menu itself:
346
shinythings-webmirror.directory:
351
Icon=shinythings-webmirror-menu
356
These file can now be installed with:
358
xdg-desktop-menu install ./shinythings-webmirror.directory \
359
./shinythings-webmirror.desktop ./shinythings-webmirror-admin.desktop
361
The menu entries could also be installed one by one:
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
369
Although the result is the same it is slightly more efficient to install all
370
files at the same time.
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:
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
390
xdg-desktop-menu - command line tool for (un)installing desktop menu items
394
xdg-desktop-menu install [--noupdate] [--novendor] [--mode mode] directory-file
397
xdg-desktop-menu uninstall [--noupdate] [--mode mode] directory-file(s)
400
xdg-desktop-menu forceupdate [--mode mode]
402
xdg-desktop-menu { --help | --manual | --version }
409
#----------------------------------------------------------------------------
410
# Common utility functions included in all XDG wrapper scripts
411
#----------------------------------------------------------------------------
415
[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
416
[ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
421
#-------------------------------------------------------------
422
# Exit script on successfully completing the desired operation
426
if [ $# -gt 0 ]; then
435
#-----------------------------------------
436
# Exit script on malformed arguments, not enough arguments
437
# or missing required option.
438
# prints usage information
440
exit_failure_syntax()
442
if [ $# -gt 0 ]; then
443
echo "xdg-desktop-menu: $@" >&2
444
echo "Try 'xdg-desktop-menu --help' for more information." >&2
447
echo "Use 'man xdg-desktop-menu' or 'xdg-desktop-menu --manual' for additional info."
453
#-------------------------------------------------------------
454
# Exit script on missing file specified on command line
456
exit_failure_file_missing()
458
if [ $# -gt 0 ]; then
459
echo "xdg-desktop-menu: $@" >&2
465
#-------------------------------------------------------------
466
# Exit script on failure to locate necessary tool applications
468
exit_failure_operation_impossible()
470
if [ $# -gt 0 ]; then
471
echo "xdg-desktop-menu: $@" >&2
477
#-------------------------------------------------------------
478
# Exit script on failure returned by a tool application
480
exit_failure_operation_failed()
482
if [ $# -gt 0 ]; then
483
echo "xdg-desktop-menu: $@" >&2
489
#------------------------------------------------------------
490
# Exit script on insufficient permission to read a specified file
492
exit_failure_file_permission_read()
494
if [ $# -gt 0 ]; then
495
echo "xdg-desktop-menu: $@" >&2
501
#------------------------------------------------------------
502
# Exit script on insufficient permission to write a specified file
504
exit_failure_file_permission_write()
506
if [ $# -gt 0 ]; then
507
echo "xdg-desktop-menu: $@" >&2
515
if [ ! -e "$1" ]; then
516
exit_failure_file_missing "file '$1' does not exist"
518
if [ ! -r "$1" ]; then
519
exit_failure_file_permission_read "no permission to read file '$1'"
523
check_vendor_prefix()
526
[ -n "$file_label" ] || file_label="filename"
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
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
546
if [ ! -w "$1" ]; then
547
exit_failure_file_permission_write "no permission to write to file '$1'"
551
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
552
exit_failure_file_permission_write "no permission to create file '$1'"
557
#----------------------------------------
558
# Checks for shared commands, e.g. --help
560
check_common_commands()
562
while [ $# -gt 0 ] ; do
569
echo "Use 'man xdg-desktop-menu' or 'xdg-desktop-menu --manual' for additional info."
579
echo "xdg-desktop-menu 1.0.2"
586
check_common_commands "$@"
588
[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
589
if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
591
xdg_redirect_output=" > /dev/null 2> /dev/null"
593
# All output to stderr
594
xdg_redirect_output=" >&2"
597
#--------------------------------------
598
# Checks for known desktop environments
599
# set variable DE to the desktop environments name, lowercase
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;
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
617
kfmclient_fix_exit_code()
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
629
update_desktop_database()
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
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
651
local xdg_default_dirs
653
DEBUG 1 "make_lazy_default $1/$2"
656
if (match($0,/MimeType=/)) {
657
split(substr($0,RSTART+9),mimetypes,";")
664
}' "$1/$2" 2> /dev/null`
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"
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;"
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
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
695
echo $MIME="$default_app$2" >> ${default_file}.new
696
mv ${default_file}.new $default_file
702
DEBUG 1 "update_submenu $1"
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"
710
xdg_system_dirs="$XDG_CONFIG_DIRS"
711
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/etc/xdg
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"
719
xdg_user_dir="$xdg_user_dir/applications-merged"
720
xdg_global_dir="$xdg_global_dir/applications-merged"
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"
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"
737
xdg_dir="$xdg_global_dir"
738
kde_dir="$kde_global_dir"
739
gnome_dir="$gnome_global_dir"
742
if [ -z "${xdg_dir}${kde_dir}${gnome_dir}" ] ; then
743
exit_failure_operation_impossible "No writable system menu directory found."
747
if [ -z "$menu_file" ] ; then
748
# Work around for SUSE/gnome 2.12 to pick up new ~/.local/share/applications
753
touch $xdg_dir/xdg-desktop-menu-dummy.menu
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
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
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
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
793
orig_menu_file=$xdg_dir/$menu_file
795
DEBUG 1 "Updating $orig_menu_file ($action)"
797
test "${TMPDIR+set}" = set || TMPDIR=/tmp
798
tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX`
800
if [ -r "$orig_menu_file" ] ; then
802
# List all files within <Filename> tags
808
print substr($0,RSTART+1)
810
}' $orig_menu_file > $tmpfile
813
orig_desktop_files=`cat $tmpfile`
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
820
echo "$basefile" >> $tmpfile
823
new_desktop_files=`cat $tmpfile`
825
if [ $action = "uninstall" ] ; then
827
for desktop_file in $desktop_files; do
828
echo "$desktop_file" >> $tmpfile
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"
841
DEBUG 3 "Files to list in $menu_file: $new_desktop_files"
843
if [ -n "$new_desktop_files" ] ; then
845
test "${TMPDIR+set}" = set || TMPDIR=/tmp
846
tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX`
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 -->'
852
echo ' <Name>Applications</Name>'
854
for desktop_file in $directory_files; do
855
basefile=`basename "$desktop_file"`
856
basefilename=`echo "$basefile"|cut -d '.' -f 1`
858
echo " <Name>$basefilename</Name>"
859
echo " <Directory>$basefile</Directory>"
863
for desktop_file in $new_desktop_files; do
864
echo " <Filename>$desktop_file</Filename>"
868
for desktop_file in $directory_files; do
874
chmod $my_chmod $tmpfile
880
eval 'cp $tmpfile $xdg_dir/$menu_file'$xdg_redirect_output
886
rm -f $xdg_dir/$menu_file
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
896
# List all files within <Directory> tags
902
print substr($0,RSTART+1)
904
}' $menu_file >> $tmpfile
907
orig_directory_files="$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"
920
[ x"$1" != x"" ] || exit_failure_syntax
942
exit_failure_syntax "unknown command '$1'"
949
while [ $# -gt 0 ] ; do
959
if [ -z "$1" ] ; then
960
exit_failure_syntax "mode argument missing for --mode"
972
exit_failure_syntax "unknown mode '$1'"
983
exit_failure_syntax "unexpected option '$parm'"
987
if [ "$action" = "install" ] ; then
988
check_input_file "$parm"
992
if [ -n "$desktop_files" ] ; then
993
exit_failure_syntax "'$parm' must preceed any *.desktop file"
995
directory_files="$directory_files $parm"
998
desktop_files="$desktop_files $parm"
1001
exit_failure_syntax "file to $action must be a *.directory or *.desktop file"
1009
if [ -z "$action" ] ; then
1010
exit_failure_syntax "command argument missing"
1013
if [ -n "$XDG_UTILS_INSTALL_MODE" ] ; then
1014
if [ "$XDG_UTILS_INSTALL_MODE" = "system" ] ; then
1016
elif [ "$XDG_UTILS_INSTALL_MODE" = "user" ] ; then
1021
if [ -z "$mode" ] ; then
1022
if [ `whoami` = "root" ] ; then
1029
if [ x"$action" = x"forceupdate" ] ; then
1030
update_desktop_database
1034
if [ -z "$desktop_files" ] ; then
1035
exit_failure_syntax "desktop-file argument missing"
1039
for desktop_file in $directory_files; do
1040
if [ "$vendor" = "true" -a "$action" = "install" ] ; then
1041
check_vendor_prefix "$desktop_file"
1044
basefilename=`basename "$desktop_file" | cut -d '.' -f 1`
1045
if [ -z "$menu_name" ] ; then
1046
menu_name="$basefilename"
1048
menu_name="$menu_name-$basefilename"
1052
if [ -n "$menu_name" ] ; then
1053
if [ x"$mode" = x"user" ] ; then
1054
update_submenu "user-$menu_name.menu"
1056
update_submenu "$menu_name.menu"
1059
# Work around for SUSE/gnome 2.12 to pick up new ~/.local/share/applications
1060
if [ x"$mode" = x"user" ] ; then
1065
# Install *.directory files
1067
xdg_dir_name=desktop-directories
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"
1073
xdg_system_dirs="$XDG_DATA_DIRS"
1074
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
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"
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"
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"
1097
xdg_dir="$xdg_global_dir"
1098
kde_dir="$kde_global_dir"
1099
gnome_dir="$gnome_global_dir"
1101
if [ -z "${xdg_dir}${kde_dir}${gnome_dir}" ] ; then
1102
exit_failure_operation_impossible "No writable system menu directory found."
1106
for desktop_file in $directory_files; do
1107
basefile=`basename "$desktop_file"`
1109
DEBUG 1 "$action $desktop_file in $xdg_dir $kde_dir $gnome_dir"
1116
for x in $xdg_dir $kde_dir $gnome_dir ; do
1118
eval 'cp $desktop_file $x/$basefile'$xdg_redirect_output
1125
for x in $xdg_dir $kde_dir $gnome_dir ; do
1133
# Install *.desktop files
1134
xdg_dir_name=applications
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"
1140
xdg_system_dirs="$XDG_DATA_DIRS"
1141
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
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"
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=
1154
gnome_user_dir="$HOME/.gnome/apps"
1155
gnome_global_dir="/usr/share/gnome/apps"
1156
[ -w $gnome_global_dir ] || gnome_global_dir=
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"
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"
1172
xdg_dir="$xdg_global_dir"
1173
kde_dir="$kde_global_dir"
1174
gnome_dir="$gnome_global_dir"
1176
if [ -z "${xdg_dir}${kde_dir}${gnome_dir}" ] ; then
1177
exit_failure_operation_impossible "No writable system menu directory found."
1181
for desktop_file in $desktop_files; do
1182
if [ "$vendor" = "true" -a "$action" = "install" ] ; then
1183
check_vendor_prefix "$desktop_file"
1186
basefile=`basename "$desktop_file"`
1188
DEBUG 1 "$action $desktop_file in $xdg_dir $kde_dir $gnome_dir"
1195
for x in $xdg_dir $kde_dir $gnome_dir ; do
1197
eval 'cp $desktop_file $x/$basefile'$xdg_redirect_output
1200
if [ -f $kde_dir/$basefile ] ; then
1201
echo "OnlyShowIn=Old;" >> $kde_dir/$basefile
1204
if [ -f $gnome_dir/$basefile ] ; then
1205
echo "OnlyShowIn=Old;" >> $gnome_dir/$basefile
1208
make_lazy_default "$xdg_dir" "$basefile"
1214
for x in $xdg_dir $kde_dir $gnome_dir ; do
1222
if [ x"$update" = x"yes" ] ; then
1223
update_desktop_database