install.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. PERL_SCRIPT="sylpheed-kdeservicemenu.pl"
  3. DESKTOP_TEMPLATE_ONE="template_sylpheed-attach-files.desktop"
  4. DESKTOP_ONE="sylpheed-attach-files.desktop"
  5. DESKTOP_TEMPLATE_TWO="template_sylpheed-compress-attach.desktop"
  6. DESKTOP_TWO="sylpheed-compress-attach.desktop"
  7. SERVICEMENU_DIR="share/apps/konqueror/servicemenus"
  8. function check_environ {
  9. echo "Checking for kde-config..."
  10. if [ -z "$(type 'kde-config' 2> /dev/null)" ]; then
  11. echo "kde-config not found, checking for \$KDEDIR to compensate..."
  12. if [ ! -z $KDEDIR ]; then
  13. export PATH=$PATH:$KDEDIR/bin
  14. else
  15. KDEDIR=$(kdialog --title "Where is KDE installed?" --getexistingdirectory / )
  16. test -z $KDEDIR && exit 1
  17. export PATH=$PATH:$KDEDIR/bin
  18. fi
  19. fi
  20. echo "Okay."
  21. }
  22. function install_all {
  23. echo "Generating $DESKTOP_ONE ..."
  24. SED_PREFIX=${PREFIX//\//\\\/}
  25. sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE_ONE > $DESKTOP_ONE
  26. echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE"
  27. mv -f $DESKTOP_ONE $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE
  28. echo "Generating $DESKTOP_TWO ..."
  29. SED_PREFIX=${PREFIX//\//\\\/}
  30. sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE_TWO > $DESKTOP_TWO
  31. echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO"
  32. mv -f $DESKTOP_TWO $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
  33. echo "Installing $PREFIX/bin/$PERL_SCRIPT"
  34. cp -f $PERL_SCRIPT $PREFIX/bin/
  35. echo "Setting permissions ..."
  36. chmod 0644 $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE
  37. chmod 0644 $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
  38. chmod 0755 $PREFIX/bin/$PERL_SCRIPT
  39. echo "Finished installation."
  40. kdialog --msgbox "Finished installation."
  41. }
  42. function uninstall_all {
  43. echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE"
  44. rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE
  45. echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO"
  46. rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
  47. echo "Removing $PREFIX/bin/$PERL_SCRIPT"
  48. rm $PREFIX/bin/$PERL_SCRIPT
  49. echo "Finished uninstall."
  50. kdialog --msgbox "Finished uninstall."
  51. }
  52. function show_help {
  53. echo "Usage: $0 [--global|--local|--uninstall-global|--uninstall-local]"
  54. echo
  55. echo " --global attempts a system-wide installation."
  56. echo " --local attempts to install in your home directory."
  57. echo " --uninstall-global attempts a system-wide uninstallation."
  58. echo " --uninstall-local attempts to uninstall in your home directory."
  59. echo
  60. exit 0
  61. }
  62. if [ -z $1 ]
  63. then option="--$(kdialog --menu "Please select installation type" \
  64. local "install for you only" \
  65. global "install for all users" \
  66. uninstall-local "uninstall for you only" \
  67. uninstall-global "uninstall for all users" 2> /dev/null)"
  68. else option=$1
  69. fi
  70. case $option in
  71. "--global" )
  72. check_environ
  73. PREFIX=$(kde-config --prefix)
  74. echo "Installing in $PREFIX ..."
  75. if [ "$(id -u)" != "0" ]; then
  76. exec kdesu "$0 --global"
  77. fi
  78. install_all
  79. ;;
  80. "--local" )
  81. check_environ
  82. PREFIX=$(kde-config --localprefix)
  83. echo "Installing in $PREFIX ..."
  84. if [ ! -d $PREFIX/bin ]; then
  85. mkdir $PREFIX/bin
  86. fi
  87. if [ ! -d $PREFIX/$SERVICEMENU_DIR ]; then
  88. mkdir $PREFIX/$SERVICEMENU_DIR
  89. fi
  90. install_all
  91. ;;
  92. "--uninstall-global" )
  93. check_environ
  94. PREFIX=$(kde-config --prefix)
  95. echo "Uninstalling in $PREFIX ..."
  96. if [ "$(id -u)" != "0" ]; then
  97. exec kdesu "$0 --uninstall-global"
  98. fi
  99. uninstall_all
  100. ;;
  101. "--uninstall-local" )
  102. check_environ
  103. PREFIX=$(kde-config --localprefix)
  104. echo "Uninstalling in $PREFIX ..."
  105. uninstall_all
  106. ;;
  107. "-h" )
  108. show_help
  109. ;;
  110. "--help" )
  111. show_help
  112. ;;
  113. * )
  114. show_help
  115. esac
  116. echo "Done."