#!/bin/sh
#
# /scripts/install
#
# (C)opyright Tecomat a.s.
#
# 2013/07/15 Hosek Martin <hosek@tecomat.cz>
#

INSTALL_DIR="/"
CONTENT_DIR="content"
PRIVATE_DIR="private"

NET_CONFIG="/etc/network/interfaces"

### Show update splash image (Lock screen)

if [ "$DISPLAY" = "" ]; then
    export DISPLAY=:0
fi

xli -fullscreen $PRIVATE_DIR/id-update.jpg >/dev/null 2&>1 &

sleep 2

### Update Linux Kernel

VERSION_LINKE=`cat /proc/version | grep "TECO" | awk {'print $3'}`

if [ `expr $VERSION_LINKE \< 2.0` == 1 ]; then
    /sbin/insmod $PRIVATE_DIR/mtd_rw.o minor=3 flag=0

    cat $PRIVATE_DIR/uImage-MP1x-IDx8-20.bin >/dev/mtdblock3

    if [ $? == 1 ]; then
	exit 1
    fi
fi

### Update Root filesystem

rm -f /home
rm -f /mnt
rm -f /root
rm -f /var

rm -f /etc/adjtime
rm -f /etc/hostname
rm -f /etc/motd
rm -f /etc/resolv.conf
rm -f /etc/network/run
rm -f /etc/rc6.d/S25bootsplash-00

rm -f /usr/sbin/fbset

if [ -f /opt/MiniBrowser/MiniBrowser.ini ]; then
    rm -f $CONTENT_DIR/opt/MiniBrowser/MiniBrowser.ini
    cp -a /opt/MiniBrowser/MiniBrowser.ini $CONTENT_DIR/opt/MiniBrowser/MiniBrowser.ini
fi

if [ -f /opt/PLCComS/PLCComS.ini ]; then
    rm -f $CONTENT_DIR/opt/PLCComS/PLCComS.ini
    cp -a /opt/PLCComS/PLCComS.ini $CONTENT_DIR/opt/PLCComS/PLCComS.ini
fi

rm -rf /opt/MiniBrowser
rm -rf /opt/PLCComS

cp -af $CONTENT_DIR/* $INSTALL_DIR/

ret=$?

/sbin/depmod -a

TMP_CONFIG=`cat $NET_CONFIG | sed s/" (broadcast a gateway jsou voliteln)"/""/`

echo "$TMP_CONFIG" > $NET_CONFIG

sync

/sbin/reboot

exit $ret
