Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: third_party/xdg-utils/scripts/xdg-mime

Issue 3273010: Update our copy of xdg-utils to 2010-08-30, and include a patched xdg-mime. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 exit_failure_file_permission_read() 315 exit_failure_file_permission_read()
316 { 316 {
317 if [ $# -gt 0 ]; then 317 if [ $# -gt 0 ]; then
318 echo "xdg-mime: $@" >&2 318 echo "xdg-mime: $@" >&2
319 fi 319 fi
320 320
321 exit 5 321 exit 5
322 } 322 }
323 323
324 #------------------------------------------------------------ 324 #------------------------------------------------------------
325 # Exit script on insufficient permission to read a specified file 325 # Exit script on insufficient permission to write a specified file
326 326
327 exit_failure_file_permission_write() 327 exit_failure_file_permission_write()
328 { 328 {
329 if [ $# -gt 0 ]; then 329 if [ $# -gt 0 ]; then
330 echo "xdg-mime: $@" >&2 330 echo "xdg-mime: $@" >&2
331 fi 331 fi
332 332
333 exit 6 333 exit 6
334 } 334 }
335 335
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info. " 392 echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info. "
393 exit_success 393 exit_success
394 ;; 394 ;;
395 395
396 --manual) 396 --manual)
397 manualpage 397 manualpage
398 exit_success 398 exit_success
399 ;; 399 ;;
400 400
401 --version) 401 --version)
402 echo "xdg-mime 1.0.1" 402 echo "xdg-mime 1.0.2"
403 exit_success 403 exit_success
404 ;; 404 ;;
405 esac 405 esac
406 done 406 done
407 } 407 }
408 408
409 check_common_commands "$@" 409 check_common_commands "$@"
410 410
411 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; 411 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
412 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then 412 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
413 # Be silent 413 # Be silent
414 xdg_redirect_output=" > /dev/null 2> /dev/null" 414 xdg_redirect_output=" > /dev/null 2> /dev/null"
415 else 415 else
416 # All output to stderr 416 # All output to stderr
417 xdg_redirect_output=" >&2" 417 xdg_redirect_output=" >&2"
418 fi 418 fi
419 419
420 #-------------------------------------- 420 #--------------------------------------
421 # Checks for known desktop environments 421 # Checks for known desktop environments
422 # set variable DE to the desktop environments name, lowercase 422 # set variable DE to the desktop environments name, lowercase
423 423
424 detectDE() 424 detectDE()
425 { 425 {
426 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; 426 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
427 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; 427 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
428 elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce; 428 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul l 2>&1` ; then DE=gnome;
429 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul l 2>&1; then DE=xfce;
429 fi 430 fi
430 } 431 }
431 432
432 #---------------------------------------------------------------------------- 433 #----------------------------------------------------------------------------
433 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 434 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
434 # It also always returns 1 in KDE 3.4 and earlier 435 # It also always returns 1 in KDE 3.4 and earlier
435 # Simply return 0 in such case 436 # Simply return 0 in such case
436 437
437 kfmclient_fix_exit_code() 438 kfmclient_fix_exit_code()
438 { 439 {
439 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` 440 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE`
440 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` 441 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'`
441 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` 442 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'`
442 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` 443 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
443 test "$major" -gt 3 && return $1 444 test "$major" -gt 3 && return $1
444 test "$minor" -gt 5 && return $1 445 test "$minor" -gt 5 && return $1
445 test "$release" -gt 4 && return $1 446 test "$release" -gt 4 && return $1
446 return 0 447 return 0
447 } 448 }
448 449
449 update_mime_database() 450 update_mime_database()
450 { 451 {
451 if [ x"$mode" = x"user" -a -n "$DISPLAY" ] ; then 452 if [ x"$mode" = x"user" -a -n "$DISPLAY" ] ; then
452 detectDE 453 detectDE
453 if [ x"$DE" = x"kde" ] ; then 454 if [ x"$DE" = x"kde" ] ; then
454 DEBUG 1 "Running kbuildsycoca" 455 DEBUG 1 "Running kbuildsycoca"
455 eval 'kbuildsycoca'$xdg_redirect_output 456 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
457 eval 'kbuildsycoca4'$xdg_redirect_output
458 else
459 eval 'kbuildsycoca'$xdg_redirect_output
460 fi
456 fi 461 fi
457 fi 462 fi
458 for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do 463 for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do
459 if [ -x $x/update-mime-database ] ; then 464 if [ -x $x/update-mime-database ] ; then
460 DEBUG 1 "Running $x/update-mime-database $1" 465 DEBUG 1 "Running $x/update-mime-database $1"
461 eval '$x/update-mime-database $1'$xdg_redirect_output 466 eval '$x/update-mime-database $1'$xdg_redirect_output
462 return 467 return
463 fi 468 fi
464 done 469 done
465 } 470 }
466 471
467 info_kde() 472 info_kde()
468 { 473 {
469 if which "kmimetypefinder" > /dev/null 2>/dev/null; then 474 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
470 DEBUG 1 "Running kmimetypefinder \"$1\"" 475 DEBUG 1 "Running kmimetypefinder \"$1\""
471 kmimetypefinder "$1" 2>/dev/null | head -n 1 476 KMIMETYPEFINDER=`which kmimetypefinder 2>/dev/null`
477 $KMIMETYPEFINDER "$1" 2>/dev/null | head -n 1
472 else 478 else
473 DEBUG 1 "Running kfile \"$1\"" 479 DEBUG 1 "Running kfile \"$1\""
474 kfile "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1 480 KFILE=`which kfile 2>/dev/null`
481 $KFILE "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1
475 fi 482 fi
476 483
477 exit_success 484 if [ $? -eq 0 ]; then
485 exit_success
486 else
487 exit_failure_operation_failed
488 fi
478 } 489 }
479 490
480 info_gnome() 491 info_gnome()
481 { 492 {
482 file=`readlink -f "$1"` # Normalize path 493 file=`readlink -f "$1"` # Normalize path
483 DEBUG 1 "Running gnomevfs-info \"$file\""
484 gnomevfs-info "$file" 2> /dev/null | grep MIME | cut -d ":" -f 2 | sed s/"^ "//
485 494
486 exit_success 495 if gvfs-info --help 2>/dev/null 1>&2; then
496 DEBUG 1 "Running gvfs-info \"$file\""
497 gvfs-info "$file" 2> /dev/null | grep standard::content-type | cut -d' ' -f4
498 else
499 DEBUG 1 "Running gnomevfs-info \"$file\""
500 gnomevfs-info --slow-mime "$file" 2> /dev/null | grep "^MIME" | cut -d ": " -f 2 | sed s/"^ "//
501 fi
502
503 if [ $? -eq 0 ]; then
504 exit_success
505 else
506 exit_failure_operation_failed
507 fi
487 } 508 }
488 509
489 info_generic() 510 info_generic()
490 { 511 {
491 DEBUG 1 "Running /usr/bin/file -i \"$1\"" 512 DEBUG 1 "Running file -i \"$1\""
492 /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "// 513 /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "//
493 514
494 exit_success 515 if [ $? -eq 0 ]; then
516 exit_success
517 else
518 exit_failure_operation_failed
519 fi
495 } 520 }
496 521
497 make_default_kde() 522 make_default_kde()
498 { 523 {
499 # $1 is vendor-name.desktop 524 # $1 is vendor-name.desktop
500 # $2 is mime/type 525 # $2 is mime/type
501 # Add to $KDE_HOME/share/config/profilerc: 526 #
527 # On KDE 3, add to $KDE_CONFIG_PATH/profilerc:
502 # [$2 - 1] 528 # [$2 - 1]
503 # Application=$1 529 # Application=$1
504 # 530 #
505 # Remove all [$2 - *] sections, or even better, 531 # Remove all [$2 - *] sections, or even better,
506 # renumber [$2 - *] sections and remove duplicate 532 # renumber [$2 - *] sections and remove duplicate
507 533 #
508 default_file="$HOME/.kde/share/config/profilerc" 534 # On KDE 4, add $2=$1 to $XDG_DATA_APPS/mimeapps.list
509 DEBUG 2 "make_default_kde $1 $2" 535 #
536 # Example file:
537 #
538 # [Added Associations]
539 # text/plain=kde4-kate.desktop;kde4-kwrite.desktop;
540 #
541 # [Removed Associations]
542 # text/plain=gnome-gedit.desktop;gnu-emacs.desktop;
543 vendor="$1"
544 mimetype="$2"
545 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
546 default_dir=`kde4-config --path xdgdata-apps 2> /dev/null | cut -d ':' - f 1`
547 default_file="$default_dir/mimeapps.list"
548 else
549 default_dir=`kde-config --path config 2> /dev/null | cut -d ':' -f 1`
550 default_file="$default_dir/profilerc"
551 fi
552 if [ -z "$default_dir" ]; then
553 DEBUG 2 "make_default_kde: No kde runtime detected"
554 return
555 fi
556 DEBUG 2 "make_default_kde $vendor $mimetype"
510 DEBUG 1 "Updating $default_file" 557 DEBUG 1 "Updating $default_file"
511 mkdir -p "$HOME/.kde/share/config" 558 mkdir -p "$default_dir"
512 [ -f $default_file ] || touch $default_file 559 [ -f $default_file ] || touch $default_file
513 awk -v application="$1" -v mimetype="$2" ' 560 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
561 [ -f $default_file ] || touch $default_file
562 awk -v application="$vendor" -v mimetype="$mimetype" '
514 BEGIN { 563 BEGIN {
515 header_start="[" mimetype " - " 564 prefix=mimetype "="
516 supress=0 565 associations=0
566 found=0
567 blanks=0
517 } 568 }
518 { 569 {
519 if (index($0, header_start) == 1 ) 570 suppress=0
520 supress=1 571 if (index($0, "[Added Associations]") == 1) {
521 else 572 associations=1
522 if (/^\[/) { supress=0 } 573 } else if (index($0, "[") == 1) {
523 574 if (associations && !found) {
524 if (!supress) { 575 print prefix application
576 found=1
577 }
578 associations=0
579 } else if ($0 == "") {
580 blanks++
581 suppress=1
582 } else if (associations && index($0, prefix) == 1) {
583 value=substr($0, length(prefix) + 1, length)
584 split(value, apps, ";")
585 value=application ";"
586 count=0
587 for (i in apps) {
588 count++
589 }
590 for (i=0; i < count; i++) {
591 if (apps[i] != application && apps[i] != "") {
592 value=value apps[i] ";"
593 }
594 }
595 $0=prefix value
596 found=1
597 }
598 if (!suppress) {
599 while (blanks > 0) {
600 print ""
601 blanks--
602 }
525 print $0 603 print $0
526 } 604 }
527 } 605 }
528 END { 606 END {
529 print "" 607 if (!found) {
608 if (!associations) {
609 print "[Added Associations]"
610 }
611 print prefix application
612 }
613 while (blanks > 0) {
614 print ""
615 blanks--
616 }
617 }
618 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file
619 eval 'kbuildsycoca4'$xdg_redirect_output
620 else
621 awk -v application="$vendor" -v mimetype="$mimetype" '
622 BEGIN {
623 header_start="[" mimetype " - "
624 suppress=0
625 }
626 {
627 if (index($0, header_start) == 1 )
628 suppress=1
629 else
630 if (/^\[/) { suppress=0 }
631
632 if (!suppress) {
633 print $0
634 }
635 }
636 END {
637 print ""
530 print "[" mimetype " - 1]" 638 print "[" mimetype " - 1]"
531 print "Application=" application 639 print "Application=" application
532 print "AllowAsDefault=true" 640 print "AllowAsDefault=true"
533 print "GenericServiceType=Application" 641 print "GenericServiceType=Application"
534 print "Preference=1" 642 print "Preference=1"
535 print "ServiceType=" mimetype 643 print "ServiceType=" mimetype
536 } 644 }
537 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file 645 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file
646 fi
538 } 647 }
539 648
540 make_default_generic() 649 make_default_generic()
541 { 650 {
542 # $1 is vendor-name.desktop 651 # $1 is vendor-name.desktop
543 # $2 is mime/type 652 # $2 is mime/type
544 # Add $2=$1 to XDG_DATA_HOME/applications/defaults.list 653 # Add $2=$1 to XDG_DATA_HOME/applications/defaults.list
545 xdg_user_dir="$XDG_DATA_HOME" 654 xdg_user_dir="$XDG_DATA_HOME"
546 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" 655 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
547 default_file="$xdg_user_dir/applications/defaults.list" 656 default_file="$xdg_user_dir/applications/defaults.list"
548 DEBUG 2 "make_default_generic $1 $2" 657 DEBUG 2 "make_default_generic $1 $2"
549 DEBUG 1 "Updating $default_file" 658 DEBUG 1 "Updating $default_file"
550 grep -v "$2=" $default_file > ${default_file}.new 2> /dev/null 659 grep -v "$2=" $default_file > ${default_file}.new 2> /dev/null
551 if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then 660 if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then
552 echo "[Default Applications]" >> ${default_file}.new 661 echo "[Default Applications]" >> ${default_file}.new
553 fi 662 fi
(...skipping 17 matching lines...) Expand all
571 echo $trader_result 680 echo $trader_result
572 exit_success 681 exit_success
573 fi 682 fi
574 done 683 done
575 exit_success 684 exit_success
576 } 685 }
577 686
578 defapp_kde() 687 defapp_kde()
579 { 688 {
580 MIME="$1" 689 MIME="$1"
581 ktradertest=`which ktradertest 2> /dev/null` 690 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
582 if [ -n "$ktradertest" ] ; then 691 KTRADER=`which ktraderclient 2> /dev/null`
583 DEBUG 1 "Running ktradertest \"$MIME\" Application" 692 MIMETYPE="--mimetype"
584 trader_result=`ktradertest "$MIME" Application 2>/dev/null | grep Deskto pEntryPath \ 693 SERVICETYPE="--servicetype"
585 | head -n 1 | cut -d ':' -f 2 | cut -d \' -f 2` 694 else
695 KTRADER=`which ktradertest 2> /dev/null`
696 fi
697 if [ -n "$KTRADER" ] ; then
698 DEBUG 1 "Running KDE trader query \"$MIME\" mimetype and \"Application\" servicetype"
699 trader_result=`$KTRADER $MIMETYPE "$MIME" $SERVICETYPE Application 2>/de v/null \
700 | grep DesktopEntryPath | head -n 1 | cut -d ':' -f 2 | cut -d \' -f 2`
586 if [ -n "$trader_result" ] ; then 701 if [ -n "$trader_result" ] ; then
587 basename "$trader_result" 702 basename "$trader_result"
588 exit_success 703 exit_success
589 else 704 else
590 exit_failure_operation_failed 705 exit_failure_operation_failed
591 fi 706 fi
592 else 707 else
593 defapp_generic "$1" 708 defapp_generic "$1"
594 fi 709 fi
595 } 710 }
(...skipping 10 matching lines...) Expand all
606 action=install 721 action=install
607 ;; 722 ;;
608 723
609 uninstall) 724 uninstall)
610 action=uninstall 725 action=uninstall
611 ;; 726 ;;
612 727
613 query) 728 query)
614 shift 729 shift
615 730
616 if [ -z "$1" ] ; then 731 if [ -z "$1" ] ; then
617 exit_failure_syntax "query type argument missing" 732 exit_failure_syntax "query type argument missing"
618 fi 733 fi
619 734
620 case $1 in 735 case $1 in
621 filetype) 736 filetype)
622 action=info 737 action=info
623 738
624 filename="$2" 739 filename="$2"
625 if [ -z "$filename" ] ; then 740 if [ -z "$filename" ] ; then
626 exit_failure_syntax "FILE argument missing" 741 exit_failure_syntax "FILE argument missing"
627 fi 742 fi
628 case $filename in 743 case $filename in
629 -*) 744 -*)
630 exit_failure_syntax "unexpected option '$filename'" 745 exit_failure_syntax "unexpected option '$filename'"
631 ;; 746 ;;
632 esac 747 esac
633 check_input_file "$filename" 748 check_input_file "$filename"
634 ;; 749 ;;
635 750
636 default) 751 default)
637 action=defapp 752 action=defapp
638 mimetype="$2" 753 mimetype="$2"
639 if [ -z "$mimetype" ] ; then 754 if [ -z "$mimetype" ] ; then
640 exit_failure_syntax "mimetype argument missing" 755 exit_failure_syntax "mimetype argument missing"
641 fi 756 fi
642 case $mimetype in 757 case $mimetype in
643 -*) 758 -*)
644 exit_failure_syntax "unexpected option '$mimetype'" 759 exit_failure_syntax "unexpected option '$mimetype'"
645 ;; 760 ;;
646 761
647 */*) 762 */*)
648 # Ok 763 # Ok
649 ;; 764 ;;
650 765
651 *) 766 *)
652 exit_failure_syntax "mimetype '$mimetype' is not in the form 'minor/ major'" 767 exit_failure_syntax "mimetype '$mimetype' is not in the form 'minor/ major'"
653 ;; 768 ;;
654 esac 769 esac
655 ;; 770 ;;
656 771
657 *) 772 *)
658 exit_failure_syntax "unknown query type '$1'" 773 exit_failure_syntax "unknown query type '$1'"
659 ;; 774 ;;
660 esac 775 esac
661 ;; 776 ;;
662 777
663 default) 778 default)
664 action=makedefault 779 action=makedefault
665 shift 780 shift
666 781
667 if [ -z "$1" ] ; then 782 if [ -z "$1" ] ; then
668 exit_failure_syntax "application argument missing" 783 exit_failure_syntax "application argument missing"
669 fi 784 fi
670 case $1 in 785 case $1 in
671 -*) 786 -*)
672 exit_failure_syntax "unexpected option '$1'" 787 exit_failure_syntax "unexpected option '$1'"
673 ;; 788 ;;
674 789
675 *.desktop) 790 *.desktop)
676 filename="$1" 791 filename="$1"
677 ;; 792 ;;
678 793
679 *) 794 *)
680 exit_failure_syntax "malformed argument '$1', expected *.desktop" 795 exit_failure_syntax "malformed argument '$1', expected *.desktop"
681 ;; 796 ;;
682 esac 797 esac
683 ;; 798 ;;
684 799
685 *) 800 *)
686 exit_failure_syntax "unknown command '$1'" 801 exit_failure_syntax "unknown command '$1'"
687 ;; 802 ;;
688 esac 803 esac
689 804
690 shift 805 shift
691 806
692 807
693 if [ "$action" = "makedefault" ]; then 808 if [ "$action" = "makedefault" ]; then
694 if [ -z "$1" ] ; then 809 if [ -z "$1" ] ; then
695 exit_failure_syntax "mimetype argument missing" 810 exit_failure_syntax "mimetype argument missing"
696 fi 811 fi
697 812
698 while [ $# -gt 0 ] ; do 813 while [ $# -gt 0 ] ; do
699 case $1 in 814 case $1 in
700 -*) 815 -*)
701 exit_failure_syntax "unexpected option '$1'" 816 exit_failure_syntax "unexpected option '$1'"
702 ;; 817 ;;
703 esac 818 esac
704 mimetype="$1" 819 mimetype="$1"
705 shift 820 shift
706 821
707 make_default_kde "$filename" "$mimetype" 822 make_default_kde "$filename" "$mimetype"
708 make_default_generic "$filename" "$mimetype" 823 make_default_generic "$filename" "$mimetype"
709 done 824 done
710 exit_success 825 exit_success
711 fi 826 fi
712 827
713 if [ "$action" = "info" ]; then 828 if [ "$action" = "info" ]; then
714 detectDE 829 detectDE
715 830
716 if [ x"$DE" = x"" ]; then 831 if [ x"$DE" = x"" ]; then
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 exit_failure_syntax "mode argument missing for --mode" 876 exit_failure_syntax "mode argument missing for --mode"
762 fi 877 fi
763 case "$1" in 878 case "$1" in
764 user) 879 user)
765 mode="user" 880 mode="user"
766 ;; 881 ;;
767 882
768 system) 883 system)
769 mode="system" 884 mode="system"
770 ;; 885 ;;
771 886
772 *) 887 *)
773 exit_failure_syntax "unknown mode '$1'" 888 exit_failure_syntax "unknown mode '$1'"
774 ;; 889 ;;
775 esac 890 esac
776 shift 891 shift
777 ;; 892 ;;
778 893
779 --novendor) 894 --novendor)
780 vendor=false 895 vendor=false
781 ;; 896 ;;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 basefile=`basename "$filename"` 1007 basefile=`basename "$filename"`
893 #[ -z $vendor ] || basefile="$vendor-$basefile" 1008 #[ -z $vendor ] || basefile="$vendor-$basefile"
894 1009
895 mimetypes= 1010 mimetypes=
896 if [ -n "$kde_dir" ] ; then 1011 if [ -n "$kde_dir" ] ; then
897 DEBUG 2 "KDE3 mimelnk directory found, extracting mimetypes from XML file" 1012 DEBUG 2 "KDE3 mimelnk directory found, extracting mimetypes from XML file"
898 1013
899 mimetypes=`awk < "$filename" ' 1014 mimetypes=`awk < "$filename" '
900 # Strip XML comments 1015 # Strip XML comments
901 BEGIN { 1016 BEGIN {
902 supress=0 1017 suppress=0
903 } 1018 }
904 { 1019 {
905 do 1020 do
906 if (supress) { 1021 if (suppress) {
907 if (match($0,/-->/)) { 1022 if (match($0,/-->/)) {
908 $0=substr($0,RSTART+RLENGTH) 1023 $0=substr($0,RSTART+RLENGTH)
909 supress=0 1024 suppress=0
910 } 1025 }
911 else { 1026 else {
912 break 1027 break
913 } 1028 }
914 } 1029 }
915 else { 1030 else {
916 if (match($0,/<!--/)) { 1031 if (match($0,/<!--/)) {
917 if (RSTART>1) print substr($0,0,RSTART) 1032 if (RSTART>1) print substr($0,0,RSTART)
918 $0=substr($0,RSTART+RLENGTH) 1033 $0=substr($0,RSTART+RLENGTH)
919 supress=1 1034 suppress=1
920 } 1035 }
921 else { 1036 else {
922 if ($0) print $0 1037 if ($0) print $0
923 break 1038 break
924 } 1039 }
925 } 1040 }
926 while(1) 1041 while(1)
927 } 1042 }
928 ' | awk ' 1043 ' | awk '
929 # List MIME types listed in <mime-type> tags 1044 # List MIME types listed in <mime-type> tags
930 BEGIN { 1045 BEGIN {
931 RS="<" 1046 RS="<"
932 } 1047 }
933 /^mime-info/, /^\/mime-info/ { 1048 /^mime-info/, /^\/mime-info/ {
934 if (match($0,/^mime-type/)) { 1049 if (match($0,/^mime-type/)) {
935 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { 1050 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) {
936 print substr($0,RSTART+6,RLENGTH-6) 1051 print substr($0,RSTART+6,RLENGTH-6)
937 } 1052 }
938 } 1053 }
939 }'` 1054 }'`
940 fi 1055 fi
941 1056
942 DEBUG 1 "$action mimetype in $xdg_dir" 1057 DEBUG 1 "$action mimetype in $xdg_dir"
943 1058
944 case $action in 1059 case $action in
945 install) 1060 install)
946 save_umask=`umask` 1061 save_umask=`umask`
947 umask $my_umask 1062 umask $my_umask
948 1063
949 for x in $xdg_dir ; do 1064 for x in $xdg_dir ; do
950 mkdir -p $x 1065 mkdir -p $x
951 eval 'cp $filename $x/$basefile'$xdg_redirect_output 1066 eval 'cp $filename $x/$basefile'$xdg_redirect_output
952 done 1067 done
953 1068
954 if [ -n "$mimetypes" ] ; then 1069 if [ -n "$mimetypes" ] ; then
955 # No quotes around $mimetypes 1070 # No quotes around $mimetypes
956 for x in $mimetypes ; do 1071 for x in $mimetypes ; do
957 DEBUG 1 "Installing $kde_dir/$x.desktop (KDE 3.x support)" 1072 DEBUG 1 "Installing $kde_dir/$x.desktop (KDE 3.x support)"
958 mkdir -p `dirname $kde_dir/$x.desktop` 1073 mkdir -p `dirname $kde_dir/$x.desktop`
959 awk < "$filename" ' 1074 awk < "$filename" '
960 # Strip XML comments 1075 # Strip XML comments
961 BEGIN { 1076 BEGIN {
962 supress=0 1077 suppress=0
963 } 1078 }
964 { 1079 {
965 do 1080 do
966 if (supress) { 1081 if (suppress) {
967 if (match($0,/-->/)) { 1082 if (match($0,/-->/)) {
968 $0=substr($0,RSTART+RLENGTH) 1083 $0=substr($0,RSTART+RLENGTH)
969 supress=0 1084 suppress=0
970 } 1085 }
971 else { 1086 else {
972 break 1087 break
973 } 1088 }
974 } 1089 }
975 else { 1090 else {
976 if (match($0,/<!--/)) { 1091 if (match($0,/<!--/)) {
977 if (RSTART>1) print substr($0,0,RSTART) 1092 if (RSTART>1) print substr($0,0,RSTART)
978 $0=substr($0,RSTART+RLENGTH) 1093 $0=substr($0,RSTART+RLENGTH)
979 supress=1 1094 suppress=1
980 } 1095 }
981 else { 1096 else {
982 if ($0) print $0 1097 if ($0) print $0
983 break 1098 break
984 } 1099 }
985 } 1100 }
986 while(1) 1101 while(1)
987 } 1102 }
988 ' | awk > $kde_dir/$x.desktop ' 1103 ' | awk > $kde_dir/$x.desktop '
989 # Extract mimetype $x from the XML file $filename 1104 # Extract mimetype $x from the XML file $filename
990 # Note that bash requires us to escape a single quote as '"'"' 1105 # Note that bash requires us to escape a single quote as '"'"'
991 BEGIN { 1106 BEGIN {
992 the_type=ARGV[1] 1107 the_type=ARGV[1]
993 the_source=ARGV[2] 1108 the_source=ARGV[2]
994 ARGC=1 1109 ARGC=1
995 RS="<" 1110 RS="<"
996 found=0 1111 found=0
997 glob_patterns="" 1112 glob_patterns=""
998 } 1113 }
999 /^mime-info/, /^\/mime-info/ { 1114 /^mime-info/, /^\/mime-info/ {
1000 if (match($0,/^mime-type/)) { 1115 if (match($0,/^mime-type/)) {
1001 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { 1116 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) {
1002 if (substr($0,RSTART+6,RLENGTH-6) == the_type) { 1117 if (substr($0,RSTART+6,RLENGTH-6) == the_type) {
1003 found=1 1118 found=1
1004 print "[Desktop Entry]" 1119 print "[Desktop Entry]"
1005 print "# Installed by xdg-mime from " the_source 1120 print "# Installed by xdg-mime from " the_source
1006 print "Type=MimeType" 1121 print "Type=MimeType"
1007 print "MimeType=" the_type 1122 print "MimeType=" the_type
1008 the_icon=the_type 1123 the_icon=the_type
1009 sub("/", "-", the_icon) 1124 sub("/", "-", the_icon)
1010 print "Icon=" the_icon 1125 print "Icon=" the_icon
1011 } 1126 }
1012 } 1127 }
1013 } 1128 }
1014 else if (found) { 1129 else if (found) {
1015 if (match($0,/^\/mime-type/)) { 1130 if (match($0,/^\/mime-type/)) {
1016 if (glob_patterns) 1131 if (glob_patterns)
1017 print "Patterns=" glob_patterns 1132 print "Patterns=" glob_patterns
1018 exit 0 1133 exit 0
1019 } 1134 }
1020 1135
1021 if (match($0,/^sub-class-of/)) { 1136 if (match($0,/^sub-class-of/)) {
1022 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) { 1137 if (match($0,/type="[^"]*/) || match($0,/type='"'"'[^'"'"']*/)) {
1023 print "X-KDE-IsAlso=" substr($0,RSTART+6,RLENGTH-6) 1138 print "X-KDE-IsAlso=" substr($0,RSTART+6,RLENGTH-6)
1024 } 1139 }
1025 else { 1140 else {
1026 print "Error: '"'"'type'"'"' argument missing in " RS $0 1141 print "Error: '"'"'type'"'"' argument missing in " RS $0
1027 exit 1 1142 exit 1
1028 } 1143 }
1029 } 1144 }
1030 if (match($0,/^glob/)) { 1145 if (match($0,/^glob/)) {
1031 if (match($0,/pattern="[^"]*/) || match($0,/pattern='"'"'[^'"'"']*/)) { 1146 if (match($0,/pattern="[^"]*/) || match($0,/pattern='"'"'[^'"'"']*/)) {
1032 glob_patterns = glob_patterns substr($0,RSTART+9,RLENGTH-9) ";" 1147 glob_patterns = glob_patterns substr($0,RSTART+9,RLENGTH-9) ";"
1033 } 1148 }
1034 else { 1149 else {
1035 print "Error: '"'"'pattern'"'"' argument missing in " RS $0 1150 print "Error: '"'"'pattern'"'"' argument missing in " RS $0
1036 exit 1 1151 exit 1
1037 } 1152 }
1038 } 1153 }
1039 if (match($0,/^comment/)) { 1154 if (match($0,/^comment/)) {
1040 if (match($0,/xml:lang="[^"]*/) || match($0,/xml:lang='"'"'[^'"'"']*/)) { 1155 if (match($0,/xml:lang="[^"]*/) || match($0,/xml:lang='"'"'[^'"'"']*/)) {
1041 lang=substr($0,RSTART+10,RLENGTH-10) 1156 lang=substr($0,RSTART+10,RLENGTH-10)
1042 } 1157 }
1043 else { 1158 else {
1044 lang="" 1159 lang=""
1045 } 1160 }
1046 if (match($0,/>/)) { 1161 if (match($0,/>/)) {
1047 comment=substr($0,RSTART+1) 1162 comment=substr($0,RSTART+1)
1048 sub("&lt;", "<", comment) 1163 sub("&lt;", "<", comment)
1049 sub("&gt;", ">", comment) 1164 sub("&gt;", ">", comment)
1050 sub("&amp;", "\\&", comment) 1165 sub("&amp;", "\\&", comment)
1051 if (lang) 1166 if (lang)
1052 print "Comment[" lang "]=" comment 1167 print "Comment[" lang "]=" comment
1053 else 1168 else
1054 print "Comment=" comment 1169 print "Comment=" comment
1055 } 1170 }
1056 } 1171 }
1057 } 1172 }
1058 } 1173 }
1059 END { 1174 END {
1060 if (!found) { 1175 if (!found) {
1061 print "Error: Mimetype '"'"'" the_type "'"'"' not found" 1176 print "Error: Mimetype '"'"'" the_type "'"'"' not found"
1062 exit 1 1177 exit 1
1063 } 1178 }
1064 } 1179 }
1065 ' $x $basefile 1180 ' $x $basefile
1066 if [ "$?" = "1" ] ; then 1181 if [ "$?" = "1" ] ; then
1067 grep -A 10 "^Error:" $kde_dir/$x.desktop >&2 1182 grep -A 10 "^Error:" $kde_dir/$x.desktop >&2
1068 rm $kde_dir/$x.desktop 1183 rm $kde_dir/$x.desktop
1069 exit 1 1184 exit 1
1070 fi 1185 fi
1071 done 1186 done
1072 fi 1187 fi
1073 1188
1074 umask $save_umask 1189 umask $save_umask
1075 ;; 1190 ;;
1076 1191
1077 uninstall) 1192 uninstall)
1078 for x in $xdg_dir ; do 1193 for x in $xdg_dir ; do
1079 rm -f $x/$basefile 1194 rm -f $x/$basefile
1080 done 1195 done
1081 1196
1082 # No quotes around $mimetypes 1197 # No quotes around $mimetypes
1083 for x in $mimetypes ; do 1198 for x in $mimetypes ; do
1084 if grep '^# Installed by xdg-mime' $kde_dir/$x.desktop >/dev/null 2> &1; then 1199 if grep '^# Installed by xdg-mime' $kde_dir/$x.desktop >/dev/null 2> &1; then
1085 DEBUG 1 "Removing $kde_dir/$x.desktop (KDE 3.x support)" 1200 DEBUG 1 "Removing $kde_dir/$x.desktop (KDE 3.x support)"
1086 rm -f $kde_dir/$x.desktop 1201 rm -f $kde_dir/$x.desktop
1087 fi 1202 fi
1088 done 1203 done
1089 ;; 1204 ;;
1090 esac 1205 esac
1091 1206
1092 update_mime_database $xdg_base_dir 1207 update_mime_database $xdg_base_dir
1093 1208
1094 exit_success 1209 exit_success
1095 1210
OLDNEW
« no previous file with comments | « third_party/xdg-utils/scripts/xdg-icon-resource.in ('k') | third_party/xdg-utils/scripts/xdg-mime.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698