. /etc/init.d/functions

## If called with wait we do not want to go to mainos
## Otherwise, transition to mainos in 15 seconds

#trap "" 2 

echo "$1" >>/nn/sbin/call.log
trap exit 1
rc=0
_wait=0
_timeout=10

case "$1" in
   "wait" )
   _wait=1
   ;;
   "short" )
   _timeout=10
   ;;
   "long" )
   _timeout=60
   ;;
esac



while [ $rc -eq 0 ]; do
   # the swap file should only exist if a selection has been made through the cli
   # terminate the cli and exit so we do not restart
   if [ -e /root/swap ]; then
      rc=1 #Should not matter
      /usr/bin/killall BCMCli
      exit 0
   fi
   i_pid=
   i_pid=`pidof BCMCli`
   if [ -z "$i_pid" ]; then
      if [ $_wait -eq 0 ]; then
         /usr/bin/clear
         echo "BCM450 Safe OS"
         /nn/sbin/BCMCli -t $_timeout -T /dev/ttyS1 & 
         #sleep 1
      else
         /usr/bin/clear
         /nn/sbin/BCMCli -T /dev/ttyS1
         #rc=1
         #sleep 1
      fi
   fi
done

exit 0

