#! /bin/bash
# Provided by Charles S Schuman ( k4gbb1@gmail.com )
# 03/09/15
### BEGIN INIT INFO
# Provides: ax25
# Required-Start: $syslog $network
# Required-Stop:  $syslog $network
# Default-Start: S
# Default-Stop: 0 1 6
# Short-Description: Ax.25 initialization
# Description: This script provides the control for the ax.25 Packet Radio Service.
#	       The fine tuning is accomplished via /etc/ax25/ax25-up and /etc/ax25/ax25-down.
#
### END INIT INFO

# Using the lsb functions to perform the operations.
. /lib/lsb/init-functions

NAME=Ax25			# Process name ( For display )
DAEMON=/usr/local/etc/ax25/ax25-up
PIDFILE=/var/run/ax25.pid 	# pid file for the daemon

test -x $DAEMON || exit 5
case "$1" in
  start )
  # Check the status of ax25
  if [ -d /proc/sys/net/ax25/ax0 ]; then
      echo -e " \t $NAME: is already running."
      netstat|grep LISTENING
      exit 1
  fi
      echo  "        ** $NAME $1 **"
    /etc/ax25/ax25-up
    ;;

    stop )
     echo  "        ** $NAME $1 **"
    /etc/ax25/ax25-down
    ;;

   restart )
     echo  "        ** $NAME $1 **"
    /etc/ax25/ax25-down
    sleep 1
    /etc/ax25/ax25-up
    ;;

  status )
     echo -e "\t ** $NAME $1 **"
    if [ ! -d /proc/sys/net/ax25/ax0 ] ; then
      echo "$NAME is down"
    else
        if [ -z "$(uname -r | grep kjd)" ] ;then
          netstat --ax25
#           netstat|grep LISTENING
        else
          /sbin/ifconfig ipax0
          cat /proc/net/ax25
        fi
    fi
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0
