#! /bin/sh
cd /kirac/downloads
rm *.zip

#copy fstab
mv fstab /etc

#copy init.d scripts
mv rcS /etc/init.d
mv S*.sh /etc/init.d

#copy ppp sctipt
mv pppd_script /etc/ppp/peers

#copy curl
mv curl /usr/bin

#mount mmc-boot vfat partition
mkdir -p /media/mmc-boot
mount /dev/mmcblk0p1 /media/mmc-boot

#remove old appmond
rm /usr/bin/appmond

#kill all running apps
pkill appmon
pkill webservice-send
pkill modbus-read
pkill check-update

sleep 1

#copy apps
mv appmond /kirac/app/
mv check-update /kirac/app/
mv modbus-read /kirac/app/
mv webservice-send /kirac/app/
mv register_test /kirac/app

#copy system binaries
mv arm-php-cgi /bin

#copy usr/bin scripts
mv run-update /usr/bin
mv run-read /usr/bin
mv run-send /usr/bin
mv start-appmond /usr/bin
mv start-pppd /usr/bin

#copy  libsungateway.so
mv libsungateway.so /lib

#copy other libs
mv lib*.so* /usr/lib
mv lib*.so.* /usr/lib

#copy api
mv *_api /kirac/api

#copy drivers
mv *.ko /kirac/drv

#copy www files
mv *.php /var/www
mv *.htm /var/www
mv *.js /var/www

#update db if needed
/kirac/downloads/update-db.sh

#copy version
mv version_sys.txt /kirac
mv version_hw.txt /kirac

#clean up junk files
rm -rf /kirac/downloads/*
rm -rf /var/www/zkr_update_file.zip
rm -rf /var/www/zkr_update_file.sha

sync
sleep 1
reboot -f


