#!/bin/csh -f

#
# Added "-h" flag to all chown -hs and chgrp -hs (got sick of seeing errors 
# from cron every day!)          matt 	2/26/99

set ADMIN=tmhill
set SEMESTER=fall99
set ECHO=
set VERBOSE=0

##########

if ($1 == "-v") set VERBOSE=1

##########

set groups=(`ypcat group | grep '^cs' | sed -e 's/:.*//' | grep -v owner | sort`)

cd /csinfo/www/courses/archive/$SEMESTER

foreach directory ($groups)
	if (-d $directory) then
		if ($VERBOSE) echo ""
		if ($VERBOSE) echo " processing directory $directory..."
		if ($VERBOSE) echo "  chgrp -h -R $directory $directory"
		${ECHO} chgrp -h -R $directory $directory
		if ($VERBOSE) echo "  chmod -R g+rw $directory"
		${ECHO} chmod -R g+rw $directory
		if ($VERBOSE) echo "  find $directory -type d -exec chmod u+x,g+xs {} \;"
		${ECHO} find $directory -type d -exec chmod u+x,g+xs {} \;
		set owner=`ypcat group | grep "^${directory}-owner" | sed -e 's/^.*:.*://'`
		if ( "$owner" == "" ) then
			if ($VERBOSE) echo "  chown -h -R $ADMIN $directory"
			${ECHO} chown -h -R $ADMIN $directory
		else
			if ($VERBOSE) echo "  chown -h -R $owner $directory"
			${ECHO} chown -h -R $owner $directory
		endif
		if ($VERBOSE) echo "  find $directory -type d -exec chmod u+rwx {} \;"
		${ECHO} find $directory -type d -exec chmod u+rwx {} \;
	endif
end
