#!/bin/sh
# The following code detects if something is connected to USB port 0,
# and if so checks for a flash drive with /tsinit to execute.

. /ts7000.subr
usb_init
TMP=`usb_port_devexists 0`
if test "$TMP" = "1"; then
  led1 1

  TMP=0
  while test $TMP -lt 20 -a -e /mnt/root/notrootfs; do
    TMP=$((TMP+1))
    sleep 1
  done
  if [ ! -e /mnt/root/notrootfs ]; then
    modprobe ohci-hcd
    modprobe sd_mod
    modprobe usb-storage
    modprobe vfat
    modprobe ext3
  fi

  TMP=0
  while test $TMP -lt 15 -a ! -b /dev/sda1; do 
    let TMP=$TMP+1;
    mdev -s 
    sleep 1; 
  done
  if test -b /dev/sda1; then
    umount /mnt/root
    mount -o ro /dev/sda1 /mnt/root
    if test -x /mnt/root/tsinit; then
      /mnt/root/tsinit < $CONSOLE > $CONSOLE 2>&1
    fi
    umount /mnt/root
  fi
  led1 0
else
  usb_off
fi
