#!/bin/sh
#################################################
# Version: 1.08 (07.12.2007)
# Device:  DR5000/DU7xx/DR2800/DR3800/DR2800eco/DR2700/LICO
# Author:  Johannes Berssen / Andre Naggies
# Author:  Ralf Bressel / Thomas Hoehenleitner
# Author:  Max Schreiber
#################################################



# Linux kernel 2.4
###################
if [ -e /usr/local/prg/Sportmap ] ; then
    
    # Mount egllinux server (for development only)
    # /usr/local/prg/Snetwork start
    # /usr/local/prg/Sportmap start
    # mount egllinux:/home /home

    # Display needs to be inverted for Corona Mobile DR2800
    if [ -e /usr/local/prg/usbcorona.o ] ; then
	if [ ! -e /usr/local/prg/pal_num ] ; then
	    /usr/local/prg/invert.o
	fi
    fi

    # Mount of usbfs done in fstab for linux krnl 2.6
    mount -t usbdevfs none /proc/bus/usb

    # Create mount directories for USB stick
    mkdir /media
    mkdir /media/stick

    # Give slow USB devices time to initialize
    sleep 2
    
    # Look for root_upd.sh on USB stick to allow an update
    for x in /dev/sda1 /dev/sda; do
        if mount -t vfat $x /media/stick ; then
	    echo -e "USB stick (device: $x) found\n\r"
	    if [ -x /media/stick/root_upd.sh ]; then
		echo -e "script for update found\n\r"
 		. /media/stick/root_upd.sh
	    fi
	    umount /media/stick
        fi
    done

# Linux kernel 2.6
###################
else
    # Mount egllinux server (for development only)
    # mount 192.168.200.99:/home /home 
    
    # Insert HACH Data Trans device driver module
    if [ -e /usr/local/prg/usbcorona.o ] ; then
	insmod /usr/local/prg/usbcorona.o
    fi
    if [ -e /usr/local/prg/usbn9603.o ] ; then
	if [ -e /usr/local/prg/modules ] ; then
	    /usr/local/prg/modules
	fi
    fi
fi

#
# Ein evt. vorhandenes *.gz - file muss ausgepackt werden.
# Ab Kernel 06 (/proc/version #33) (gzip kein Link mehr) kann geprueft werden ob das gz - file ok ist,
# dann muss aber zum echten auspacken das Anwenderprogramm geloescht werden.
#
for x in dr2800 ghl dr3800 du730 du720 dr2700 dr2800eco lcp5 lcp150 ctp atp gtp; do
    if [ -e /usr/local/prg/$x.gz ]; then
	echo -e "$x.gz found\n\r"
	if [ -e /usr/local/prg/$x ]; then
	   echo -e "$x found\n\r"
	   
           # busybox gzip can not perform -t, so we skip that if we have busybox gzip, what is a link.
	   # Newer initrd's have a full featured gzip, so we can check in advance.
	   
           if [ ! -L /bin/gzip ]; then                   # we have a full featured gzip (no link)
	      if gzip -t /usr/local/prg/$x.gz ; then     # we have no error
	         if rm /usr/local/prg/$x ; then          # delete application
	            echo "rm $x success"
	         fi
	      fi
	   fi
	fi
	if gzip -d /usr/local/prg/$x.gz ; then
	   echo -e "gzip $x.gz success\n\r"
	else 
           echo -e "$x.gz broken \n\r"
	fi
    fi
done

#
# Start application
#
for x in dr2800 ghl dr3800 du730 du720 dr2700 dr2800eco lcp5 lcp150 ctp atp gtp; do
    if [ -x /usr/local/prg/$x ]; then
 	/usr/local/prg/$x
    fi
done

exit 0

