#
# sna [parameters as sna_commands ]
# 
# start/stop command for CS Linux.
#
# Essentially, parameters are passed unchanged to 
# the sna_commands executable. 
# However, the drivers must be loaded or sna_commands will
# fail to run. Hence, before running sna_commands
#  sna start - will attempt to start them
#  sna everything else - will check they are loaded.
# 
ALLPARMS=$*

# 
# Set path for message catalog file.  Set "C" to be the default.
NLSPATH=/opt/ibm/sna/lib/nls/msg/LC_MESSAGES/%N:/opt/ibm/sna/lib/nls/msg/%L/%N
export NLSPATH=${NLSPATH}:/opt/ibm/sna/lib/nls/msg/C/%N

#
# Set path for snareadinstcat binary
READINSTCAT=/opt/ibm/sna/bin/snareadinstcat

if [ x$1 = xstart ]
then
# 
# Start CS Linux
# ensure drivers are loaded
#
  /opt/ibm/sna/bin/snaldmod
  LOADRC=$?

  #
  # Some O/S file systems are bugged such that mknod sometimes fails. The
  # workaround to this is to simply retry a couple of times.
  #
  if [ x$LOADRC = x99 ]
  then 
    /opt/ibm/sna/bin/snaulmod
    /opt/ibm/sna/bin/snaldmod
    LOADRC=$?
    if [ x$LOADRC = x99 ]
    then
      /opt/ibm/sna/bin/snaulmod
      /opt/ibm/sna/bin/snaldmod
      LOADRC=$?
      if [ x$LOADRC = x99 ]
      then
        /opt/ibm/sna/bin/snaulmod
        /opt/ibm/sna/bin/snaldmod
        LOADRC=$?
      fi
    fi
  fi 
  if [ $LOADRC != 0 ]
  then
    # echo "CS Linux cannot start because drivers failed to load"
    # echo "Refer to the readme for further information"
    $READINSTCAT 5
    $READINSTCAT 47
    exit $LOADRC
  fi


else
#
# Other sna commands (e.g. stop, -getsense)
#
  cat /proc/modules | grep sna_linux > /dev/null 2>&1
  if [ $? = 1 ]
  then
    # echo "CS Linux not running"
    $READINSTCAT 6
    exit 10
  fi

fi

# start daemons
/opt/ibm/sna/bin/sna_commands $ALLPARMS
exit $?

