#!/bin/sh
case ${n-x} in
x)
	case `echo -n foo` in
	-n*)
		n="";c="\c";;foo)n="-n";c="";;
	esac
	export n c
	;;
esac
case $# in
1)
	account=$1
	;;
*)
	echo "usage: $0 account"
	exit 1
	;;
esac
fs=/bin/athena/fs
vos=/afs/athena.mit.edu/system/afsuser/bin/vos
src=/afs/sipb.mit.edu/project/guests/prototype
dst=/afs/sipb.mit.edu/user/$account
auid=`hesinfo $account passwd|awk -F: '{print $3}'`
case `whoami` in
root)
	;;
*)
	echo "You must be root"
	exit 1
	;;
esac
case $account in
sipb[0-7])
	;;
*)
	echo "You can only clean a valid guest account"
	exit 1
	;;
esac
cat<<EOF
Cleaning SIPB guest account $account.
Make sure you have system:administrators tokens!
Are you sure you want to obliterate the account $account?
EOF
echo $n "Enter YES to do it: $c"
read ans
case $ans in
YES)
	;;
*)
	echo "Cancelled."
	exit 1
	;;
esac
$vos e user.$account -c sipb>/tmp/vol.$account
sed -ne '2s=^[ 	]*\([^ 	]*\).*/vicep\(.*\)=\1 \2=p' \
	/tmp/vol.$account>/tmp/where.$account
$vos remove `cat /tmp/where.$account` user.$account -c sipb -verbose
$vos create `cat /tmp/where.$account` user.$account -c sipb -verbose
$fs checkv
$fs sq $dst  17500
$fs sa $dst system:anyuser rl $account all
echo $n "copying files... $c"
(cd $src;tar cf - .)|(cd $dst;tar xpf -)
echo "done."
echo $n "fixing directories... $c"
mkdir $dst/Mail
chmod 600 $dst/Mail
$fs sa $dst/Mail system:anyuser none
chown -R $auid $dst
$fs sa $dst/Mail system:administrators none
$fs sa $dst system:administrators none
echo "done."
$vos backup user.$account -c sipb -verbose
echo "SIPB guest account $account cleaned"
exit  0
