#!/bin/sh 
#
# this is called by checkArduino to test and set drive configuration to proper state
# config file has entries:
#    command pattern action action2
# on boot the $command is piped to grep on $pattern 
# if not found, $action and $action2 are taken
#
cfg=$1
dno=$2
if [[ -f $cfg ]]; then
  echo "checkAsserts dev=$dno cfg=$cfg"
  while read line
  do
    cmd=`echo $line | awk '{print $1}'`
    if [ "$cmd" = "#" ]; then continue ; fi
    pat=`echo $line | awk '{print $2}'`
    act=`echo $line | awk '{print $3}'`
    act2=`echo $line | awk '{print $4}'`
    echo "checkAssert cmd=($cmd) pat=($pat) act=($act) act2=($act2)"
    if [ "`$cmd | grep -i $pat`" = "" ]; then
      if [ "$cmd" = "ipmice" ]; then ipmice $act ; fi
      if [ "$act" = "REBOOT" ]; then touch /tmp/iceos.REBOOT ; fi
      if [ "$act2" = "REBOOT" ]; then touch /tmp/iceos.REBOOT ; fi
    fi
  done < "$cfg"
fi
