#!/bin/csh -f
#
# $Header: /afs/athena.mit.edu/astaff/project/moiradev/src/gen/RCS/zero_quotas,v 1.3 90/03/19 19:07:48 mar Exp $
#
# This script zeros quotas for uid's which are not in standard input
# Note that the input must be sorted in increasing order by uid.

set dev=$1
set MR_SETQUOTA = 47836471

# Checking for /etc/zero_old_quotas allows us to release this program
# one server at a time.

if ( -f /etc/zero_old_quotas ) then

   set current_uid = 0

   while (1)
      # set args = $< will NOT work.  $< will be treated as a single word
      set args = `echo $<`
 
      if (${#args} != 2) break   # end of input

      set uid = $args[1]
      @ checksorted = ($current_uid <= $uid)

      if (checksorted == 0) then 
	echo "Input not sorted"
	exit $MR_SETQUOTA
      endif

      # zero all quotas between current_uid and uid (not including uid)
      if ($current_uid != $uid) then
	@ uid_high = $uid - 1
        setquota -r $dev $current_uid $uid_high 0
      endif

     # skip over $uid
     @ current_uid = $uid + 1

   end
  
   # zero all remaining quotas, except for nobody (32767).
   if ($current_uid != 32767) setquota -r $dev $current_uid 32766 0
   
endif

exit 0

