#!/bin/sh

export PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
UPDATE_TARBALL=update.tar.gz

echo "Update Script started"
pre_vers=`head -n 1 /etc/cabversion`

path=$PWD

rm -f /etc/dropbear/dropbear_dss_host_key
rm -f /etc/factory/scripts.d/boot.d/.gitignore
rm -f /etc/factory/scripts.d/dhcp-exit-hooks/.gitignore
rm -f /etc/init.d/S43ntp.sh
rm -f /etc/init.d/S44wlan.sh
rm -f /etc/pic/PIC_AnyRover_NG_v3.hex
rm -f /sbin/udhcpc
rm -f /usr/bin/install.sh
rm -f /usr/etc/dhcpcd.enter-hook
rm -f /usr/etc/dhcpcd.exit-hook
rm -f /usr/lib/liblc.a
rm -f /usr/lib/libopenconnect.la
rm -f /usr/lib/pkgconfig/libcurl.pc
rm -f /usr/lib/pkgconfig/libiptc.pc
rm -f /usr/lib/pkgconfig/libnetfilter_conntrack.pc
rm -f /usr/lib/pkgconfig/libnetfilter_log.pc
rm -f /usr/lib/pkgconfig/libnfnetlink.pc
rm -f /usr/lib/pkgconfig/libnl-1.pc
rm -f /usr/lib/pkgconfig/xtables.pc
#<REMOVE>
cd /
tar xzf ${path}/${UPDATE_TARBALL}

file=$(ls -1 /root/uImage* | head -n 1)
if [ -r "${file}" ]; then
	echo -n "Updating kernel ... "
	dd if=${file} of=/dev/mtdblock2
	echo "done"
fi

cd ${path}

echo "Update finished."

post_vers=`head -n 1 /etc/cabversion`
echo "Updated from ${pre_vers} to ${post_vers}"

echo "The config file /etc/cablynx.conf was untouched."
echo "Please use the new config file in /etc/cablynx.conf.${post_vers#*: }"

