install.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/usr/bin/env bash
  2. PERL_SCRIPT="claws-mail-kdeservicemenu.pl"
  3. DESKTOP="claws-mail-attach-files.desktop"
  4. function check_environ {
  5. echo "Checking for kde4-config..."
  6. if [ ! -z "$(type 'kde4-config' 2> /dev/null)" ]; then
  7. echo "Found kde4-config..."
  8. SERVICEMENU_DIR="share/kde4/services/ServiceMenus"
  9. DESKTOP_TEMPLATE="claws-mail-attach-files.desktop.kde4template"
  10. KDECONFIG="kde4-config"
  11. else
  12. echo "kde4-config not found..."
  13. echo "Checking for kde-config..."
  14. if [ ! -z "$(type 'kde-config' 2> /dev/null)" ]; then
  15. echo "Found kde-config..."
  16. SERVICEMENU_DIR="share/apps/konqueror/servicemenus"
  17. DESKTOP_TEMPLATE="claws-mail-attach-files.desktop.template"
  18. KDECONFIG="kde-config"
  19. else
  20. echo "kde-config not found..."
  21. echo "asking user to find kde4-config or kde-config..."
  22. KDECONFIG=$(kdialog --title "Locate kde-config or kde4-config" --getopenfilename / )
  23. test -z $KDECONFIG && exit 1
  24. if [[ $KDECONFIG == *4-config ]]; then
  25. SERVICEMENU_DIR="share/kde4/services/ServiceMenus"
  26. DESKTOP_TEMPLATE="claws-mail-attach-files.desktop.kde4template"
  27. else
  28. SERVICEMENU_DIR="share/apps/konqueror/servicemenus"
  29. DESKTOP_TEMPLATE="claws-mail-attach-files.desktop.template"
  30. fi
  31. fi
  32. fi
  33. }
  34. function install_all {
  35. echo "Generating $DESKTOP ..."
  36. SED_PREFIX=${PREFIX//\//\\\/}
  37. sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE > $DESKTOP
  38. echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP"
  39. mv -f $DESKTOP $PREFIX/$SERVICEMENU_DIR/$DESKTOP
  40. if [[ $? -ne 0 ]]
  41. then
  42. kdialog --error "Could not complete installation."
  43. exit
  44. fi
  45. echo "Installing $PREFIX/bin/$PERL_SCRIPT"
  46. cp -f $PERL_SCRIPT $PREFIX/bin/
  47. echo "Setting permissions ..."
  48. chmod 0644 $PREFIX/$SERVICEMENU_DIR/$DESKTOP
  49. chmod 0755 $PREFIX/bin/$PERL_SCRIPT
  50. echo "Finished installation."
  51. kdialog --msgbox "Finished installation."
  52. }
  53. function uninstall_all {
  54. echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP"
  55. rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP
  56. if [[ $? -ne 0 ]]
  57. then
  58. kdialog --error "Could not complete uninstall."
  59. exit
  60. fi
  61. echo "Removing $PREFIX/bin/$PERL_SCRIPT"
  62. rm $PREFIX/bin/$PERL_SCRIPT
  63. echo "Finished uninstall."
  64. kdialog --msgbox "Finished uninstall."
  65. }
  66. function show_help {
  67. echo "Usage: $0 [--global|--local|--uninstall-global|--uninstall-local]"
  68. echo
  69. echo " --global attempts a system-wide installation."
  70. echo " --local attempts to install in your home directory."
  71. echo " --uninstall-global attempts a system-wide uninstallation."
  72. echo " --uninstall-local attempts to uninstall in your home directory."
  73. echo
  74. exit 0
  75. }
  76. if [ -z $1 ]
  77. then option="--$(kdialog --menu "Please select installation type" \
  78. local "install for you only" \
  79. global "install for all users" \
  80. uninstall-local "uninstall for you only" \
  81. uninstall-global "uninstall for all users" 2> /dev/null)"
  82. else option=$1
  83. fi
  84. case $option in
  85. "--global" )
  86. check_environ
  87. PREFIX=$($KDECONFIG --prefix)
  88. echo "Installing in $PREFIX/$SERVICEMENU_DIR ..."
  89. if [ "$(id -u)" != "0" ]; then
  90. exec kdesu "$0 --global"
  91. fi
  92. install_all
  93. ;;
  94. "--local" )
  95. check_environ
  96. PREFIX=$($KDECONFIG --localprefix)
  97. echo "Installing in $PREFIX$SERVICEMENU_DIR ..."
  98. if [ ! -d $PREFIX/bin ]; then
  99. mkdir $PREFIX/bin
  100. fi
  101. if [ ! -d $PREFIX/$SERVICEMENU_DIR ]; then
  102. mkdir $PREFIX/$SERVICEMENU_DIR
  103. fi
  104. install_all
  105. ;;
  106. "--uninstall-global" )
  107. check_environ
  108. PREFIX=$($KDECONFIG --prefix)
  109. echo "Uninstalling from $PREFIX/$SERVICEMENU_DIR ..."
  110. if [ "$(id -u)" != "0" ]; then
  111. exec kdesu "$0 --uninstall-global"
  112. fi
  113. uninstall_all
  114. ;;
  115. "--uninstall-local" )
  116. check_environ
  117. PREFIX=$($KDECONFIG --localprefix)
  118. echo "Uninstalling from $PREFIX$SERVICEMENU_DIR ..."
  119. uninstall_all
  120. ;;
  121. "-h" )
  122. show_help
  123. ;;
  124. "--help" )
  125. show_help
  126. ;;
  127. * )
  128. show_help
  129. esac
  130. echo "Done."