#!/bin/sh 
#
#
#

KEEP="/dev/log
"


if [ Q$1 == "Q" -o Q$2 == "Q" ]
then
	echo "Usage: upratejail <config.file> <jail identifier>"
else

	JAIL=`cat $1 | grep Root: | grep $2 | awk '{print $2}'`
	echo "jail: " $JAIL
	echo "config: " $1
	read

	
	if test -d $JAIL
	then
		cd $JAIL
                tmpfile=`tempfile` || { echo "$0: Cannot create temporary file" >&2; exit 1;  }
                tmpfile2=`tempfile` || { echo "$0: Cannot create temporary file" >&2; exit 1;  }
                trap " /bin/rm -f -- \"$tmpfile\" \"$tmpfile2\"" 0 1 2 3 13 15

		find $JAIL -type b > $tmpfile
		find $JAIL -type c >> $tmpfile
		find $JAIL -type p >> $tmpfile
		find $JAIL -type f >> $tmpfile
		find $JAIL -type l >> $tmpfile
		find $JAIL -type s >> $tmpfile
		for i in `echo $KEEP`
		do
			cat $tmpfile | grep -v $JAIL$i > $tmpfile2
			mv $tmpfile2 $tmpfile
		done
		for i in `cat $tmpfile`
		do
			rm $i
		done
                cat $tmpfile | xargs -r rm
		/usr/sbin/jailer $1 $2
	else
		echo "This jail does not exist!"
	fi
fi
