#!/bin/sh
PROGS="pmonit respawnd vftpd smartrescue boa sslwrap remotizzatore smistatore smartdiscover"
IMAGE="/tmp/SLANG_UPGRADE.pkg"

if [ ! -e $IMAGE ]; then

        echo "Image firmware not present"
        exit 1

fi

mv $IMAGE /tmp/SLANG_UPGRADE.tar.gz
IMAGE="/tmp/SLANG_UPGRADE.tar.gz"

sleep 2

# Sending SIGKILL to progs
echo -n "Sending SIGKILL to all runnning process"
for i in $PROGS;
do
        echo -n "."
        kill -9 `pidof $i`
done;
echo "DONE"

sleep 2

RES=0
for i in seq 1 3; do
	/etc/init.d/S87vftpd restart
	/usr/bin/pgrep vftpd
	if [ $? -ne 0 ]
	then
		# continue
		sleep 1
	else
		RES=1
        	break
	fi
done

if [ $RES -eq 0 ]; then
	/sbin/reboot	
fi

gunzip $IMAGE && tar -vxf /tmp/SLANG_UPGRADE.tar -C /


/upgrade.sh

rm -fr /tmp/SLANG_UPGRADE.tar
rm -fr /upgrade.sh

touch /tmp/SLANG_UPGRADE_done



