#!/bin/sh

if [ "$1" = "" ]
then 
	echo "This command should not be run by the user, it is used exclusively to apply patches to the distributed folding client"
	exit 1
fi
 
PROTEIN_SIZE=`ls -s protein.trj 2> /dev/null | cut -d " " -f 1`
FNAME=$1
TESTFILE=file_id.diz

echo -e "\r\nNew version found; attempting to unpack patch file\r\n"

sleep 3

gzip -cd $FNAME |tar xf -

if [ -f $TESTFILE ]
then
# successful unpacking, so remove files and run again
	rm -f $FNAME
	rm -f $TESTFILE
	echo -e "Update was successful, restarting client\r\n"
	sleep 3
	exec ./foldit
else
	echo -e "Update was unsuccessful, please correct any problems, ensure the file `echo $1` is in the current directory and try again\r\n"
fi
