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