2004-12-06 [colin] 0.9.12cvs187.1
[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       echo "You are not root, as would be expected."
70       echo "However, we will still attempt a system-wide install."
71       echo "But, you probably don't have permission."
72     fi
73     install_all
74     ;;
75   "--local" )
76     check_environ
77     PREFIX=$(kde-config --localprefix)
78     echo "Installing in $PREFIX ..."
79     if [ ! -d $PREFIX/bin ]; then
80       mkdir $PREFIX/bin
81     fi
82     if [ ! -d $PREFIX/$SERVICEMENU_DIR ]; then
83       mkdir $PREFIX/$SERVICEMENU_DIR
84     fi
85     install_all
86     ;;
87   "--uninstall-global" )
88     check_environ
89     PREFIX=$(kde-config --prefix)
90     echo "Uninstalling in $PREFIX ..."
91     if [ "$(id -u)" != "0" ]; then
92       echo "You are not root, if you have any global installs, you will probably not have permission to remove them."
93     fi
94     uninstall_all
95     ;;
96   "--uninstall-local" )
97     check_environ
98     PREFIX=$(kde-config --localprefix)
99     echo "Uninstalling in $PREFIX ..."
100     uninstall_all
101     ;;
102   * )
103     echo "Usage: $0 [--global|--local|--uninstall-global|--uninstall-local]"
104     echo
105     echo "    --global            attempts a system-wide installation."
106     echo "    --local             attempts to install in your home directory."
107     echo "    --uninstall-global  attempts a system-wide uninstallation."
108     echo "    --uninstall-local   attempts to uninstall in your home directory."
109     echo
110     exit 0
111     ;;
112 esac
113
114 echo "Done."