#!/bin/sh
###
###  Nuke a directory and take away the proper amount of credits from the
###  miserable soul that created the mess	13.aug.96 -Philter
###
###  Usage:  Nuke <dir> [reason]
###
###	$# == the number of arguments passed in on the command line
###	$0 == the name that we were called  (argv[0])
###	$1 == the dir
###	$2 == the reason

HOME=/gftp
PASSWD=${HOME}/etc/passwd
GCRED=gcredz
NUKELOG=/incoming/NukeLog

NUKEDIR=$1
REASON=$2

case $# in
	1|2)	;;
	*)	echo "Usage: $0 /incoming/somecrap [reason]"
		echo "*note:  reason is limited to one word."
		echo " "
		exit
		;;
esac

## Make sure the specified directory exists
if [ ! -d ${NUKEDIR} ]; then
	echo "The directory you specified doesn't exist, moron. "
	exit
fi

## Get the site of the specified directory
NUKEDIRSIZE=`du -s ${NUKEDIR}|awk '{print $1}'`

echo "The directory you are about to nuke is:  $NUKEDIR"
echo "The size of ${NUKEDIR} is: ${NUKEDIRSIZE}k"

## Find out who created the dir
NUKEUSER=`ls -ald ${NUKEDIR} | awk '{print $3}'`

## Delete the contents of the directory, and rename the directory
find ${NUKEDIR} -type f -exec rm {} \; 
case $? in
	0)	;;
	*)	echo "Errors removing da crap!"
		echo "Continuing with the xcred adjustment."
		;;
esac

## Adjust the Xcreds
echo "	*** LUser ${NUKEUSER} is now being penalized ${NUKEDIRSIZE}k "
${GCRED} ${NUKEUSER} -${NUKEDIRSIZE}k

## Rename the directory
mv ${NUKEDIR} [NUKED].${NUKEDIR}

## Update the Nuke log
echo "${NUKEUSER} ${NUKEDIR} ${REASON} -${NUKEDIRSIZE}k" | \
awk '{printf("%10s:%30s:%18s:%10s\n"),$1,$2,$3,$4}'\
>>${NUKELOG}
