xdg-mime 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. #!/bin/sh
  2. #---------------------------------------------
  3. # xdg-mime
  4. #
  5. # Utility script to manipulate MIME related information
  6. # on XDG compliant systems.
  7. #
  8. # Refer to the usage() function below for usage.
  9. #
  10. # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
  11. # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
  12. # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
  13. # Copyright 2006, Jeremy White <jwhite@codeweavers.com>
  14. #
  15. # LICENSE:
  16. #
  17. # Permission is hereby granted, free of charge, to any person obtaining a
  18. # copy of this software and associated documentation files (the "Software"),
  19. # to deal in the Software without restriction, including without limitation
  20. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  21. # and/or sell copies of the Software, and to permit persons to whom the
  22. # Software is furnished to do so, subject to the following conditions:
  23. #
  24. # The above copyright notice and this permission notice shall be included
  25. # in all copies or substantial portions of the Software.
  26. #
  27. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  28. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  30. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  31. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  32. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  33. # OTHER DEALINGS IN THE SOFTWARE.
  34. #
  35. #---------------------------------------------
  36. manualpage()
  37. {
  38. cat << _MANUALPAGE
  39. Name
  40. xdg-mime - command line tool for querying information about file type handling
  41. and adding descriptions for new file types
  42. Synopsis
  43. xdg-mime query { filetype | default } ...
  44. xdg-mime default application mimetype(s)
  45. xdg-mime install [--mode mode] [--novendor] mimetypes-file
  46. xdg-mime uninstall [--mode mode] mimetypes-file
  47. xdg-mime { --help | --manual | --version }
  48. Description
  49. The xdg-mime program can be used to query information about file types and to
  50. add descriptions for new file types.
  51. Commands
  52. query
  53. Returns information related to file types.
  54. The query option is for use inside a desktop session only. It is not
  55. recommended to use xdg-mime query as root.
  56. The following queries are supported:
  57. query filetype FILE: Returns the file type of FILE in the form of a MIME
  58. type.
  59. query default mimetype: Returns the default application that the desktop
  60. environment uses for opening files of type mimetype. The default
  61. application is identified by its *.desktop file.
  62. default
  63. Ask the desktop environment to make application the default application for
  64. opening files of type mimetype. An application can be made the default for
  65. several file types by specifying multiple mimetypes.
  66. application is the desktop file id of the application and has the form
  67. vendor-name.desktop application must already be installed in the desktop
  68. menu before it can be made the default handler. The aplication's desktop
  69. file must list support for all the MIME types that it wishes to be the
  70. default handler for.
  71. Requests to make an application a default handler may be subject to system
  72. policy or approval by the end-user. xdg-mime query can be used to verify
  73. whether an application is the actual default handler for a specific file
  74. type.
  75. The default option is for use inside a desktop session only. It is not
  76. recommended to use xdg-mime default as root.
  77. install
  78. Adds the file type descriptions provided in mimetypes-file to the desktop
  79. environment. mimetypes-file must be a XML file that follows the
  80. freedesktop.org Shared MIME-info Database specification and that has a
  81. mime-info element as its document root. For each new file type one or more
  82. icons with name type-subtype must be installed with the xdg-icon-resource
  83. command in the mimetypes context. For example the filetype application/
  84. vnd.oasis.opendocument.text requires an icon named
  85. application-vnd.oasis.opendocument.text to be installed (unless the file
  86. type recommends another icon name).
  87. uninstall
  88. Removes the file type descriptions provided in mimetypes-file and
  89. previously added with xdg-mime install from the desktop environment.
  90. mimetypes-file must be a XML file that follows the freedesktop.org Shared
  91. MIME-info Database specification and that has a mime-info element as its
  92. document root.
  93. Options
  94. --mode mode
  95. mode can be user or system. In user mode the file is (un)installed for the
  96. current user only. In system mode the file is (un)installed for all users
  97. on the system. Usually only root is allowed to install in system mode.
  98. The default is to use system mode when called by root and to use user mode
  99. when called by a non-root user.
  100. --novendor
  101. Normally, xdg-mime checks to ensure that the mimetypes-file to be installed
  102. has a proper vendor prefix. This option can be used to disable that check.
  103. A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated
  104. with a dash ("-"). Companies and organizations are encouraged to use a word
  105. or phrase, preferably the organizations name, for which they hold a
  106. trademark as their vendor prefix. The purpose of the vendor prefix is to
  107. prevent name conflicts.
  108. --help
  109. Show command synopsis.
  110. --manual
  111. Show this manualpage.
  112. --version
  113. Show the xdg-utils version information.
  114. Environment Variables
  115. xdg-mime honours the following environment variables:
  116. XDG_UTILS_DEBUG_LEVEL
  117. Setting this environment variable to a non-zero numerical value makes
  118. xdg-mime do more verbose reporting on stderr. Setting a higher value
  119. increases the verbosity.
  120. XDG_UTILS_INSTALL_MODE
  121. This environment variable can be used by the user or administrator to
  122. override the installation mode. Valid values are user and system.
  123. Exit Codes
  124. An exit code of 0 indicates success while a non-zero exit code indicates
  125. failure. The following failure codes can be returned:
  126. 1
  127. Error in command line syntax.
  128. 2
  129. One of the files passed on the command line did not exist.
  130. 3
  131. A required tool could not be found.
  132. 4
  133. The action failed.
  134. 5
  135. No permission to read one of the files passed on the command line.
  136. See Also
  137. xdg-icon-resource(1), xdg-desktop-menu(1)
  138. Examples
  139. xdg-mime query filetype /tmp/foobar.png
  140. Prints the MIME type of the file /tmp/foobar.png, in this case image/png
  141. xdg-mime query default image/png
  142. Prints the .desktop filename of the application which is registered to open PNG
  143. files.
  144. xdg-mime install shinythings-shiny.xml
  145. Adds a file type description for "shiny"-files. "shinythings-" is used as the
  146. vendor prefix. The file type description could look as folows.
  147. shinythings-shiny.xml:
  148. <?xml version="1.0"?>
  149. <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  150. <mime-type type="text/x-shiny">
  151. <comment>Shiny new file type</comment>
  152. <glob pattern="*.shiny"/>
  153. <glob pattern="*.shi"/>
  154. </mime-type>
  155. </mime-info>
  156. An icon for this new file type must also be installed, for example with:
  157. xdg-icon-resource install --context mimetypes --size 64 shiny-file-icon.png text-x-shiny
  158. _MANUALPAGE
  159. }
  160. usage()
  161. {
  162. cat << _USAGE
  163. xdg-mime - command line tool for querying information about file type handling
  164. and adding descriptions for new file types
  165. Synopsis
  166. xdg-mime query { filetype | default } ...
  167. xdg-mime default application mimetype(s)
  168. xdg-mime install [--mode mode] [--novendor] mimetypes-file
  169. xdg-mime uninstall [--mode mode] mimetypes-file
  170. xdg-mime { --help | --manual | --version }
  171. _USAGE
  172. }
  173. #@xdg-utils-common@
  174. #----------------------------------------------------------------------------
  175. # Common utility functions included in all XDG wrapper scripts
  176. #----------------------------------------------------------------------------
  177. DEBUG()
  178. {
  179. [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
  180. [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
  181. shift
  182. echo "$@" >&2
  183. }
  184. # This handles backslashes but not quote marks.
  185. first_word()
  186. {
  187. read first rest
  188. echo "$first"
  189. }
  190. #-------------------------------------------------------------
  191. # map a binary to a .desktop file
  192. binary_to_desktop_file()
  193. {
  194. search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  195. binary="`which "$1"`"
  196. binary="`readlink -f "$binary"`"
  197. base="`basename "$binary"`"
  198. IFS=:
  199. for dir in $search; do
  200. unset IFS
  201. [ "$dir" ] || continue
  202. [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue
  203. for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
  204. [ -r "$file" ] || continue
  205. # Check to make sure it's worth the processing.
  206. grep -q "^Exec.*$base" "$file" || continue
  207. # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
  208. grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
  209. command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
  210. command="`which "$command"`"
  211. if [ x"`readlink -f "$command"`" = x"$binary" ]; then
  212. # Fix any double slashes that got added path composition
  213. echo "$file" | sed -e 's,//*,/,g'
  214. return
  215. fi
  216. done
  217. done
  218. }
  219. #-------------------------------------------------------------
  220. # map a .desktop file to a binary
  221. ## FIXME: handle vendor dir case
  222. desktop_file_to_binary()
  223. {
  224. search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  225. desktop="`basename "$1"`"
  226. IFS=:
  227. for dir in $search; do
  228. unset IFS
  229. [ "$dir" -a -d "$dir/applications" ] || continue
  230. file="$dir/applications/$desktop"
  231. [ -r "$file" ] || continue
  232. # Remove any arguments (%F, %f, %U, %u, etc.).
  233. command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
  234. command="`which "$command"`"
  235. readlink -f "$command"
  236. return
  237. done
  238. }
  239. #-------------------------------------------------------------
  240. # Exit script on successfully completing the desired operation
  241. exit_success()
  242. {
  243. if [ $# -gt 0 ]; then
  244. echo "$@"
  245. echo
  246. fi
  247. exit 0
  248. }
  249. #-----------------------------------------
  250. # Exit script on malformed arguments, not enough arguments
  251. # or missing required option.
  252. # prints usage information
  253. exit_failure_syntax()
  254. {
  255. if [ $# -gt 0 ]; then
  256. echo "xdg-mime: $@" >&2
  257. echo "Try 'xdg-mime --help' for more information." >&2
  258. else
  259. usage
  260. echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info."
  261. fi
  262. exit 1
  263. }
  264. #-------------------------------------------------------------
  265. # Exit script on missing file specified on command line
  266. exit_failure_file_missing()
  267. {
  268. if [ $# -gt 0 ]; then
  269. echo "xdg-mime: $@" >&2
  270. fi
  271. exit 2
  272. }
  273. #-------------------------------------------------------------
  274. # Exit script on failure to locate necessary tool applications
  275. exit_failure_operation_impossible()
  276. {
  277. if [ $# -gt 0 ]; then
  278. echo "xdg-mime: $@" >&2
  279. fi
  280. exit 3
  281. }
  282. #-------------------------------------------------------------
  283. # Exit script on failure returned by a tool application
  284. exit_failure_operation_failed()
  285. {
  286. if [ $# -gt 0 ]; then
  287. echo "xdg-mime: $@" >&2
  288. fi
  289. exit 4
  290. }
  291. #------------------------------------------------------------
  292. # Exit script on insufficient permission to read a specified file
  293. exit_failure_file_permission_read()
  294. {
  295. if [ $# -gt 0 ]; then
  296. echo "xdg-mime: $@" >&2
  297. fi
  298. exit 5
  299. }
  300. #------------------------------------------------------------
  301. # Exit script on insufficient permission to write a specified file
  302. exit_failure_file_permission_write()
  303. {
  304. if [ $# -gt 0 ]; then
  305. echo "xdg-mime: $@" >&2
  306. fi
  307. exit 6
  308. }
  309. check_input_file()
  310. {
  311. if [ ! -e "$1" ]; then
  312. exit_failure_file_missing "file '$1' does not exist"
  313. fi
  314. if [ ! -r "$1" ]; then
  315. exit_failure_file_permission_read "no permission to read file '$1'"
  316. fi
  317. }
  318. check_vendor_prefix()
  319. {
  320. file_label="$2"
  321. [ -n "$file_label" ] || file_label="filename"
  322. file=`basename "$1"`
  323. case "$file" in
  324. [a-zA-Z]*-*)
  325. return
  326. ;;
  327. esac
  328. echo "xdg-mime: $file_label '$file' does not have a proper vendor prefix" >&2
  329. echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
  330. echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
  331. echo "Use --novendor to override or 'xdg-mime --manual' for additional info." >&2
  332. exit 1
  333. }
  334. check_output_file()
  335. {
  336. # if the file exists, check if it is writeable
  337. # if it does not exists, check if we are allowed to write on the directory
  338. if [ -e "$1" ]; then
  339. if [ ! -w "$1" ]; then
  340. exit_failure_file_permission_write "no permission to write to file '$1'"
  341. fi
  342. else
  343. DIR=`dirname "$1"`
  344. if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
  345. exit_failure_file_permission_write "no permission to create file '$1'"
  346. fi
  347. fi
  348. }
  349. #----------------------------------------
  350. # Checks for shared commands, e.g. --help
  351. check_common_commands()
  352. {
  353. while [ $# -gt 0 ] ; do
  354. parm="$1"
  355. shift
  356. case "$parm" in
  357. --help)
  358. usage
  359. echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info."
  360. exit_success
  361. ;;
  362. --manual)
  363. manualpage
  364. exit_success
  365. ;;
  366. --version)
  367. echo "xdg-mime 1.1.0 rc1"
  368. exit_success
  369. ;;
  370. esac
  371. done
  372. }
  373. check_common_commands "$@"
  374. [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
  375. if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
  376. # Be silent
  377. xdg_redirect_output=" > /dev/null 2> /dev/null"
  378. else
  379. # All output to stderr
  380. xdg_redirect_output=" >&2"
  381. fi
  382. #--------------------------------------
  383. # Checks for known desktop environments
  384. # set variable DE to the desktop environments name, lowercase
  385. detectDE()
  386. {
  387. # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
  388. unset GREP_OPTIONS
  389. if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
  390. case "${XDG_CURRENT_DESKTOP}" in
  391. GNOME)
  392. DE=gnome;
  393. ;;
  394. KDE)
  395. DE=kde;
  396. ;;
  397. LXDE)
  398. DE=lxde;
  399. ;;
  400. XFCE)
  401. DE=xfce
  402. esac
  403. fi
  404. if [ x"$DE" = x"" ]; then
  405. # classic fallbacks
  406. if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
  407. elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
  408. 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;
  409. elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
  410. elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
  411. fi
  412. fi
  413. if [ x"$DE" = x"" ]; then
  414. # fallback to checking $DESKTOP_SESSION
  415. case "$DESKTOP_SESSION" in
  416. gnome)
  417. DE=gnome;
  418. ;;
  419. LXDE)
  420. DE=lxde;
  421. ;;
  422. xfce|xfce4)
  423. DE=xfce;
  424. ;;
  425. esac
  426. fi
  427. if [ x"$DE" = x"" ]; then
  428. # fallback to uname output for other platforms
  429. case "$(uname 2>/dev/null)" in
  430. Darwin)
  431. DE=darwin;
  432. ;;
  433. esac
  434. fi
  435. if [ x"$DE" = x"gnome" ]; then
  436. # gnome-default-applications-properties is only available in GNOME 2.x
  437. # but not in GNOME 3.x
  438. which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
  439. fi
  440. }
  441. #----------------------------------------------------------------------------
  442. # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
  443. # It also always returns 1 in KDE 3.4 and earlier
  444. # Simply return 0 in such case
  445. kfmclient_fix_exit_code()
  446. {
  447. version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
  448. major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
  449. minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
  450. release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
  451. test "$major" -gt 3 && return $1
  452. test "$minor" -gt 5 && return $1
  453. test "$release" -gt 4 && return $1
  454. return 0
  455. }
  456. update_mime_database()
  457. {
  458. if [ x"$mode" = x"user" -a -n "$DISPLAY" ] ; then
  459. detectDE
  460. if [ x"$DE" = x"kde" ] ; then
  461. DEBUG 1 "Running kbuildsycoca"
  462. if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
  463. eval 'kbuildsycoca4'$xdg_redirect_output
  464. else
  465. eval 'kbuildsycoca'$xdg_redirect_output
  466. fi
  467. fi
  468. fi
  469. for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do
  470. if [ -x $x/update-mime-database ] ; then
  471. DEBUG 1 "Running $x/update-mime-database $1"
  472. eval '$x/update-mime-database $1'$xdg_redirect_output
  473. return
  474. fi
  475. done
  476. }
  477. info_kde()
  478. {
  479. if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
  480. DEBUG 1 "Running kmimetypefinder \"$1\""
  481. kmimetypefinder "$1" 2>/dev/null | head -n 1
  482. else
  483. DEBUG 1 "Running kfile \"$1\""
  484. kfile "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1
  485. fi
  486. if [ $? -eq 0 ]; then
  487. exit_success
  488. else
  489. exit_failure_operation_failed
  490. fi
  491. }
  492. info_gnome()
  493. {
  494. if gvfs-info --help 2>/dev/null 1>&2; then
  495. DEBUG 1 "Running gvfs-info \"$1\""
  496. gvfs-info "$1" 2> /dev/null | grep standard::content-type | cut -d' ' -f4
  497. elif gnomevfs-info --help 2>/dev/null 1>&2; then
  498. DEBUG 1 "Running gnomevfs-info \"$1\""
  499. gnomevfs-info --slow-mime "$1" 2> /dev/null | grep "^MIME" | cut -d ":" -f 2 | sed s/"^ "//
  500. else
  501. # according to https://bugs.freedesktop.org/show_bug.cgi?id=33094#c5
  502. # neither gvfs-info or gnomevfs-info are present in a default Ubuntu Natty
  503. # install, so fallback to info_generic
  504. info_generic "$1"
  505. fi
  506. if [ $? -eq 0 ]; then
  507. exit_success
  508. else
  509. exit_failure_operation_failed
  510. fi
  511. }
  512. info_generic()
  513. {
  514. if mimetype --version >/dev/null 2>&1; then
  515. DEBUG 1 "Running mimetype -b \"$1\""
  516. mimetype -b "$1"
  517. else
  518. DEBUG 1 "Running file --mime-type \"$1\""
  519. /usr/bin/file --mime-type "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "//
  520. fi
  521. if [ $? -eq 0 ]; then
  522. exit_success
  523. else
  524. exit_failure_operation_failed
  525. fi
  526. }
  527. make_default_kde()
  528. {
  529. # $1 is vendor-name.desktop
  530. # $2 is mime/type
  531. #
  532. # On KDE 3, add to $KDE_CONFIG_PATH/profilerc:
  533. # [$2 - 1]
  534. # Application=$1
  535. #
  536. # Remove all [$2 - *] sections, or even better,
  537. # renumber [$2 - *] sections and remove duplicate
  538. #
  539. # On KDE 4, add $2=$1 to $XDG_DATA_APPS/mimeapps.list
  540. #
  541. # Example file:
  542. #
  543. # [Added Associations]
  544. # text/plain=kde4-kate.desktop;kde4-kwrite.desktop;
  545. #
  546. # [Removed Associations]
  547. # text/plain=gnome-gedit.desktop;gnu-emacs.desktop;
  548. vendor="$1"
  549. mimetype="$2"
  550. if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
  551. default_dir=`kde4-config --path xdgdata-apps 2> /dev/null | cut -d ':' -f 1`
  552. default_file="$default_dir/mimeapps.list"
  553. else
  554. default_dir=`kde-config --path config 2> /dev/null | cut -d ':' -f 1`
  555. default_file="$default_dir/profilerc"
  556. fi
  557. if [ -z "$default_dir" ]; then
  558. DEBUG 2 "make_default_kde: No kde runtime detected"
  559. return
  560. fi
  561. DEBUG 2 "make_default_kde $vendor $mimetype"
  562. DEBUG 1 "Updating $default_file"
  563. mkdir -p "$default_dir"
  564. [ -f "$default_file" ] || touch "$default_file"
  565. if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
  566. [ -f "$default_file" ] || touch "$default_file"
  567. awk -v application="$vendor" -v mimetype="$mimetype" '
  568. BEGIN {
  569. prefix=mimetype "="
  570. associations=0
  571. found=0
  572. blanks=0
  573. }
  574. {
  575. suppress=0
  576. if (index($0, "[Added Associations]") == 1) {
  577. associations=1
  578. } else if (index($0, "[") == 1) {
  579. if (associations && !found) {
  580. print prefix application
  581. found=1
  582. }
  583. associations=0
  584. } else if ($0 == "") {
  585. blanks++
  586. suppress=1
  587. } else if (associations && index($0, prefix) == 1) {
  588. value=substr($0, length(prefix) + 1, length)
  589. split(value, apps, ";")
  590. value=application ";"
  591. count=0
  592. for (i in apps) {
  593. count++
  594. }
  595. for (i=0; i < count; i++) {
  596. if (apps[i] != application && apps[i] != "") {
  597. value=value apps[i] ";"
  598. }
  599. }
  600. $0=prefix value
  601. found=1
  602. }
  603. if (!suppress) {
  604. while (blanks > 0) {
  605. print ""
  606. blanks--
  607. }
  608. print $0
  609. }
  610. }
  611. END {
  612. if (!found) {
  613. if (!associations) {
  614. print "[Added Associations]"
  615. }
  616. print prefix application
  617. }
  618. while (blanks > 0) {
  619. print ""
  620. blanks--
  621. }
  622. }
  623. ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_file"
  624. eval 'kbuildsycoca4'$xdg_redirect_output
  625. else
  626. awk -v application="$vendor" -v mimetype="$mimetype" '
  627. BEGIN {
  628. header_start="[" mimetype " - "
  629. suppress=0
  630. }
  631. {
  632. if (index($0, header_start) == 1 )
  633. suppress=1
  634. else
  635. if (/^\[/) { suppress=0 }
  636. if (!suppress) {
  637. print $0
  638. }
  639. }
  640. END {
  641. print ""
  642. print "[" mimetype " - 1]"
  643. print "Application=" application
  644. print "AllowAsDefault=true"
  645. print "GenericServiceType=Application"
  646. print "Preference=1"
  647. print "ServiceType=" mimetype
  648. }
  649. ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_file"
  650. fi
  651. }
  652. make_default_generic()
  653. {
  654. # $1 is vendor-name.desktop
  655. # $2 is mime/type
  656. # Add $2=$1 to XDG_DATA_HOME/applications/mimeapps.list
  657. xdg_user_dir="$XDG_DATA_HOME"
  658. [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
  659. default_file="$xdg_user_dir/applications/mimeapps.list"
  660. DEBUG 2 "make_default_generic $1 $2"
  661. DEBUG 1 "Updating $default_file"
  662. [ -f "$default_file" ] || touch "$default_file"
  663. awk -v mimetype="$2" -v application="$1" '
  664. BEGIN {
  665. prefix=mimetype "="
  666. indefault=0
  667. added=0
  668. blanks=0
  669. found=0
  670. }
  671. {
  672. suppress=0
  673. if (index($0, "[Default Applications]") == 1) {
  674. indefault=1
  675. found=1
  676. } else if (index($0, "[") == 1) {
  677. if (!added && indefault) {
  678. print prefix application
  679. added=1
  680. }
  681. indefault=0
  682. } else if ($0 == "") {
  683. suppress=1
  684. blanks++
  685. } else if (indefault && !added && index($0, prefix) == 1) {
  686. $0=prefix application
  687. added=1
  688. }
  689. if (!suppress) {
  690. while (blanks > 0) {
  691. print ""
  692. blanks--
  693. }
  694. print $0
  695. }
  696. }
  697. END {
  698. if (!added) {
  699. if (!found) {
  700. print ""
  701. print "[Default Applications]"
  702. }
  703. print prefix application
  704. }
  705. while (blanks > 0) {
  706. print ""
  707. blanks--
  708. }
  709. }
  710. ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_file"
  711. }
  712. defapp_generic()
  713. {
  714. MIME="$1"
  715. xdg_user_dir="$XDG_DATA_HOME"
  716. [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
  717. xdg_user_dir="$xdg_user_dir/$xdg_dir_name"
  718. xdg_system_dirs="$XDG_DATA_DIRS"
  719. [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
  720. for x in `echo "$xdg_user_dir" | sed 's/:/ /g'`; do
  721. mimeapps_list="$x/applications/mimeapps.list"
  722. if [ -f "$mimeapps_list" ] ; then
  723. DEBUG 2 "Checking $mimeapps_list"
  724. trader_result=`awk -v mimetype="$MIME" '
  725. BEGIN {
  726. prefix=mimetype "="
  727. indefault=0
  728. found=0
  729. }
  730. {
  731. if (index($0, "[Default Applications]") == 1) {
  732. indefault=1
  733. } else if (index($0, "[") == 1) {
  734. indefault=0
  735. } else if (!found && indefault && index($0, prefix) == 1) {
  736. print substr($0, length(prefix) +1, length)
  737. found=1
  738. }
  739. }
  740. ' $mimeapps_list`
  741. if [ -n "$trader_result" ] ; then
  742. echo $trader_result
  743. exit_success
  744. fi
  745. fi
  746. done
  747. for x in `echo "$xdg_system_dirs" | sed 's/:/ /g'`; do
  748. DEBUG 2 "Checking $x/applications/defaults.list"
  749. trader_result=`grep "$MIME=" $x/applications/defaults.list 2> /dev/null | cut -d '=' -f 2 | cut -d ';' -f 1`
  750. if [ -n "$trader_result" ] ; then
  751. echo $trader_result
  752. exit_success
  753. fi
  754. done
  755. exit_success
  756. }
  757. defapp_kde()
  758. {
  759. MIME="$1"
  760. if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
  761. KTRADER=`which ktraderclient 2> /dev/null`
  762. MIMETYPE="--mimetype"
  763. SERVICETYPE="--servicetype"
  764. else
  765. KTRADER=`which ktradertest 2> /dev/null`
  766. fi
  767. if [ -n "$KTRADER" ] ; then
  768. DEBUG 1 "Running KDE trader query \"$MIME\" mimetype and \"Application\" servicetype"
  769. trader_result=`$KTRADER $MIMETYPE "$MIME" $SERVICETYPE Application 2>/dev/null \
  770. | grep DesktopEntryPath | head -n 1 | cut -d ':' -f 2 | cut -d \' -f 2`
  771. if [ -n "$trader_result" ] ; then
  772. basename "$trader_result"
  773. exit_success
  774. else
  775. exit_failure_operation_failed
  776. fi
  777. else
  778. defapp_generic "$1"
  779. fi
  780. }
  781. [ x"$1" != x"" ] || exit_failure_syntax
  782. mode=
  783. action=
  784. filename=
  785. mimetype=
  786. case $1 in
  787. install)
  788. action=install
  789. ;;
  790. uninstall)
  791. action=uninstall
  792. ;;
  793. query)
  794. shift
  795. if [ -z "$1" ] ; then
  796. exit_failure_syntax "query type argument missing"
  797. fi
  798. case $1 in
  799. filetype)
  800. action=info
  801. filename="$2"
  802. if [ -z "$filename" ] ; then
  803. exit_failure_syntax "FILE argument missing"
  804. fi
  805. case $filename in
  806. -*)
  807. exit_failure_syntax "unexpected option '$filename'"
  808. ;;
  809. esac
  810. check_input_file "$filename"
  811. filename=`readlink -f -- "$filename"`
  812. ;;
  813. default)
  814. action=defapp
  815. mimetype="$2"
  816. if [ -z "$mimetype" ] ; then
  817. exit_failure_syntax "mimetype argument missing"
  818. fi
  819. case $mimetype in
  820. -*)
  821. exit_failure_syntax "unexpected option '$mimetype'"
  822. ;;
  823. */*)
  824. # Ok
  825. ;;
  826. *)
  827. exit_failure_syntax "mimetype '$mimetype' is not in the form 'minor/major'"
  828. ;;
  829. esac
  830. ;;
  831. *)
  832. exit_failure_syntax "unknown query type '$1'"
  833. ;;
  834. esac
  835. ;;
  836. default)
  837. action=makedefault
  838. shift
  839. if [ -z "$1" ] ; then
  840. exit_failure_syntax "application argument missing"
  841. fi
  842. case $1 in
  843. -*)
  844. exit_failure_syntax "unexpected option '$1'"
  845. ;;
  846. *.desktop)
  847. filename="$1"
  848. ;;
  849. *)
  850. exit_failure_syntax "malformed argument '$1', expected *.desktop"
  851. ;;
  852. esac
  853. ;;
  854. *)
  855. exit_failure_syntax "unknown command '$1'"
  856. ;;
  857. esac
  858. shift
  859. if [ "$action" = "makedefault" ]; then
  860. if [ -z "$1" ] ; then
  861. exit_failure_syntax "mimetype argument missing"
  862. fi
  863. while [ $# -gt 0 ] ; do
  864. case $1 in
  865. -*)
  866. exit_failure_syntax "unexpected option '$1'"
  867. ;;
  868. esac
  869. mimetype="$1"
  870. shift
  871. make_default_kde "$filename" "$mimetype"
  872. make_default_generic "$filename" "$mimetype"
  873. done
  874. exit_success
  875. fi
  876. if [ "$action" = "info" ]; then
  877. detectDE
  878. if [ x"$DE" = x"" ]; then
  879. if [ -x /usr/bin/file ]; then
  880. DE=generic
  881. fi
  882. fi
  883. case "$DE" in
  884. kde)
  885. info_kde "$filename"
  886. ;;
  887. gnome*)
  888. info_gnome "$filename"
  889. ;;
  890. *)
  891. info_generic "$filename"
  892. ;;
  893. esac
  894. exit_failure_operation_impossible "no method available for quering MIME type of '$filename'"
  895. fi
  896. if [ "$action" = "defapp" ]; then
  897. detectDE
  898. case "$DE" in
  899. kde)
  900. defapp_kde "$mimetype"
  901. ;;
  902. *)
  903. defapp_generic "$mimetype"
  904. ;;
  905. esac
  906. exit_failure_operation_impossible "no method available for quering default application for '$mimetype'"
  907. fi
  908. vendor=true
  909. while [ $# -gt 0 ] ; do
  910. parm="$1"
  911. shift
  912. case $parm in
  913. --mode)
  914. if [ -z "$1" ] ; then
  915. exit_failure_syntax "mode argument missing for --mode"
  916. fi
  917. case "$1" in
  918. user)
  919. mode="user"
  920. ;;
  921. system)
  922. mode="system"
  923. ;;
  924. *)
  925. exit_failure_syntax "unknown mode '$1'"
  926. ;;
  927. esac
  928. shift
  929. ;;
  930. --novendor)
  931. vendor=false
  932. ;;
  933. -*)
  934. exit_failure_syntax "unexpected option '$parm'"
  935. ;;
  936. *)
  937. if [ -n "$filename" ] ; then
  938. exit_failure_syntax "unexpected argument '$parm'"
  939. fi
  940. filename="$parm"
  941. check_input_file "$filename"
  942. ;;
  943. esac
  944. done
  945. if [ -z "$action" ] ; then
  946. exit_failure_syntax "command argument missing"
  947. fi
  948. if [ -n "$XDG_UTILS_INSTALL_MODE" ] ; then
  949. if [ "$XDG_UTILS_INSTALL_MODE" = "system" ] ; then
  950. mode="system"
  951. elif [ "$XDG_UTILS_INSTALL_MODE" = "user" ] ; then
  952. mode="user"
  953. fi
  954. fi
  955. if [ -z "$mode" ] ; then
  956. if [ `whoami` = "root" ] ; then
  957. mode="system"
  958. else
  959. mode="user"
  960. fi
  961. fi
  962. if [ -z "$filename" ] ; then
  963. exit_failure_syntax "mimetypes-file argument missing"
  964. fi
  965. if [ "$vendor" = "true" -a "$action" = "install" ] ; then
  966. check_vendor_prefix "$filename"
  967. fi
  968. xdg_base_dir=
  969. xdg_dir_name=mime/packages/
  970. xdg_user_dir="$XDG_DATA_HOME"
  971. [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
  972. [ x"$mode" = x"user" ] && xdg_base_dir="$xdg_user_dir/mime"
  973. xdg_user_dir="$xdg_user_dir/$xdg_dir_name"
  974. xdg_system_dirs="$XDG_DATA_DIRS"
  975. [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
  976. for x in `echo $xdg_system_dirs | sed 's/:/ /g'`; do
  977. if [ -w $x/$xdg_dir_name ] ; then
  978. [ x"$mode" = x"system" ] && xdg_base_dir="$x/mime"
  979. xdg_global_dir="$x/$xdg_dir_name"
  980. break
  981. fi
  982. done
  983. [ -w $xdg_global_dir ] || xdg_global_dir=
  984. DEBUG 3 "xdg_user_dir: $xdg_user_dir"
  985. DEBUG 3 "xdg_global_dir: $xdg_global_dir"
  986. # Find KDE3 mimelnk directory
  987. kde_user_dir=
  988. kde_global_dir=
  989. kde_global_dirs=`kde${KDE_SESSION_VERSION}-config --path mime 2> /dev/null`
  990. DEBUG 3 "kde_global_dirs: $kde_global_dirs"
  991. first=
  992. for x in `echo $kde_global_dirs | sed 's/:/ /g'` ; do
  993. if [ -z "$first" ] ; then
  994. first=false
  995. kde_user_dir="$x"
  996. elif [ -w $x ] ; then
  997. kde_global_dir="$x"
  998. fi
  999. done
  1000. DEBUG 3 "kde_user_dir: $kde_user_dir"
  1001. DEBUG 3 "kde_global_dir: $kde_global_dir"
  1002. # TODO: Gnome legacy support
  1003. # See http://forums.fedoraforum.org/showthread.php?t=26875
  1004. gnome_user_dir="$HOME/.gnome/apps"
  1005. gnome_global_dir=/usr/share/gnome/apps
  1006. [ -w $gnome_global_dir ] || gnome_global_dir=
  1007. DEBUG 3 "gnome_user_dir: $gnome_user_dir"
  1008. DEBUG 3 "gnome_global_dir: $gnome_global_dir"
  1009. if [ x"$mode" = x"user" ] ; then
  1010. xdg_dir="$xdg_user_dir"
  1011. kde_dir="$kde_user_dir"
  1012. gnome_dir="$gnome_user_dir"
  1013. my_umask=077
  1014. else
  1015. xdg_dir="$xdg_global_dir"
  1016. kde_dir="$kde_global_dir"
  1017. gnome_dir="$gnome_global_dir"
  1018. my_umask=022
  1019. if [ -z "${xdg_dir}${kde_dir}${gnome_dir}" ] ; then
  1020. exit_failure_operation_impossible "No writable system mimetype directory found."
  1021. fi
  1022. fi
  1023. # echo "[xdg|$xdg_user_dir|$xdg_global_dir]"
  1024. # echo "[kde|$kde_user_dir|$kde_global_dir]"
  1025. # echo "[gnome|$gnome_user_dir|$gnome_global_dir]"
  1026. # echo "[using|$xdg_dir|$kde_dir|$gnome_dir]"
  1027. basefile=`basename "$filename"`
  1028. #[ -z $vendor ] || basefile="$vendor-$basefile"
  1029. mimetypes=
  1030. if [ -n "$kde_dir" ] ; then
  1031. DEBUG 2 "KDE3 mimelnk directory found, extracting mimetypes from XML file"
  1032. mimetypes=`awk < "$filename" '
  1033. # Strip XML comments
  1034. BEGIN {
  1035. suppress=0
  1036. }
  1037. {
  1038. do
  1039. if (suppress) {
  1040. if (match($0,/-->/)) {
  1041. $0=substr($0,RSTART+RLENGTH)
  1042. suppress=0
  1043. }
  1044. else {
  1045. break
  1046. }
  1047. }
  1048. else {
  1049. if (match($0,/<!--/)) {
  1050. if (RSTART>1) print substr($0,0,RSTART)
  1051. $0=substr($0,RSTART+RLENGTH)
  1052. suppress=1
  1053. }
  1054. else {
  1055. if ($0) print $0
  1056. break
  1057. }
  1058. }
  1059. while(1)
  1060. }
  1061. ' | awk '
  1062. # List MIME types listed in <mime-type> tags
  1063. BEGIN {
  1064. RS="<"
  1065. }
  1066. /^mime-info/, /^\/mime-info/ {
  1067. if (match($0,/^mime-type/)) {
  1068. if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) {
  1069. print substr($0,RSTART+6,RLENGTH-6)
  1070. }
  1071. }
  1072. }'`
  1073. fi
  1074. DEBUG 1 "$action mimetype in $xdg_dir"
  1075. case $action in
  1076. install)
  1077. save_umask=`umask`
  1078. umask $my_umask
  1079. for x in $xdg_dir ; do
  1080. mkdir -p $x
  1081. eval 'cp $filename $x/$basefile'$xdg_redirect_output
  1082. done
  1083. if [ -n "$mimetypes" ] ; then
  1084. # No quotes around $mimetypes
  1085. for x in $mimetypes ; do
  1086. DEBUG 1 "Installing $kde_dir/$x.desktop (KDE 3.x support)"
  1087. mkdir -p `dirname $kde_dir/$x.desktop`
  1088. awk < "$filename" '
  1089. # Strip XML comments
  1090. BEGIN {
  1091. suppress=0
  1092. }
  1093. {
  1094. do
  1095. if (suppress) {
  1096. if (match($0,/-->/)) {
  1097. $0=substr($0,RSTART+RLENGTH)
  1098. suppress=0
  1099. }
  1100. else {
  1101. break
  1102. }
  1103. }
  1104. else {
  1105. if (match($0,/<!--/)) {
  1106. if (RSTART>1) print substr($0,0,RSTART)
  1107. $0=substr($0,RSTART+RLENGTH)
  1108. suppress=1
  1109. }
  1110. else {
  1111. if ($0) print $0
  1112. break
  1113. }
  1114. }
  1115. while(1)
  1116. }
  1117. ' | awk > $kde_dir/$x.desktop '
  1118. # Extract mimetype $x from the XML file $filename
  1119. # Note that bash requires us to escape a single quote as '"'"'
  1120. BEGIN {
  1121. the_type=ARGV[1]
  1122. the_source=ARGV[2]
  1123. ARGC=1
  1124. RS="<"
  1125. found=0
  1126. glob_patterns=""
  1127. }
  1128. /^mime-info/, /^\/mime-info/ {
  1129. if (match($0,/^mime-type/)) {
  1130. if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) {
  1131. if (substr($0,RSTART+6,RLENGTH-6) == the_type) {
  1132. found=1
  1133. print "[Desktop Entry]"
  1134. print "# Installed by xdg-mime from " the_source
  1135. print "Type=MimeType"
  1136. print "MimeType=" the_type
  1137. the_icon=the_type
  1138. sub("/", "-", the_icon)
  1139. print "Icon=" the_icon
  1140. }
  1141. }
  1142. }
  1143. else if (found) {
  1144. if (match($0,/^\/mime-type/)) {
  1145. if (glob_patterns)
  1146. print "Patterns=" glob_patterns
  1147. exit 0
  1148. }
  1149. if (match($0,/^sub-class-of/)) {
  1150. if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) {
  1151. print "X-KDE-IsAlso=" substr($0,RSTART+6,RLENGTH-6)
  1152. }
  1153. else {
  1154. print "Error: '"'"'type'"'"' argument missing in " RS $0
  1155. exit 1
  1156. }
  1157. }
  1158. if (match($0,/^glob/)) {
  1159. if (match($0,/pattern="[^"]*/) || match($0,/pattern='"'"'[^'"'"']*/)) {
  1160. glob_patterns = glob_patterns substr($0,RSTART+9,RLENGTH-9) ";"
  1161. }
  1162. else {
  1163. print "Error: '"'"'pattern'"'"' argument missing in " RS $0
  1164. exit 1
  1165. }
  1166. }
  1167. if (match($0,/^comment/)) {
  1168. if (match($0,/xml:lang="[^"]*/) || match($0,/xml:lang='"'"'[^'"'"']*/)) {
  1169. lang=substr($0,RSTART+10,RLENGTH-10)
  1170. }
  1171. else {
  1172. lang=""
  1173. }
  1174. if (match($0,/>/)) {
  1175. comment=substr($0,RSTART+1)
  1176. sub("&lt;", "<", comment)
  1177. sub("&gt;", ">", comment)
  1178. sub("&amp;", "\\&", comment)
  1179. if (lang)
  1180. print "Comment[" lang "]=" comment
  1181. else
  1182. print "Comment=" comment
  1183. }
  1184. }
  1185. }
  1186. }
  1187. END {
  1188. if (!found) {
  1189. print "Error: Mimetype '"'"'" the_type "'"'"' not found"
  1190. exit 1
  1191. }
  1192. }
  1193. ' $x $basefile
  1194. if [ "$?" = "1" ] ; then
  1195. grep -A 10 "^Error:" $kde_dir/$x.desktop >&2
  1196. rm $kde_dir/$x.desktop
  1197. exit 1
  1198. fi
  1199. done
  1200. fi
  1201. umask $save_umask
  1202. ;;
  1203. uninstall)
  1204. for x in $xdg_dir ; do
  1205. rm -f $x/$basefile
  1206. done
  1207. # No quotes around $mimetypes
  1208. for x in $mimetypes ; do
  1209. if grep '^# Installed by xdg-mime' $kde_dir/$x.desktop >/dev/null 2>&1; then
  1210. DEBUG 1 "Removing $kde_dir/$x.desktop (KDE 3.x support)"
  1211. rm -f $kde_dir/$x.desktop
  1212. fi
  1213. done
  1214. ;;
  1215. esac
  1216. update_mime_database $xdg_base_dir
  1217. exit_success