1#!/bin/sh 2# local-install.sh 3# for Bareos on Slackware platform 4# Phil Stracchino 13 Mar 2004 5# 6# Installs and removes Bareos 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 15if [ -n "$2" ] ; then 16 TARG=$DESTDIR/etc/rc.d/rc.local 17else 18 TARG=/etc/rc.d/rc.local 19fi 20 21if [ ! -f $TARG ] ; then 22 echo $TARG does not appear to exist. Bailing out. 23 exit -1 24fi 25 26if [ "$1" = "install" ] ; then 27 echo Installing Bareos autostart into $TARG: 28 COUNT=`grep -c "Bareos section @@@@" $TARG` 29 if [ ! "$COUNT" == "0" ] ; then 30 echo -e "\tBareos 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 Bareos section @@@@ 41# The line above is needed to automatically remove bareos. 42 43if [ -x /etc/rc.d/rc.bareos-sd ]; then 44 /etc/rc.d/rc.bareos-sd start 45fi 46if [ -x /etc/rc.d/rc.bareos-fd ]; then 47 /etc/rc.d/rc.bareos-fd start 48fi 49if [ -x /etc/rc.d/rc.bareos-dir ]; then 50 /etc/rc.d/rc.bareos-dir start 51fi 52 53# @@@@ End Bareos section @@@@ 54EOF 55 echo -e "\tBareos 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 61elif [ "$1" = "remove" ] ; then 62 echo Removing Bareos autostart from $TARG: 63 COUNT=`grep -c "Bareos section @@@@" $TARG` 64 if [ ! "$COUNT" == "2" ] ; then 65 echo -e "\tCould not find Bareos 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 Bareos section @@@@" $TARG | cut -d: -f1` 76 LAST=`grep -n "@@@@ End Bareos 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 "\tBareos autostart section has been removed from $TARG.\n"; 84 fi 85 fi 86else 87 echo -e "\tUSAGE: $0 install|remove [destdir]" 88fi 89exit 0 90