#!/bin/csh -f
# This script installs new directories on NFS servers. 

# The following exit codes are defined and MUST BE CONSISTENT with the
# MR error codes the library uses:
set MR_PROTO = 47836477

set path=(/etc /bin /usr/bin /usr/etc)

# Find out what device we're working on
set dev = $1

set USERTAR = /tmp/nfs.dir/proto.tar	# Tarfile for user . files

# So that the new directories get the right protections.
umask 66

while (1)
   # Do this until there are no more lines of input
   set input = `echo $<`
   if ($#input != 4) break

   set dir = $input[1]
   set uid = $input[2]
   set gid = $input[3]
   set type = $input[4]

   # Don't do anything if the directory already exists
   if (-d $dir) continue

   while (1)
      set tmpdir = $dir:h/_$dir:t
      # Don't clobber this directory if it exists.
      if (-d $tmpdir) then
	 break;
      else
         mkdir $tmpdir
         # At some point it may be wise to check the status here and 
         # return a soft failure, but the current protocol doesn't
         # support this
         break
      endif
   end
   if (! -d $tmpdir) continue
   chown $uid.$gid $tmpdir

   # At some point, we may wish to add a more elegant way of handling 
   # locker types.  The current arrangement allows for easy adding of 
   # default actions here.
   switch ($type)
      case HOMEDIR:
         
         # ***** Remove this when /etc/encorce_quota becomes obsolete!
         # Give this filesystem a 1200K quota
         setquota $dev $uid 1200
         # *****

         # Give user prototype files
         (cd $tmpdir; tar xf $USERTAR)
         if ($status) set WARN
	 chown $uid.$gid $tmpdir $tmpdir/.??* $tmpdir/*
         breaksw      
      case COURSE:
	 /bin/chmod 775 $tmpdir
	 breaksw
      default:
         breaksw
   endsw

   mv $tmpdir $dir
   ### Soft failure when ready
end

exit 0

#
# 	$Source: /afs/athena.mit.edu/astaff/project/moiradev/src/gen/RCS/install_dirs,v $
#	$Header: /afs/athena.mit.edu/astaff/project/moiradev/src/gen/RCS/install_dirs,v 1.10 91/01/04 11:57:04 mar Exp $
#
