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