#!/bin/sh
echo "**********************************"
echo "*******    Update run...	******** "
echo "**********************************"

gpio dirout 80
gpio dirout 81
gpio dirin 82


cd /home/CAPELEC/DATA/update/dirtmp/
killall 1830
cp 1830 /usr/bin/

if [ $? = 0 ]; then
	echo "update OK"	
	echo "export VERSION=V1.07" > /etc/info
	echo "export DATE=01/06/2015" >> /etc/info
	echo "export INFORMATION=" >> /etc/info

gpio clear 80
rm -R /var/www

cp -R init.d /etc

sleep 1

gpio set 80

cp -rf wwwspx /var/www
sleep 1
gpio clear 80
sleep 1

sed "s/TECNO1/SPX1/" /etc/ip_config > /etc/ip_config_tmp
cp /etc/ip_config_tmp /etc/ip_config

rm /etc/ip_config_tmp

sed "s/TECNO/SPX/" /home/CAPELEC/DATA/PARAM.txt > /home/CAPELEC/DATA/PARAM_tmp.txt
cp /home/CAPELEC/DATA/PARAM_tmp.txt /home/CAPELEC/DATA/PARAM.txt

rm /home/CAPELEC/DATA/PARAM_tmp.txt

gpio set 80

cp -R zoneinfo /etc

sleep 1

gpio clear 80

chmod 777 -R /etc/zoneinfo

sleep 1

gpio set 80

cp DAEMONMAJ.sh /usr/bin
cp maj.sh /usr/bin

sleep 1
gpio clear 80

cp lan.sh /usr/bin
cp fonction.sh /usr/bin
cp testNetwork.sh /usr/bin
cp test_nmblook /usr/bin
cp majdist.sh /usr/bin
cp BP82.sh /usr/bin
cp ip_machine.template /etc

echo "fin de la MAJ!!!!!!!!!!!!!!!"
echo "reboot"


else
	echo "update NOK!!!!"	
	VERSION=`cat /etc/info | grep VERSION`
	DATE=`cat /etc/info | grep DATE`
	
	echo "$VERSION" > /etc/info
	echo "$DATE" >> /etc/info
	echo "export INFORMATION=Update Error" >> /etc/info
fi			

reboot


