#! /bin/sh
# avfscoda
# generic init script

rc_failed="\tFAILED"
rc_done="\tOK"

return=$rc_done
case "$1" in
    start)
	echo -n "Loading redir module"
	/sbin/modprobe -s redir || return=$rc_failed
	echo -e "$return"
	
	# try to load coda module (no problem if it fails, because it can be
	# in the kernel)
	/sbin/modprobe coda > /dev/null 2>&1

	return=$rc_done
	echo -n "Starting avfscoda"
	/usr/sbin/avfscoda || return=$rc_failed
	echo -e "$return"
	;;

    stop)
	echo -n "Shutting down avfscoda"
	if test -x /usr/sbin/flushredir; then
	    /usr/sbin/flushredir
	fi
	/usr/bin/killall avfscoda || return=$rc_failed
	echo -e "$return"

	return=$rc_done
	echo -n "Unloading redir module"
	/sbin/rmmod -s redir || return=$rc_failed
	echo -e "$return"
	;;

    restart|reload)
	$0 stop && $0 start || return=$rc_failed
	;;

    status)
	echo "Checking for avfscoda: ???"
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload}"
	exit 1
	;;
esac

# Inform the caller not only verbosely and set an exit status.
test "$return" = "$rc_done" || exit 1
exit 0
