#! /bin/sh
#
# Lane Machine update script
#

echo "Running update script"

# make sure the GUI does not restart while downloading files...
killall watchdog
sync

# Get rid of all translations - need new files to work properly
rm /opt/LM_GUI/scripts/languages/* 

# v0.21 no changes to machine data (since v0.15)
# Remove the state and machine data - changed internal values
#rm /opt/LM_GUI/data/data.machine.dat
#rm /opt/LM_GUI/data/data.state.dat

# New bitmap fonts (v0.15) remove old truetype fonts... (done in image now v0.19)
#rm /usr/X11R6/lib/X11/fonts/TTF/* 
#rm /usr/X11R6/lib/X11/fonts/Type1/* 

# Check kernel version to see if we need to upgrade
export KERNEL_VER=`uname -r`
echo ""
echo "kernel version = $KERNEL_VER"
if [ "$KERNEL_VER" = "2.6.11.11-arcom3" ]
	then
	echo "No kernel upgrade needed."
	echo ""
else
	echo "upgrading kernel..."
	echo ""
	cp ./kernel/zImage /boot/
	echo "upgrading kernel modules..."
	mkdir /lib/modules/2.6.11.11-arcom3
	mkdir /lib/modules/2.6.11.11-arcom3/kernel

	export USB_DIR=`pwd`
	cd /lib/modules/2.6.11.11-arcom3/kernel
	tar -xzvf $USB_DIR/kernel/modules.tar.gz
	cd $USB_DIR	

	# this is so depmod -a -q runs on reboot.
	cp ./kernel/modutils /etc/init.d/
	echo "kernel upgrade done..."
fi

# remove link to resolv.conf so ssh logins go faster
rm /etc/resolv.conf

# Update Lane Machine GUI files
cp ./scripts/*  /opt/LM_GUI/scripts/
cp ./pics/*     /opt/LM_GUI/pics/
cp ./data/*     /opt/LM_GUI/data/
cp ./scripts/languages/*  /opt/LM_GUI/scripts/languages

# Other items to update here (done in image now v0.19)
# Make shutdown faster (v0.24 / v1.0)
rm -f /etc/rc0.d/*umountnfs*
rm -f /etc/rc0.d/*networking*
rm -f /etc/rc0.d/*sendsigs*
rm -f /etc/rc0.d/*inetd*
rm -f /etc/rc0.d/*cron*
rm -f /etc/rc0.d/*thttpd*
rm -f /etc/rc0.d/*umountfs*

# Remove xterm startup (done in image now v0.19)
# Changed background color for X window (v0.22 - for trouble shooting)
cp ./setup/xinitrc /usr/X11R6/lib/X11/xinit
# Changed startup to act like the other scripts in /etc/init.d (v1.02)
cp ./setup/start_x /etc/init.d/

# Update watchdog stuff (added v0.23)
cp ./setup/start_gui /opt/LM_GUI/scripts/
cp ./setup/watchdog /opt/LM_GUI/
cp ./setup/usb-storage /etc/hotplug/usb/

# Update to latest fonts (no new fonts since v0.19)
# Problem loading Thai font - keep this line for now (v0.24 / v1.0) - support old GUIs
cp ./fonts/misc/* /usr/X11R6/lib/X11/fonts/misc

# Do this stuff last - may crash the tcl (wish) screen
cp ./drivers/*  /opt/LM_GUI/drivers/

# Remove old thread lib
#rm -f /opt/LM_GUI/lib/libthread2.4g.so

# Removed tcl, tk, BLT & thread libs (v0.24 / v1.0) from here haven't changed recently (since v0.16)
cp ./lib/*      /opt/LM_GUI/lib/

# Also copy init.tcl into the tcl8.4 dir.  Not sure why it's in there twice
cp /opt/LM_GUI/lib/init.tcl /opt/LM_GUI/lib/tcl8.4/

reboot
