xdg-desktop-icon 21 KB

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