#!/bin/bash
#
#	/etc/rc.d/init.d/cfsd
#
# Starts the crypto filesystem CFS
#
# chkconfig: - 73 27
# description: Starts the crypto filesystem providing encryption \
#	       functionality

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

test -x /usr/sbin/cfsd || exit 5


CFSD_MNT_POINT=/mnt/crypt
CFSD_OPTIONS=
test -f /etc/sysconfig/cfsd && . /etc/sysconfig/cfsd

prog=cfsd
lockfile=/var/lock/subsys/cfsd

start() {
    ret=1

    grep -qE "^[^[:space:]#]+[[:space:]]+$CFSD_MNT_POINT[[:space:]]+" /etc/fstab || {
	action $"Starting $prog: " false
	echo "*** CFS mount-point not configured; please see"
	echo "*** /usr/share/doc/cfs-*/INSTALL for details"
	return 6
    }
	
    # Check if cfsd is already running
    if [ ! -f $lockfile  ]; then
	echo -n $"Starting $prog: "
	daemon /usr/sbin/cfsd ${CFSD_OPTIONS}
	ret=$?
	echo
	if [ $ret -eq 0 ]; then
	    touch $lockfile
	    action $"Mounting CFS dir: " mount ${CFSD_MNT_POINT}
	    ret=$?
	fi
    fi
    
    return $ret
}

stop() {
    action $"Unmounting CFS dir: " umount ${CFSD_MNT_POINT}
    echo -n $"Stopping $prog: "
    killproc /usr/sbin/cfsd
    ret=$?
    [ $ret -eq 0 ] && rm -f $lockfile
    echo
    return $ret
}


restart() {
    stop
    rm -f $lockfile
    start
}	

reload() {
    restart
}	

case "$1" in
    start|stop|reload|restart)	$1 ;;
    condrestart)
	test \! -f "$lockfile" || restart
	;;
    status)
	status cfsd
	;;
    *)
	echo "Usage: cfsd {start|stop|restart|condrestart|status}"
	exit 2
esac
