2005-08-13 [hoa] 1.9.13cvs33
[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 #Check to see if we can coax kde-config into the PATH
12 echo "Checking for kde-config..."
13 if [ -z "$(type 'kde-config' 2> /dev/null)" ]; then #Odd way of checking if kde-config is in $PATH
14   echo "kde-config not found, checking for \$KDEDIR to compensate..."
15   if [ ! -z $KDEDIR ]; then
16     export PATH=$PATH:$KDEDIR/bin
17   else
18     echo "***"
19     echo "***$0 cannot figure out where KDE is installed."
20     echo "***kde-config is not in \$PATH, and \$KDEDIR is not set."
21     echo "***To fix this, manually change \$PATH to add the KDE executables."
22     echo "***E.g. export PATH=\$PATH:/opt/kde/bin"
23     echo "***It would also be a good idea to add this line to your shell login/profile."
24     echo "***"
25     echo
26     echo "Nothing was installed or removed."
27     exit 1
28   fi
29 fi
30 echo "Okay."
31 }
32
33 function install_all {
34 #Go ahead and install
35 echo "Generating $DESKTOP_ONE ..."
36 SED_PREFIX=${PREFIX//\//\\\/} #Replace forward slashes in $PREFIX with \/ so that sed doesn't freak out
37 sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE_ONE > $DESKTOP_ONE
38 echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE"
39 mv -f $DESKTOP_ONE $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE
40 echo "Generating $DESKTOP_TWO ..."
41 SED_PREFIX=${PREFIX//\//\\\/} #Replace forward slashes in $PREFIX with \/ so that sed doesn't freak out
42 sed "s/SCRIPT_PATH/$SED_PREFIX\\/bin\\/$PERL_SCRIPT/" $DESKTOP_TEMPLATE_TWO > $DESKTOP_TWO
43 echo "Installing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO"
44 mv -f $DESKTOP_TWO $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
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_ONE
49 chmod 0644 $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
50 chmod 0755 $PREFIX/bin/$PERL_SCRIPT
51 }
52
53 function uninstall_all {
54 echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE"
55 rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP_ONE
56 echo "Removing $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO"
57 rm $PREFIX/$SERVICEMENU_DIR/$DESKTOP_TWO
58 echo "Removing $PREFIX/bin/$PERL_SCRIPT"
59 rm $PREFIX/bin/$PERL_SCRIPT
60 echo "Finished uninstall."
61 }
62
63 case $1 in
64   "--global" )
65     check_environ
66     PREFIX=$(kde-config --prefix)
67     echo "Installing in $PREFIX ..."
68     if [ "$(id -u)" != "0" ]; then
69         exec kdesu "$0 --global"
70     fi
71     install_all
72     ;;
73   "--local" )
74     check_environ
75     PREFIX=$(kde-config --localprefix)
76     echo "Installing in $PREFIX ..."
77     if [ ! -d $PREFIX/bin ]; then
78       mkdir $PREFIX/bin
79     fi
80     if [ ! -d $PREFIX/$SERVICEMENU_DIR ]; then
81       mkdir $PREFIX/$SERVICEMENU_DIR
82     fi
83     install_all
84     ;;
85   "--uninstall-global" )
86     check_environ
87     PREFIX=$(kde-config --prefix)
88     echo "Uninstalling in $PREFIX ..."
89     if [ "$(id -u)" != "0" ]; then
90         exec kdesu "$0 --uninstall-global"
91     fi
92     uninstall_all
93     ;;
94   "--uninstall-local" )
95     check_environ
96     PREFIX=$(kde-config --localprefix)
97     echo "Uninstalling in $PREFIX ..."
98     uninstall_all
99     ;;
100   * )
101     echo "Usage: $0 [--global|--local|--uninstall-global|--uninstall-local]"
102     echo
103     echo "    --global            attempts a system-wide installation."
104     echo "    --local             attempts to install in your home directory."
105     echo "    --uninstall-global  attempts a system-wide uninstallation."
106     echo "    --uninstall-local   attempts to uninstall in your home directory."
107     echo
108     exit 0
109     ;;
110 esac
111
112 echo "Done."