6bb7874a15038e5ec4b5f1e10db8ab7e416cfc73
[claws.git] / tools / kdeservicemenu / install.sh
1 #!/bin/bash
2
3 PERL_SCRIPT="claws-mail-kdeservicemenu.pl"
4 DESKTOP_TEMPLATE="claws-mail-attach-files.desktop.template"
5 DESKTOP="claws-mail-attach-files.desktop"
6 SERVICEMENU_DIR="share/apps/konqueror/servicemenus"
7
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 "OK"
21 }
22
23 function install_all {
24 echo "Generating $DESKTOP ..."
25 SED_PREFIX=${PREFIX//\//\\\/}
26 sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE > $DESKTOP
27 echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP"
28 mv -f $DESKTOP $PREFIX/$SERVICEMENU_DIR/$DESKTOP
29 echo "Installing $PREFIX/bin/$PERL_SCRIPT"
30 cp -f $PERL_SCRIPT $PREFIX/bin/
31 echo "Setting permissions ..."
32 chmod 0644 $PREFIX/$SERVICEMENU_DIR/$DESKTOP
33 chmod 0755 $PREFIX/bin/$PERL_SCRIPT
34 echo "Finished installation."
35 kdialog --msgbox "Finished installation."
36 }
37
38 function uninstall_all {
39 echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP"
40 rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP
41 echo "Removing $PREFIX/bin/$PERL_SCRIPT"
42 rm $PREFIX/bin/$PERL_SCRIPT
43 echo "Finished uninstall."
44 kdialog --msgbox "Finished uninstall."
45 }
46
47 function show_help {
48     echo "Usage: $0 [--global|--local|--uninstall-global|--uninstall-local]"
49     echo
50     echo "    --global            attempts a system-wide installation."
51     echo "    --local             attempts to install in your home directory."
52     echo "    --uninstall-global  attempts a system-wide uninstallation."
53     echo "    --uninstall-local   attempts to uninstall in your home directory."
54     echo
55     exit 0
56 }
57
58 if [ -z $1 ]
59     then option="--$(kdialog --menu "Please select installation type" \
60                                 local "install for you only" \
61                                 global "install for all users" \
62                                 uninstall-local "uninstall for you only" \
63                                 uninstall-global "uninstall for all users"  2> /dev/null)"
64     else option=$1
65 fi
66
67 case $option in
68   "--global" )
69     check_environ
70     PREFIX=$(kde-config --prefix)
71     echo "Installing in $PREFIX ..."
72     if [ "$(id -u)" != "0" ]; then
73         exec kdesu "$0 --global"
74     fi
75     install_all
76     ;;
77   "--local" )
78     check_environ
79     PREFIX=$(kde-config --localprefix)
80     echo "Installing in $PREFIX ..."
81     if [ ! -d $PREFIX/bin ]; then
82       mkdir $PREFIX/bin
83     fi
84     if [ ! -d $PREFIX/$SERVICEMENU_DIR ]; then
85       mkdir $PREFIX/$SERVICEMENU_DIR
86     fi
87     install_all
88     ;;
89   "--uninstall-global" )
90     check_environ
91     PREFIX=$(kde-config --prefix)
92     echo "Uninstalling in $PREFIX ..."
93     if [ "$(id -u)" != "0" ]; then
94         exec kdesu "$0 --uninstall-global"
95     fi
96     uninstall_all
97     ;;
98   "--uninstall-local" )
99     check_environ
100     PREFIX=$(kde-config --localprefix)
101     echo "Uninstalling in $PREFIX ..."
102     uninstall_all
103     ;;
104   "-h" )
105     show_help
106     ;;
107   "--help" )
108     show_help
109     ;;
110   * )
111     show_help
112 esac
113
114 echo "Done."