#! /bin/sh
#

FLAGS=-aug


# check if quota are enabled
if grep -q '^[^#]*quota' /etc/fstab && grep -q '^/' /etc/exports; then
	need_rquotad=1
else
	need_rquotad=0
fi


# names of binaries
check=/sbin/quotacheck
on=/sbin/quotaon
off=/sbin/quotaoff
quotad=/usr/sbin/rpc.rquotad


case "$1" in
  start)
     # Check quotas.
     if [ -x $check ]
     then
        echo -n 'Checking quotas...';
	$check $FLAGS
        echo 'done.'

     fi 
     # Turn quotas on.
     if [ -x $on ]
     then
        echo 'Turning on quotas.';
        $on $FLAGS
     fi
     # The daemon
     if [ -x $quotad -a $need_rquotad = 1 ]; then
        echo -n 'Starting quota services: rpc.rquotad'
	start-stop-daemon --start --quiet --exec $quotad
	echo "."
     fi
    ;;
  stop)
     echo -n 'Turning off quotas'
     start-stop-daemon --stop --oknodo --quiet --exec $quotad
     if [ -x $off ]
     then
	$off $FLAGS
     fi
     echo "."
    ;;
  force-reload)
    $0 rerestart
	;;
  restart)
	$0 stop
	$0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|force-reload}"
    exit 1
esac

exit 0
