#!/bin/sh 
#
#
#

KEEP="/dev/log
"



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

        if [ ! -r "$1" ] ; then
            echo "Cannot read config file $1"
            exit 1
        fi
	JAIL=`cat $1 | grep Root: | grep "$2$" | awk '{print $2}'`
	echo "jail: " $JAIL
	echo "config: " $1

        if [ -z "$JAIL" ] ; then
                echo "Could not determine root location for $2"
                exit 1
        fi

        echo "Press any key to continue...."
	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
		/usr/sbin/jailer $1 $2
	else
		echo "This jail does not exist!"
	fi
fi

exit 0
