#!/bin/bash
#
# openafs-client	Start/Stop the OpenAFS Client
#
# chkconfig: 2345 50 50
# description: OpenAFS is a distributed filesystem.
#
# $Revision: 1.1.2.3 $

[ -f /etc/init.d/functions ] && . /etc/init.d/functions
[ -f /etc/sysconfig/openafs ] && . /etc/sysconfig/openafs


start() {
        echo -n $"Updating CellServDB: "
        cat /usr/vice/etc/CellServDB.local /usr/vice/etc/CellServDB.dist > \
               /usr/vice/etc/CellServDB
        chmod 644 /usr/vice/etc/CellServDB
        echo
        echo -n $"Updating SuidCells: "
        cat /usr/vice/etc/SuidCells.local /usr/vice/etc/SuidCells.dist > \
               /usr/vice/etc/SuidCells
        chmod 644 /usr/vice/etc/SuidCells
        echo
	echo -n $"Starting openafs-client: "
	if [ -e /var/lock/subsys/openafs-client ] ; then
		echo -n $"cannot start openafs-client: already running"
		failure $"cannot start openafs-client: already running"
		echo
		return 1
	fi
	modprobe openafs
	RETVAL=$?
	if [ $RETVAL -ne 0 ] ; then
		echo -n $"failed to load openafs kernel module."
		failure $"failed to load openafs kernel module."
		echo
		return $RETVAL
	fi
	/usr/vice/etc/afsd $AFSD_ARGS
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/openafs-client
	return $RETVAL
}

stop() {
	echo -n $"Stopping openafs-client: "
	if [ ! -e /var/lock/subsys/openafs-client ] ; then
		echo -n $"cannot stop openafs-client: not running"
		failure $"cannot stop openafs-client: not running"
		echo
		return 1
	fi
	umount /afs
	RETVAL=$?
	echo
	if [ $RETVAL -eq 0 ] ; then
		rm -f /var/lock/subsys/openafs-client
		rmmod openafs
	fi
	return $RETVAL
}

rhstatus() {
	status afsd
}

restart() {
	stop || exit
	start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  status)
        rhstatus
        ;;
  condrestart)
        [ -f /var/lock/subsys/openafs-client ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart}"
        exit 1
esac
