]> git.sur5r.net Git - bacula/bacula/blob - bacula/platforms/slackware/local-install.sh
ebl Update using -mwindows
[bacula/bacula] / bacula / platforms / slackware / local-install.sh
1 #!/bin/sh
2 # local-install.sh
3 # for Bacula on Slackware platform
4 # Phil Stracchino 13 Mar 2004
5 #
6 # Installs and removes Bacula install section into /etc/rc.d/rc.local
7 # provided /etc/rc.d/rc.local is writeable.  Creates a backup copy of
8 # /etc/rc.d/rc.local in /etc/rc.d/rc.local.bak if /etc/rc.d is writeable.
9 #
10 # Usage: local-install.sh install|remove [destdir]
11 #
12 # uncomment for debugging:
13 #set -x
14
15 if [ -n "$2" ] ; then
16    TARG=$DESTDIR/etc/rc.d/rc.local
17 else
18    TARG=/etc/rc.d/rc.local
19 fi
20
21 if [ ! -f $TARG ] ; then
22    echo $TARG does not appear to exist.  Bailing out.
23    exit -1
24 fi
25
26 if [ "$1" = "install" ] ; then
27    echo Installing Bacula autostart into $TARG:
28    COUNT=`grep -c "Bacula section @@@@" $TARG`
29    if [ ! "$COUNT" == "0" ] ; then
30       echo -e "\tBacula autostart section appears to be already installed.\n\tIf you have changed the configuration, make uninstall-autostart\n\tthen make install-autostart again.\n"
31    else
32       if [ -w $TARG ] ; then
33          if [ -w `dirname $TARG` ] ; then
34             cp -p $TARG $TARG.bak
35             echo -e "\tBackup copy of $TARG saved in $TARG.bak."
36          else
37             echo -e "\tWARNING: Unable to create backup copy of $TARG.\n\tAttempting to continue anyway.";
38          fi
39          cat >> $TARG << EOF
40 # @@@@ Start Bacula section @@@@
41 # The line above is needed to automatically remove bacula.
42
43 if [ -x /etc/rc.d/rc.bacula-sd ]; then
44    /etc/rc.d/rc.bacula-sd start
45 fi
46 if [ -x /etc/rc.d/rc.bacula-fd ]; then
47    /etc/rc.d/rc.bacula-fd start
48 fi
49 if [ -x /etc/rc.d/rc.bacula-dir ]; then
50    /etc/rc.d/rc.bacula-dir start
51 fi
52
53 # @@@@ End Bacula section @@@@
54 EOF
55          echo -e "\tBacula autostart section has been installed in $TARG.\n";
56       else
57          echo -e "\tERROR!  Cannot write to $TARG.\n\tBailing out.\n"
58          exit -1
59       fi
60    fi
61 elif [ "$1" = "remove" ] ; then
62    echo Removing Bacula autostart from $TARG:
63    COUNT=`grep -c "Bacula section @@@@" $TARG`
64    if [ ! "$COUNT" == "2" ] ; then
65       echo -e "\tCould not find Bacula autostart section in $TARG.  Bailing out.\n"
66       exit -1
67    else
68       if [ -w $TARG ] ; then
69          if [ -w `dirname $TARG` ] ; then
70             cp -p $TARG $TARG.bak
71             echo -e "\tBackup copy of $TARG saved in $TARG.bak."
72          else
73             echo -e "\tWARNING: Unable to create backup copy of $TARG.\n\tAttempting to continue anyway.";
74          fi
75          FIRST=`grep -n "@@@@ Start Bacula section @@@@" $TARG | cut -d: -f1`
76          LAST=`grep -n "@@@@ End Bacula section @@@@" $TARG | cut -d: -f1`
77          FIRST=`expr $FIRST - 1`
78          LAST=`expr $LAST + 1`
79          head -$FIRST $TARG > ./installtmp
80          tail +$LAST $TARG >> ./installtmp
81          cat ./installtmp > $TARG
82          rm ./installtmp
83          echo -e "\tBacula autostart section has been removed from $TARG.\n";
84       fi
85    fi
86 else
87    echo -e "\tUSAGE: $0 install|remove [destdir]"
88 fi
89 exit 0