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