| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 #--------------------------------------------- | 2 #--------------------------------------------- |
| 3 # xdg-mime | 3 # xdg-mime |
| 4 # | 4 # |
| 5 # Utility script to manipulate MIME related information | 5 # Utility script to manipulate MIME related information |
| 6 # on XDG compliant systems. | 6 # on XDG compliant systems. |
| 7 # | 7 # |
| 8 # Refer to the usage() function below for usage. | 8 # Refer to the usage() function below for usage. |
| 9 # | 9 # |
| 10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> | 10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } | 27 } |
| 28 | 28 |
| 29 #@xdg-utils-common@ | 29 #@xdg-utils-common@ |
| 30 | 30 |
| 31 update_mime_database() | 31 update_mime_database() |
| 32 { | 32 { |
| 33 if [ x"$mode" = x"user" -a -n "$DISPLAY" ] ; then | 33 if [ x"$mode" = x"user" -a -n "$DISPLAY" ] ; then |
| 34 detectDE | 34 detectDE |
| 35 if [ x"$DE" = x"kde" ] ; then | 35 if [ x"$DE" = x"kde" ] ; then |
| 36 DEBUG 1 "Running kbuildsycoca" | 36 DEBUG 1 "Running kbuildsycoca" |
| 37 eval 'kbuildsycoca'$xdg_redirect_output | 37 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
| 38 eval 'kbuildsycoca4'$xdg_redirect_output |
| 39 else |
| 40 eval 'kbuildsycoca'$xdg_redirect_output |
| 41 fi |
| 38 fi | 42 fi |
| 39 fi | 43 fi |
| 40 for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do | 44 for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do |
| 41 if [ -x $x/update-mime-database ] ; then | 45 if [ -x $x/update-mime-database ] ; then |
| 42 DEBUG 1 "Running $x/update-mime-database $1" | 46 DEBUG 1 "Running $x/update-mime-database $1" |
| 43 eval '$x/update-mime-database $1'$xdg_redirect_output | 47 eval '$x/update-mime-database $1'$xdg_redirect_output |
| 44 return | 48 return |
| 45 fi | 49 fi |
| 46 done | 50 done |
| 47 } | 51 } |
| 48 | 52 |
| 49 info_kde() | 53 info_kde() |
| 50 { | 54 { |
| 51 if which "kmimetypefinder" > /dev/null 2>/dev/null; then | 55 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
| 52 DEBUG 1 "Running kmimetypefinder \"$1\"" | 56 DEBUG 1 "Running kmimetypefinder \"$1\"" |
| 53 kmimetypefinder "$1" 2>/dev/null | head -n 1 | 57 KMIMETYPEFINDER=`which kmimetypefinder 2>/dev/null` |
| 58 $KMIMETYPEFINDER "$1" 2>/dev/null | head -n 1 |
| 54 else | 59 else |
| 55 DEBUG 1 "Running kfile \"$1\"" | 60 DEBUG 1 "Running kfile \"$1\"" |
| 56 kfile "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1 | 61 KFILE=`which kfile 2>/dev/null` |
| 62 $KFILE "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1 |
| 57 fi | 63 fi |
| 58 | 64 |
| 59 exit_success | 65 if [ $? -eq 0 ]; then |
| 66 exit_success |
| 67 else |
| 68 exit_failure_operation_failed |
| 69 fi |
| 60 } | 70 } |
| 61 | 71 |
| 62 info_gnome() | 72 info_gnome() |
| 63 { | 73 { |
| 64 file=`readlink -f "$1"` # Normalize path | 74 file=`readlink -f "$1"` # Normalize path |
| 65 DEBUG 1 "Running gnomevfs-info \"$file\"" | |
| 66 gnomevfs-info "$file" 2> /dev/null | grep MIME | cut -d ":" -f 2 | sed s/"^
"// | |
| 67 | 75 |
| 68 exit_success | 76 if gvfs-info --help 2>/dev/null 1>&2; then |
| 77 DEBUG 1 "Running gvfs-info \"$file\"" |
| 78 gvfs-info "$file" 2> /dev/null | grep standard::content-type | cut -d' '
-f4 |
| 79 else |
| 80 DEBUG 1 "Running gnomevfs-info \"$file\"" |
| 81 gnomevfs-info --slow-mime "$file" 2> /dev/null | grep "^MIME" | cut -d ":
" -f 2 | sed s/"^ "// |
| 82 fi |
| 83 |
| 84 if [ $? -eq 0 ]; then |
| 85 exit_success |
| 86 else |
| 87 exit_failure_operation_failed |
| 88 fi |
| 69 } | 89 } |
| 70 | 90 |
| 71 info_generic() | 91 info_generic() |
| 72 { | 92 { |
| 73 DEBUG 1 "Running /usr/bin/file -i \"$1\"" | 93 DEBUG 1 "Running file -i \"$1\"" |
| 74 /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "// | 94 /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "// |
| 75 | 95 |
| 76 exit_success | 96 if [ $? -eq 0 ]; then |
| 97 exit_success |
| 98 else |
| 99 exit_failure_operation_failed |
| 100 fi |
| 77 } | 101 } |
| 78 | 102 |
| 79 make_default_kde() | 103 make_default_kde() |
| 80 { | 104 { |
| 81 # $1 is vendor-name.desktop | 105 # $1 is vendor-name.desktop |
| 82 # $2 is mime/type | 106 # $2 is mime/type |
| 83 # Add to $KDE_HOME/share/config/profilerc: | 107 # |
| 108 # On KDE 3, add to $KDE_CONFIG_PATH/profilerc: |
| 84 # [$2 - 1] | 109 # [$2 - 1] |
| 85 # Application=$1 | 110 # Application=$1 |
| 86 # | 111 # |
| 87 # Remove all [$2 - *] sections, or even better, | 112 # Remove all [$2 - *] sections, or even better, |
| 88 # renumber [$2 - *] sections and remove duplicate | 113 # renumber [$2 - *] sections and remove duplicate |
| 89 | 114 # |
| 90 default_file="$HOME/.kde/share/config/profilerc" | 115 # On KDE 4, add $2=$1 to $XDG_DATA_APPS/mimeapps.list |
| 91 DEBUG 2 "make_default_kde $1 $2" | 116 # |
| 117 # Example file: |
| 118 # |
| 119 # [Added Associations] |
| 120 # text/plain=kde4-kate.desktop;kde4-kwrite.desktop; |
| 121 # |
| 122 # [Removed Associations] |
| 123 # text/plain=gnome-gedit.desktop;gnu-emacs.desktop; |
| 124 vendor="$1" |
| 125 mimetype="$2" |
| 126 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
| 127 default_dir=`kde4-config --path xdgdata-apps 2> /dev/null | cut -d ':' -
f 1` |
| 128 default_file="$default_dir/mimeapps.list" |
| 129 else |
| 130 default_dir=`kde-config --path config 2> /dev/null | cut -d ':' -f 1` |
| 131 default_file="$default_dir/profilerc" |
| 132 fi |
| 133 if [ -z "$default_dir" ]; then |
| 134 DEBUG 2 "make_default_kde: No kde runtime detected" |
| 135 return |
| 136 fi |
| 137 DEBUG 2 "make_default_kde $vendor $mimetype" |
| 92 DEBUG 1 "Updating $default_file" | 138 DEBUG 1 "Updating $default_file" |
| 93 mkdir -p "$HOME/.kde/share/config" | 139 mkdir -p "$default_dir" |
| 94 [ -f $default_file ] || touch $default_file | 140 [ -f $default_file ] || touch $default_file |
| 95 awk -v application="$1" -v mimetype="$2" ' | 141 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
| 142 [ -f $default_file ] || touch $default_file |
| 143 awk -v application="$vendor" -v mimetype="$mimetype" ' |
| 96 BEGIN { | 144 BEGIN { |
| 97 header_start="[" mimetype " - " | 145 prefix=mimetype "=" |
| 98 supress=0 | 146 associations=0 |
| 147 found=0 |
| 148 blanks=0 |
| 99 } | 149 } |
| 100 { | 150 { |
| 101 if (index($0, header_start) == 1 ) | 151 suppress=0 |
| 102 supress=1 | 152 if (index($0, "[Added Associations]") == 1) { |
| 103 else | 153 associations=1 |
| 104 if (/^\[/) { supress=0 } | 154 } else if (index($0, "[") == 1) { |
| 105 | 155 if (associations && !found) { |
| 106 if (!supress) { | 156 print prefix application |
| 157 found=1 |
| 158 } |
| 159 associations=0 |
| 160 } else if ($0 == "") { |
| 161 blanks++ |
| 162 suppress=1 |
| 163 } else if (associations && index($0, prefix) == 1) { |
| 164 value=substr($0, length(prefix) + 1, length) |
| 165 split(value, apps, ";") |
| 166 value=application ";" |
| 167 count=0 |
| 168 for (i in apps) { |
| 169 count++ |
| 170 } |
| 171 for (i=0; i < count; i++) { |
| 172 if (apps[i] != application && apps[i] != "") { |
| 173 value=value apps[i] ";" |
| 174 } |
| 175 } |
| 176 $0=prefix value |
| 177 found=1 |
| 178 } |
| 179 if (!suppress) { |
| 180 while (blanks > 0) { |
| 181 print "" |
| 182 blanks-- |
| 183 } |
| 107 print $0 | 184 print $0 |
| 108 } | 185 } |
| 109 } | 186 } |
| 110 END { | 187 END { |
| 111 print "" | 188 if (!found) { |
| 189 if (!associations) { |
| 190 print "[Added Associations]" |
| 191 } |
| 192 print prefix application |
| 193 } |
| 194 while (blanks > 0) { |
| 195 print "" |
| 196 blanks-- |
| 197 } |
| 198 } |
| 199 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file |
| 200 eval 'kbuildsycoca4'$xdg_redirect_output |
| 201 else |
| 202 awk -v application="$vendor" -v mimetype="$mimetype" ' |
| 203 BEGIN { |
| 204 header_start="[" mimetype " - " |
| 205 suppress=0 |
| 206 } |
| 207 { |
| 208 if (index($0, header_start) == 1 ) |
| 209 suppress=1 |
| 210 else |
| 211 if (/^\[/) { suppress=0 } |
| 212 |
| 213 if (!suppress) { |
| 214 print $0 |
| 215 } |
| 216 } |
| 217 END { |
| 218 print "" |
| 112 print "[" mimetype " - 1]" | 219 print "[" mimetype " - 1]" |
| 113 print "Application=" application | 220 print "Application=" application |
| 114 print "AllowAsDefault=true" | 221 print "AllowAsDefault=true" |
| 115 print "GenericServiceType=Application" | 222 print "GenericServiceType=Application" |
| 116 print "Preference=1" | 223 print "Preference=1" |
| 117 print "ServiceType=" mimetype | 224 print "ServiceType=" mimetype |
| 118 } | 225 } |
| 119 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file | 226 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file |
| 227 fi |
| 120 } | 228 } |
| 121 | 229 |
| 122 make_default_generic() | 230 make_default_generic() |
| 123 { | 231 { |
| 124 # $1 is vendor-name.desktop | 232 # $1 is vendor-name.desktop |
| 125 # $2 is mime/type | 233 # $2 is mime/type |
| 126 # Add $2=$1 to XDG_DATA_HOME/applications/defaults.list | 234 # Add $2=$1 to XDG_DATA_HOME/applications/defaults.list |
| 127 xdg_user_dir="$XDG_DATA_HOME" | 235 xdg_user_dir="$XDG_DATA_HOME" |
| 128 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" | 236 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" |
| 129 default_file="$xdg_user_dir/applications/defaults.list" | 237 default_file="$xdg_user_dir/applications/defaults.list" |
| 130 DEBUG 2 "make_default_generic $1 $2" | 238 DEBUG 2 "make_default_generic $1 $2" |
| 131 DEBUG 1 "Updating $default_file" | 239 DEBUG 1 "Updating $default_file" |
| 132 grep -v "$2=" $default_file > ${default_file}.new 2> /dev/null | 240 grep -v "$2=" $default_file > ${default_file}.new 2> /dev/null |
| 133 if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then | 241 if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then |
| 134 echo "[Default Applications]" >> ${default_file}.new | 242 echo "[Default Applications]" >> ${default_file}.new |
| 135 fi | 243 fi |
| (...skipping 17 matching lines...) Expand all Loading... |
| 153 echo $trader_result | 261 echo $trader_result |
| 154 exit_success | 262 exit_success |
| 155 fi | 263 fi |
| 156 done | 264 done |
| 157 exit_success | 265 exit_success |
| 158 } | 266 } |
| 159 | 267 |
| 160 defapp_kde() | 268 defapp_kde() |
| 161 { | 269 { |
| 162 MIME="$1" | 270 MIME="$1" |
| 163 ktradertest=`which ktradertest 2> /dev/null` | 271 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
| 164 if [ -n "$ktradertest" ] ; then | 272 KTRADER=`which ktraderclient 2> /dev/null` |
| 165 DEBUG 1 "Running ktradertest \"$MIME\" Application" | 273 MIMETYPE="--mimetype" |
| 166 trader_result=`ktradertest "$MIME" Application 2>/dev/null | grep Deskto
pEntryPath \ | 274 SERVICETYPE="--servicetype" |
| 167 | head -n 1 | cut -d ':' -f 2 | cut -d \' -f 2` | 275 else |
| 276 KTRADER=`which ktradertest 2> /dev/null` |
| 277 fi |
| 278 if [ -n "$KTRADER" ] ; then |
| 279 DEBUG 1 "Running KDE trader query \"$MIME\" mimetype and \"Application\"
servicetype" |
| 280 trader_result=`$KTRADER $MIMETYPE "$MIME" $SERVICETYPE Application 2>/de
v/null \ |
| 281 | grep DesktopEntryPath | head -n 1 | cut -d ':' -f 2 | cut -d \' -f
2` |
| 168 if [ -n "$trader_result" ] ; then | 282 if [ -n "$trader_result" ] ; then |
| 169 basename "$trader_result" | 283 basename "$trader_result" |
| 170 exit_success | 284 exit_success |
| 171 else | 285 else |
| 172 exit_failure_operation_failed | 286 exit_failure_operation_failed |
| 173 fi | 287 fi |
| 174 else | 288 else |
| 175 defapp_generic "$1" | 289 defapp_generic "$1" |
| 176 fi | 290 fi |
| 177 } | 291 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 action=install | 302 action=install |
| 189 ;; | 303 ;; |
| 190 | 304 |
| 191 uninstall) | 305 uninstall) |
| 192 action=uninstall | 306 action=uninstall |
| 193 ;; | 307 ;; |
| 194 | 308 |
| 195 query) | 309 query) |
| 196 shift | 310 shift |
| 197 | 311 |
| 198 if [ -z "$1" ] ; then | 312 if [ -z "$1" ] ; then |
| 199 exit_failure_syntax "query type argument missing" | 313 exit_failure_syntax "query type argument missing" |
| 200 fi | 314 fi |
| 201 | 315 |
| 202 case $1 in | 316 case $1 in |
| 203 filetype) | 317 filetype) |
| 204 action=info | 318 action=info |
| 205 | 319 |
| 206 filename="$2" | 320 filename="$2" |
| 207 if [ -z "$filename" ] ; then | 321 if [ -z "$filename" ] ; then |
| 208 exit_failure_syntax "FILE argument missing" | 322 exit_failure_syntax "FILE argument missing" |
| 209 fi | 323 fi |
| 210 case $filename in | 324 case $filename in |
| 211 -*) | 325 -*) |
| 212 exit_failure_syntax "unexpected option '$filename'" | 326 exit_failure_syntax "unexpected option '$filename'" |
| 213 ;; | 327 ;; |
| 214 esac | 328 esac |
| 215 check_input_file "$filename" | 329 check_input_file "$filename" |
| 216 ;; | 330 ;; |
| 217 | 331 |
| 218 default) | 332 default) |
| 219 action=defapp | 333 action=defapp |
| 220 mimetype="$2" | 334 mimetype="$2" |
| 221 if [ -z "$mimetype" ] ; then | 335 if [ -z "$mimetype" ] ; then |
| 222 exit_failure_syntax "mimetype argument missing" | 336 exit_failure_syntax "mimetype argument missing" |
| 223 fi | 337 fi |
| 224 case $mimetype in | 338 case $mimetype in |
| 225 -*) | 339 -*) |
| 226 exit_failure_syntax "unexpected option '$mimetype'" | 340 exit_failure_syntax "unexpected option '$mimetype'" |
| 227 ;; | 341 ;; |
| 228 | 342 |
| 229 */*) | 343 */*) |
| 230 # Ok | 344 # Ok |
| 231 ;; | 345 ;; |
| 232 | 346 |
| 233 *) | 347 *) |
| 234 exit_failure_syntax "mimetype '$mimetype' is not in the form 'minor/
major'" | 348 exit_failure_syntax "mimetype '$mimetype' is not in the form 'minor/
major'" |
| 235 ;; | 349 ;; |
| 236 esac | 350 esac |
| 237 ;; | 351 ;; |
| 238 | 352 |
| 239 *) | 353 *) |
| 240 exit_failure_syntax "unknown query type '$1'" | 354 exit_failure_syntax "unknown query type '$1'" |
| 241 ;; | 355 ;; |
| 242 esac | 356 esac |
| 243 ;; | 357 ;; |
| 244 | 358 |
| 245 default) | 359 default) |
| 246 action=makedefault | 360 action=makedefault |
| 247 shift | 361 shift |
| 248 | 362 |
| 249 if [ -z "$1" ] ; then | 363 if [ -z "$1" ] ; then |
| 250 exit_failure_syntax "application argument missing" | 364 exit_failure_syntax "application argument missing" |
| 251 fi | 365 fi |
| 252 case $1 in | 366 case $1 in |
| 253 -*) | 367 -*) |
| 254 exit_failure_syntax "unexpected option '$1'" | 368 exit_failure_syntax "unexpected option '$1'" |
| 255 ;; | 369 ;; |
| 256 | 370 |
| 257 *.desktop) | 371 *.desktop) |
| 258 filename="$1" | 372 filename="$1" |
| 259 ;; | 373 ;; |
| 260 | 374 |
| 261 *) | 375 *) |
| 262 exit_failure_syntax "malformed argument '$1', expected *.desktop" | 376 exit_failure_syntax "malformed argument '$1', expected *.desktop" |
| 263 ;; | 377 ;; |
| 264 esac | 378 esac |
| 265 ;; | 379 ;; |
| 266 | 380 |
| 267 *) | 381 *) |
| 268 exit_failure_syntax "unknown command '$1'" | 382 exit_failure_syntax "unknown command '$1'" |
| 269 ;; | 383 ;; |
| 270 esac | 384 esac |
| 271 | 385 |
| 272 shift | 386 shift |
| 273 | 387 |
| 274 | 388 |
| 275 if [ "$action" = "makedefault" ]; then | 389 if [ "$action" = "makedefault" ]; then |
| 276 if [ -z "$1" ] ; then | 390 if [ -z "$1" ] ; then |
| 277 exit_failure_syntax "mimetype argument missing" | 391 exit_failure_syntax "mimetype argument missing" |
| 278 fi | 392 fi |
| 279 | 393 |
| 280 while [ $# -gt 0 ] ; do | 394 while [ $# -gt 0 ] ; do |
| 281 case $1 in | 395 case $1 in |
| 282 -*) | 396 -*) |
| 283 exit_failure_syntax "unexpected option '$1'" | 397 exit_failure_syntax "unexpected option '$1'" |
| 284 ;; | 398 ;; |
| 285 esac | 399 esac |
| 286 mimetype="$1" | 400 mimetype="$1" |
| 287 shift | 401 shift |
| 288 | 402 |
| 289 make_default_kde "$filename" "$mimetype" | 403 make_default_kde "$filename" "$mimetype" |
| 290 make_default_generic "$filename" "$mimetype" | 404 make_default_generic "$filename" "$mimetype" |
| 291 done | 405 done |
| 292 exit_success | 406 exit_success |
| 293 fi | 407 fi |
| 294 | 408 |
| 295 if [ "$action" = "info" ]; then | 409 if [ "$action" = "info" ]; then |
| 296 detectDE | 410 detectDE |
| 297 | 411 |
| 298 if [ x"$DE" = x"" ]; then | 412 if [ x"$DE" = x"" ]; then |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 exit_failure_syntax "mode argument missing for --mode" | 457 exit_failure_syntax "mode argument missing for --mode" |
| 344 fi | 458 fi |
| 345 case "$1" in | 459 case "$1" in |
| 346 user) | 460 user) |
| 347 mode="user" | 461 mode="user" |
| 348 ;; | 462 ;; |
| 349 | 463 |
| 350 system) | 464 system) |
| 351 mode="system" | 465 mode="system" |
| 352 ;; | 466 ;; |
| 353 | 467 |
| 354 *) | 468 *) |
| 355 exit_failure_syntax "unknown mode '$1'" | 469 exit_failure_syntax "unknown mode '$1'" |
| 356 ;; | 470 ;; |
| 357 esac | 471 esac |
| 358 shift | 472 shift |
| 359 ;; | 473 ;; |
| 360 | 474 |
| 361 --novendor) | 475 --novendor) |
| 362 vendor=false | 476 vendor=false |
| 363 ;; | 477 ;; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 basefile=`basename "$filename"` | 588 basefile=`basename "$filename"` |
| 475 #[ -z $vendor ] || basefile="$vendor-$basefile" | 589 #[ -z $vendor ] || basefile="$vendor-$basefile" |
| 476 | 590 |
| 477 mimetypes= | 591 mimetypes= |
| 478 if [ -n "$kde_dir" ] ; then | 592 if [ -n "$kde_dir" ] ; then |
| 479 DEBUG 2 "KDE3 mimelnk directory found, extracting mimetypes from XML file" | 593 DEBUG 2 "KDE3 mimelnk directory found, extracting mimetypes from XML file" |
| 480 | 594 |
| 481 mimetypes=`awk < "$filename" ' | 595 mimetypes=`awk < "$filename" ' |
| 482 # Strip XML comments | 596 # Strip XML comments |
| 483 BEGIN { | 597 BEGIN { |
| 484 supress=0 | 598 suppress=0 |
| 485 } | 599 } |
| 486 { | 600 { |
| 487 do | 601 do |
| 488 if (supress) { | 602 if (suppress) { |
| 489 if (match($0,/-->/)) { | 603 if (match($0,/-->/)) { |
| 490 $0=substr($0,RSTART+RLENGTH) | 604 $0=substr($0,RSTART+RLENGTH) |
| 491 supress=0 | 605 suppress=0 |
| 492 } | 606 } |
| 493 else { | 607 else { |
| 494 break | 608 break |
| 495 } | 609 } |
| 496 } | 610 } |
| 497 else { | 611 else { |
| 498 if (match($0,/<!--/)) { | 612 if (match($0,/<!--/)) { |
| 499 if (RSTART>1) print substr($0,0,RSTART) | 613 if (RSTART>1) print substr($0,0,RSTART) |
| 500 $0=substr($0,RSTART+RLENGTH) | 614 $0=substr($0,RSTART+RLENGTH) |
| 501 supress=1 | 615 suppress=1 |
| 502 } | 616 } |
| 503 else { | 617 else { |
| 504 if ($0) print $0 | 618 if ($0) print $0 |
| 505 break | 619 break |
| 506 } | 620 } |
| 507 } | 621 } |
| 508 while(1) | 622 while(1) |
| 509 } | 623 } |
| 510 ' | awk ' | 624 ' | awk ' |
| 511 # List MIME types listed in <mime-type> tags | 625 # List MIME types listed in <mime-type> tags |
| 512 BEGIN { | 626 BEGIN { |
| 513 RS="<" | 627 RS="<" |
| 514 } | 628 } |
| 515 /^mime-info/, /^\/mime-info/ { | 629 /^mime-info/, /^\/mime-info/ { |
| 516 if (match($0,/^mime-type/)) { | 630 if (match($0,/^mime-type/)) { |
| 517 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { | 631 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { |
| 518 print substr($0,RSTART+6,RLENGTH-6) | 632 print substr($0,RSTART+6,RLENGTH-6) |
| 519 } | 633 } |
| 520 } | 634 } |
| 521 }'` | 635 }'` |
| 522 fi | 636 fi |
| 523 | 637 |
| 524 DEBUG 1 "$action mimetype in $xdg_dir" | 638 DEBUG 1 "$action mimetype in $xdg_dir" |
| 525 | 639 |
| 526 case $action in | 640 case $action in |
| 527 install) | 641 install) |
| 528 save_umask=`umask` | 642 save_umask=`umask` |
| 529 umask $my_umask | 643 umask $my_umask |
| 530 | 644 |
| 531 for x in $xdg_dir ; do | 645 for x in $xdg_dir ; do |
| 532 mkdir -p $x | 646 mkdir -p $x |
| 533 eval 'cp $filename $x/$basefile'$xdg_redirect_output | 647 eval 'cp $filename $x/$basefile'$xdg_redirect_output |
| 534 done | 648 done |
| 535 | 649 |
| 536 if [ -n "$mimetypes" ] ; then | 650 if [ -n "$mimetypes" ] ; then |
| 537 # No quotes around $mimetypes | 651 # No quotes around $mimetypes |
| 538 for x in $mimetypes ; do | 652 for x in $mimetypes ; do |
| 539 DEBUG 1 "Installing $kde_dir/$x.desktop (KDE 3.x support)" | 653 DEBUG 1 "Installing $kde_dir/$x.desktop (KDE 3.x support)" |
| 540 mkdir -p `dirname $kde_dir/$x.desktop` | 654 mkdir -p `dirname $kde_dir/$x.desktop` |
| 541 awk < "$filename" ' | 655 awk < "$filename" ' |
| 542 # Strip XML comments | 656 # Strip XML comments |
| 543 BEGIN { | 657 BEGIN { |
| 544 supress=0 | 658 suppress=0 |
| 545 } | 659 } |
| 546 { | 660 { |
| 547 do | 661 do |
| 548 if (supress) { | 662 if (suppress) { |
| 549 if (match($0,/-->/)) { | 663 if (match($0,/-->/)) { |
| 550 $0=substr($0,RSTART+RLENGTH) | 664 $0=substr($0,RSTART+RLENGTH) |
| 551 supress=0 | 665 suppress=0 |
| 552 } | 666 } |
| 553 else { | 667 else { |
| 554 break | 668 break |
| 555 } | 669 } |
| 556 } | 670 } |
| 557 else { | 671 else { |
| 558 if (match($0,/<!--/)) { | 672 if (match($0,/<!--/)) { |
| 559 if (RSTART>1) print substr($0,0,RSTART) | 673 if (RSTART>1) print substr($0,0,RSTART) |
| 560 $0=substr($0,RSTART+RLENGTH) | 674 $0=substr($0,RSTART+RLENGTH) |
| 561 supress=1 | 675 suppress=1 |
| 562 } | 676 } |
| 563 else { | 677 else { |
| 564 if ($0) print $0 | 678 if ($0) print $0 |
| 565 break | 679 break |
| 566 } | 680 } |
| 567 } | 681 } |
| 568 while(1) | 682 while(1) |
| 569 } | 683 } |
| 570 ' | awk > $kde_dir/$x.desktop ' | 684 ' | awk > $kde_dir/$x.desktop ' |
| 571 # Extract mimetype $x from the XML file $filename | 685 # Extract mimetype $x from the XML file $filename |
| 572 # Note that bash requires us to escape a single quote as '"'"' | 686 # Note that bash requires us to escape a single quote as '"'"' |
| 573 BEGIN { | 687 BEGIN { |
| 574 the_type=ARGV[1] | 688 the_type=ARGV[1] |
| 575 the_source=ARGV[2] | 689 the_source=ARGV[2] |
| 576 ARGC=1 | 690 ARGC=1 |
| 577 RS="<" | 691 RS="<" |
| 578 found=0 | 692 found=0 |
| 579 glob_patterns="" | 693 glob_patterns="" |
| 580 } | 694 } |
| 581 /^mime-info/, /^\/mime-info/ { | 695 /^mime-info/, /^\/mime-info/ { |
| 582 if (match($0,/^mime-type/)) { | 696 if (match($0,/^mime-type/)) { |
| 583 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { | 697 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { |
| 584 if (substr($0,RSTART+6,RLENGTH-6) == the_type) { | 698 if (substr($0,RSTART+6,RLENGTH-6) == the_type) { |
| 585 found=1 | 699 found=1 |
| 586 print "[Desktop Entry]" | 700 print "[Desktop Entry]" |
| 587 print "# Installed by xdg-mime from " the_source | 701 print "# Installed by xdg-mime from " the_source |
| 588 print "Type=MimeType" | 702 print "Type=MimeType" |
| 589 print "MimeType=" the_type | 703 print "MimeType=" the_type |
| 590 the_icon=the_type | 704 the_icon=the_type |
| 591 sub("/", "-", the_icon) | 705 sub("/", "-", the_icon) |
| 592 print "Icon=" the_icon | 706 print "Icon=" the_icon |
| 593 } | 707 } |
| 594 } | 708 } |
| 595 } | 709 } |
| 596 else if (found) { | 710 else if (found) { |
| 597 if (match($0,/^\/mime-type/)) { | 711 if (match($0,/^\/mime-type/)) { |
| 598 if (glob_patterns) | 712 if (glob_patterns) |
| 599 print "Patterns=" glob_patterns | 713 print "Patterns=" glob_patterns |
| 600 exit 0 | 714 exit 0 |
| 601 } | 715 } |
| 602 | 716 |
| 603 if (match($0,/^sub-class-of/)) { | 717 if (match($0,/^sub-class-of/)) { |
| 604 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { | 718 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { |
| 605 print "X-KDE-IsAlso=" substr($0,RSTART+6,RLENGTH-6) | 719 print "X-KDE-IsAlso=" substr($0,RSTART+6,RLENGTH-6) |
| 606 } | 720 } |
| 607 else { | 721 else { |
| 608 print "Error: '"'"'type'"'"' argument missing in " RS $0 | 722 print "Error: '"'"'type'"'"' argument missing in " RS $0 |
| 609 exit 1 | 723 exit 1 |
| 610 } | 724 } |
| 611 } | 725 } |
| 612 if (match($0,/^glob/)) { | 726 if (match($0,/^glob/)) { |
| 613 if (match($0,/pattern="[^"]*/) || match($0,/pattern='"'"'[^'"'"']*/)) {
| 727 if (match($0,/pattern="[^"]*/) || match($0,/pattern='"'"'[^'"'"']*/)) { |
| 614 glob_patterns = glob_patterns substr($0,RSTART+9,RLENGTH-9) ";" | 728 glob_patterns = glob_patterns substr($0,RSTART+9,RLENGTH-9) ";" |
| 615 } | 729 } |
| 616 else { | 730 else { |
| 617 print "Error: '"'"'pattern'"'"' argument missing in " RS $0 | 731 print "Error: '"'"'pattern'"'"' argument missing in " RS $0 |
| 618 exit 1 | 732 exit 1 |
| 619 } | 733 } |
| 620 } | 734 } |
| 621 if (match($0,/^comment/)) { | 735 if (match($0,/^comment/)) { |
| 622 if (match($0,/xml:lang="[^"]*/) || match($0,/xml:lang='"'"'[^'"'"']*/)) {
| 736 if (match($0,/xml:lang="[^"]*/) || match($0,/xml:lang='"'"'[^'"'"']*/)) { |
| 623 lang=substr($0,RSTART+10,RLENGTH-10) | 737 lang=substr($0,RSTART+10,RLENGTH-10) |
| 624 } | 738 } |
| 625 else { | 739 else { |
| 626 lang="" | 740 lang="" |
| 627 } | 741 } |
| 628 if (match($0,/>/)) { | 742 if (match($0,/>/)) { |
| 629 comment=substr($0,RSTART+1) | 743 comment=substr($0,RSTART+1) |
| 630 sub("<", "<", comment) | 744 sub("<", "<", comment) |
| 631 sub(">", ">", comment) | 745 sub(">", ">", comment) |
| 632 sub("&", "\\&", comment) | 746 sub("&", "\\&", comment) |
| 633 if (lang) | 747 if (lang) |
| 634 print "Comment[" lang "]=" comment | 748 print "Comment[" lang "]=" comment |
| 635 else | 749 else |
| 636 print "Comment=" comment | 750 print "Comment=" comment |
| 637 } | 751 } |
| 638 } | 752 } |
| 639 } | 753 } |
| 640 } | 754 } |
| 641 END { | 755 END { |
| 642 if (!found) { | 756 if (!found) { |
| 643 print "Error: Mimetype '"'"'" the_type "'"'"' not found" | 757 print "Error: Mimetype '"'"'" the_type "'"'"' not found" |
| 644 exit 1 | 758 exit 1 |
| 645 } | 759 } |
| 646 } | 760 } |
| 647 ' $x $basefile | 761 ' $x $basefile |
| 648 if [ "$?" = "1" ] ; then | 762 if [ "$?" = "1" ] ; then |
| 649 grep -A 10 "^Error:" $kde_dir/$x.desktop >&2 | 763 grep -A 10 "^Error:" $kde_dir/$x.desktop >&2 |
| 650 rm $kde_dir/$x.desktop | 764 rm $kde_dir/$x.desktop |
| 651 exit 1 | 765 exit 1 |
| 652 fi | 766 fi |
| 653 done | 767 done |
| 654 fi | 768 fi |
| 655 | 769 |
| 656 umask $save_umask | 770 umask $save_umask |
| 657 ;; | 771 ;; |
| 658 | 772 |
| 659 uninstall) | 773 uninstall) |
| 660 for x in $xdg_dir ; do | 774 for x in $xdg_dir ; do |
| 661 rm -f $x/$basefile | 775 rm -f $x/$basefile |
| 662 done | 776 done |
| 663 | 777 |
| 664 # No quotes around $mimetypes | 778 # No quotes around $mimetypes |
| 665 for x in $mimetypes ; do | 779 for x in $mimetypes ; do |
| 666 if grep '^# Installed by xdg-mime' $kde_dir/$x.desktop >/dev/null 2>
&1; then | 780 if grep '^# Installed by xdg-mime' $kde_dir/$x.desktop >/dev/null 2>
&1; then |
| 667 DEBUG 1 "Removing $kde_dir/$x.desktop (KDE 3.x support)" | 781 DEBUG 1 "Removing $kde_dir/$x.desktop (KDE 3.x support)" |
| 668 rm -f $kde_dir/$x.desktop | 782 rm -f $kde_dir/$x.desktop |
| 669 fi | 783 fi |
| 670 done | 784 done |
| 671 ;; | 785 ;; |
| 672 esac | 786 esac |
| 673 | 787 |
| 674 update_mime_database $xdg_base_dir | 788 update_mime_database $xdg_base_dir |
| 675 | 789 |
| 676 exit_success | 790 exit_success |
| 677 | 791 |
| OLD | NEW |