#!/bin/bash
#
# chkconfig: 2345 25 90
#
# description: Shoreline Firewall (6) is a high-level tool for configuring Netfilter.

# Source function library
if [ -f /etc/init.d/functions ]; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# Detect our basename
TMP_NAME=$0
TMP_PWD=$PWD
while [ -L $TMP_NAME ]; do
  if [ ${TMP_NAME/\/} != $TMP_NAME ]; then
    cd ${TMP_NAME%/*}
  fi
  TMP_NAME=$(readlink ${TMP_NAME##*/})
done
cd $TMP_PWD
declare -r BASENAME=${TMP_NAME##*/}
unset TMP_NAME
unset TMP_PWD

start() {
  echo -n $"Starting ${BASENAME}: "
  daemon $BASENAME start > /dev/null
  RETVAL=$?
  [ $RETVAL -eq 0 ] && echo_success || echo_failure
  echo
  return $RETVAL
}

stop() {
  echo -n $"Shutting down ${BASENAME}: "
  daemon $BASENAME stop > /dev/null
  RETVAL=$?
  [ $RETVAL -eq 0 ] && echo_success || echo_failure
  echo
  return $RETVAL
}

restart() {
  echo -n $"Restarting ${BASENAME}: "
  daemon $BASENAME restart > /dev/null
  RETVAL=$?
  [ $RETVAL -eq 0 ] && echo_success || echo_failure
  echo
  return $RETVAL
}

clear() {
  echo -n $"Clearing ${BASENAME}: "
  daemon $BASENAME clear > /dev/null
  RETVAL=$?
  [ $RETVAL -eq 0 ] && echo_success || echo_failure
  echo
  return $RETVAL
}

condrestart() {
  [ -e /var/lock/subsys/${BASENAME} ] && restart || :
}

svcstatus() {
  $BASENAME status
  RETVAL=$?
}

RETVAL=0

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  reload)
    restart
    ;;
  clear)
    clear
    ;;
  condrestart)
    condrestart
    ;;
  status)
    svcstatus
    ;;
  *)
    echo $"Usage: $BASENAME {start|stop|restart|reload|clear|condrestart|status}"
    RETVAL=1
esac

exit $RETVAL
