2008-10-24 [paul] 3.6.1cvs10
[claws.git] / tools / kdeservicemenu / install.sh
index 8aba3459386f127a98a2961894c44ce262ec679e..8ffe42e6dcc30c336d41fc8654e6dbc190009938 100644 (file)
@@ -1,70 +1,89 @@
 #!/bin/bash
 
-PERL_SCRIPT="sylpheed-kdeservicemenu.pl"
-DESKTOP_TEMPLATE_ONE="template_sylpheed-attach-files.desktop"
-DESKTOP_ONE="sylpheed-attach-files.desktop"
-DESKTOP_TEMPLATE_TWO="template_sylpheed-compress-attach.desktop"
-DESKTOP_TWO="sylpheed-compress-attach.desktop"
+PERL_SCRIPT="claws-mail-kdeservicemenu.pl"
+DESKTOP_TEMPLATE="claws-mail-attach-files.desktop.template"
+DESKTOP="claws-mail-attach-files.desktop"
 SERVICEMENU_DIR="share/apps/konqueror/servicemenus"
 
 function check_environ {
-#Check to see if we can coax kde-config into the PATH
-echo "Checking for kde-config..."
-if [ -z "$(type 'kde-config' 2> /dev/null)" ]; then #Odd way of checking if kde-config is in $PATH
-  echo "kde-config not found, checking for \$KDEDIR to compensate..."
-  if [ ! -z $KDEDIR ]; then
-    export PATH=$PATH:$KDEDIR/bin
+echo "Checking for kde4-config..."
+if [ ! -z "$(type 'kde4-config' 2> /dev/null)" ]; then
+  echo "Found kde4-config..."
+  KDECONFIG="kde4-config"
+else
+  echo "kde4-config not found..."
+  echo "Checking for kde-config..."
+  if [ ! -z "$(type 'kde-config' 2> /dev/null)" ]; then
+      echo "Found kde-config..."
+      KDECONFIG="kde-config"
   else
-    echo "***"
-    echo "***$0 cannot figure out where KDE is installed."
-    echo "***kde-config is not in \$PATH, and \$KDEDIR is not set."
-    echo "***To fix this, manually change \$PATH to add the KDE executables."
-    echo "***E.g. export PATH=\$PATH:/opt/kde/bin"
-    echo "***It would also be a good idea to add this line to your shell login/profile."
-    echo "***"
-    echo
-    echo "Nothing was installed or removed."
-    exit 1
+    echo "kde-config not found..."
+    echo "asking user to find kde4-config or kde-config..."
+    KDECONFIG=$(kdialog --title "Locate kde-config or kde4-config" --getopenfilename / )
+    test -z $KDECONFIG && exit 1
   fi
 fi
-echo "Okay."
 }
 
 function install_all {
-#Go ahead and install
-echo "Generating $DESKTOP_ONE ..."
-SED_PREFIX=${PREFIX//\//\\\/} #Replace forward slashes in $PREFIX with \/ so that sed doesn't freak out
-sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE_ONE > $DESKTOP_ONE
-echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE"
-mv -f $DESKTOP_ONE $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE
-echo "Generating $DESKTOP_TWO ..."
-SED_PREFIX=${PREFIX//\//\\\/} #Replace forward slashes in $PREFIX with \/ so that sed doesn't freak out
-sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE_TWO > $DESKTOP_TWO
-echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO"
-mv -f $DESKTOP_TWO $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
+echo "Generating $DESKTOP ..."
+SED_PREFIX=${PREFIX//\//\\\/}
+sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE > $DESKTOP
+echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP"
+mv -f $DESKTOP $PREFIX/$SERVICEMENU_DIR/$DESKTOP
+if [[ $? -ne 0 ]]
+then
+  kdialog --error "Could not complete installation."
+  exit
+fi
 echo "Installing $PREFIX/bin/$PERL_SCRIPT"
 cp -f $PERL_SCRIPT $PREFIX/bin/
 echo "Setting permissions ..."
-chmod 0644 $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE
-chmod 0644 $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
+chmod 0644 $PREFIX/$SERVICEMENU_DIR/$DESKTOP
 chmod 0755 $PREFIX/bin/$PERL_SCRIPT
+echo "Finished installation."
+kdialog --msgbox "Finished installation."
 }
 
 function uninstall_all {
-echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE"
-rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE
-echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO"
-rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
+echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP"
+rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP
+if [[ $? -ne 0 ]]
+then
+  kdialog --error "Could not complete uninstall."
+  exit
+fi
 echo "Removing $PREFIX/bin/$PERL_SCRIPT"
 rm $PREFIX/bin/$PERL_SCRIPT
 echo "Finished uninstall."
+kdialog --msgbox "Finished uninstall."
+}
+
+function show_help {
+    echo "Usage: $0 [--global|--local|--uninstall-global|--uninstall-local]"
+    echo
+    echo "    --global            attempts a system-wide installation."
+    echo "    --local             attempts to install in your home directory."
+    echo "    --uninstall-global  attempts a system-wide uninstallation."
+    echo "    --uninstall-local   attempts to uninstall in your home directory."
+    echo
+    exit 0
 }
 
-case $1 in
+if [ -z $1 ]
+    then option="--$(kdialog --menu "Please select installation type" \
+                               local "install for you only" \
+                               global "install for all users" \
+                               uninstall-local "uninstall for you only" \
+                               uninstall-global "uninstall for all users"  2> /dev/null)"
+    else option=$1
+fi
+
+case $option in
   "--global" )
     check_environ
-    PREFIX=$(kde-config --prefix)
-    echo "Installing in $PREFIX ..."
+    PREFIX=$($KDECONFIG --prefix)
+    echo "Installing in $PREFIX/$SERVICEMENU_DIR ..."
     if [ "$(id -u)" != "0" ]; then
        exec kdesu "$0 --global"
     fi
@@ -72,8 +91,8 @@ case $1 in
     ;;
   "--local" )
     check_environ
-    PREFIX=$(kde-config --localprefix)
-    echo "Installing in $PREFIX ..."
+    PREFIX=$($KDECONFIG --localprefix)
+    echo "Installing in $PREFIX$SERVICEMENU_DIR ..."
     if [ ! -d $PREFIX/bin ]; then
       mkdir $PREFIX/bin
     fi
@@ -84,8 +103,8 @@ case $1 in
     ;;
   "--uninstall-global" )
     check_environ
-    PREFIX=$(kde-config --prefix)
-    echo "Uninstalling in $PREFIX ..."
+    PREFIX=$($KDECONFIG --prefix)
+    echo "Uninstalling from $PREFIX/$SERVICEMENU_DIR ..."
     if [ "$(id -u)" != "0" ]; then
        exec kdesu "$0 --uninstall-global"
     fi
@@ -93,20 +112,18 @@ case $1 in
     ;;
   "--uninstall-local" )
     check_environ
-    PREFIX=$(kde-config --localprefix)
-    echo "Uninstalling in $PREFIX ..."
+    PREFIX=$($KDECONFIG --localprefix)
+    echo "Uninstalling from $PREFIX$SERVICEMENU_DIR ..."
     uninstall_all
     ;;
-  * )
-    echo "Usage: $0 [--global|--local|--uninstall-global|--uninstall-local]"
-    echo
-    echo "    --global            attempts a system-wide installation."
-    echo "    --local             attempts to install in your home directory."
-    echo "    --uninstall-global  attempts a system-wide uninstallation."
-    echo "    --uninstall-local   attempts to uninstall in your home directory."
-    echo
-    exit 0
+  "-h" )
+    show_help
+    ;;
+  "--help" )
+    show_help
     ;;
+  * )
+    show_help
 esac
 
 echo "Done."