#!/bin/sh

# If there is a USB drive, mount it and execute 'tsinit'
# (this allows software auto-update)

TMP=0
while [ $TMP -lt 300 -a -e /mnt/root/notrootfs ]; do
  TMP=$((TMP+1))
  usleep 100000
done
if [ ! -e /mnt/root/notrootfs ]; then
  (
  sleep 1
  modprobe scsi_mod
  modprobe sd_mod
  modprobe usbcore
  modprobe ehci_hcd
  modprobe usb_storage
  modprobe vfat
  x=0
  while [ "$x" -lt 100 -a ! -e /sys/block/sda ]; do
    x=$((x+1))
    usleep 100000
  done
  if [ -e /sys/block/sda ]; then
    . /ts.subr
    led1 1
    mount -o ro /dev/sda1 /mnt/usbdev
    if [ -x /mnt/usbdev/tsinit ]; then
      /mnt/usbdev/tsinit <$CONSOLE >$CONSOLE 2>&1
    fi
    umount /mnt/usbdev
    led1 0
  fi
  ) >/dev/null 2>&1 </dev/null &
fi

