#! /bin/sh
#
# SureRestore       This shell script takes care of starting and stopping
#	       the SureRestore File daemon.
#
# chkconfig: 2345 91 9
# description: It comes by night and sucks the vital essence from your computers.
#
#  For SureRestore release 2.4.0 (04 June 2008) -- redhat
#

# Source function library
. /etc/rc.d/init.d/functions

test -e /etc/SureRestore/SureRestore-fd.conf
if [ $? != 0 ]; then
    echo "SureRestore config file missing ( /etc/SureRestore/SureRestore-fd.conf ). Not starting"
    exit 1
fi

FD_USER=root
FD_GROUP=SureRestore
FD_OPTIONS=''
OS=`uname -s`

# if /lib/tls exists, force SureRestore to use the glibc pthreads instead
if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
     export LD_ASSUME_KERNEL=2.4.19
fi

# pull in any user defined FD_OPTIONS, FD_USER, FD_GROUP 
[ -f /etc/sysconfig/SureRestore ] && . /etc/sysconfig/SureRestore

RETVAL=0
case "$1" in
    start)
       if [ "${FD_USER}" != '' ]; then
	  FD_OPTIONS="${FD_OPTIONS} -u ${FD_USER}"
       fi
										   
       if [ "${FD_GROUP}" != '' ]; then
	  FD_OPTIONS="${FD_OPTIONS} -g ${FD_GROUP}"
       fi
       echo -n "Starting SureRestore File services: "
       daemon /usr/sbin/SureRestore-fd $2 ${FD_OPTIONS} -c /etc/SureRestore/SureRestore-fd.conf
       RETVAL=$?
       echo
       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/SureRestore-fd
       ;;
    stop)
       echo -n "Stopping SureRestore File services: "
       killproc /usr/sbin/SureRestore-fd
       RETVAL=$?
       echo
       [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/SureRestore-fd
       ;;
    restart)
       $0 stop
       sleep 5
       $0 start
       ;;
    status)
       status /usr/sbin/SureRestore-fd
       ;;
    *)
       echo "Usage: $0 {start|stop|restart|status}"
       exit 1
       ;;
esac
exit 0
