#!/bin/sh
#SYSTEMS: Solaris, Linux
# This script checks that routed is being started in quiet mode (-q)
MSG="# Checking for routed..."
SYSTEM=`uname -s`
######Solaris######
if [ "$SYSTEM" = "SunOS" ]; then
  echo ""; echo "$MSG"
  #Check inet startup script 
  if [ -f "/etc/rc2.d/S69inet" ]; then
    CHK=`grep "/usr/sbin/in.routed" /etc/rc2.d/S69inet`
    CHQ=`grep "/usr/sbin/in.routed -q" /etc/rc2.d/S69inet`
    if [ "$CHK" != "" ]; then
      if [ "$CHQ" = "" ]; then
        echo "--WARN-- [ROUTED001w] in.routed is started by /etc/rc2.d/S69inet but NOT in quiet mode."
      fi
    fi
  fi
  #Check the process table
  PS=`ps -ef | grep "in.routed" | grep -v grep`
  PQ=`ps -ef | grep "in.routed -q" | grep -v grep`
  if [ "$PS" != "" ]; then 
    if [ "$PQ" = "" ]; then
      echo "--WARN-- [ROUTED002w] in.routed is currently running but NOT in quiet mode."
    fi
  fi
fi
######Linux######
if [ "$SYSTEM" = "Linux" ]; then
  echo ""; echo "$MSG"
  CHK=`ls /etc/rc.d/rc*.d/S*routed 2>/dev/null | tr "[\n]" " "`
  if [ "$CHK" != "" ]; then
    echo "--WARN-- [ROUTED003w] The following 'routed' service startup script(s) were found: $CHK"
  fi
  #Check the process table
  PS=`ps -ef | grep "routed" | grep -v grep`
  PQ=`ps -ef | grep "routed -q" | grep -v grep
`
  if [ "$PS" != "" ]; then 
    if [ "$PQ" = "" ]; then
      echo "--WARN-- [ROUTED002w] in.routed is currently running and NOT in quiet mode."
    fi
  fi
fi
