#! /bin/sh
#
# bird         Starts the Internet Routing Daemon.
#
# Author:      Ondrej Feela Filip, <feela@network.cz>
#
# chkconfig: - 32 75
# description: Internet routing daemon supporting IPv4 routing protocols:
#              BGP4, RIPv2 and OSPFv2.
#
# processname: bird
# config: /etc/bird.conf


# Source function library.
. /etc/rc.d/init.d/functions

[ -f /etc/sysconfig/network ] || exit 0

. /etc/sysconfig/network

BIRD4="yes"
BIRD6="yes"


[ -f /etc/bird.conf ] || BIRD4="no"
[ -f /usr/sbin/bird ] || BIRD4="no"
[ "${NETWORKING}" = "yes" ] || BIRD4="no"

[ -f /etc/bird6.conf ] || BIRD6="no"
[ -f /usr/sbin/bird6 ] || BIRD6="no"
[ "${NETWORKING_IPV6}" = "yes" ] || BIRD6="no"

[ -e /etc/sysconfig/bird ] && . /etc/sysconfig/bird

RETVAL=0


_start(){
    echo -n "Starting $1"
    daemon $1 
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$1
}

_stop(){
    echo -n "Stopping $1"
    killproc $1
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$1
}

_status() {
    status $1
    RETVAL=$?
}

_reload(){
    status $1 >/dev/null
    if [ $? -eq 0 ]; then
        echo -n "Reloading $1 "
            killproc $1 -HUP
            RETVAL=$?
            echo
    else
        echo "$1 was not running, starting"
        _start $1
    fi
}



# See how we were called.
case "$1" in
  start)
    if [ "$BIRD4" = "yes" ];then
        _start bird
        fi
    if [ "$BIRD6" = "yes" ];then
        _start bird6
    fi
    echo
    ;;
  stop)
    if [ "$BIRD4" = "yes" ];then
        _stop bird
    fi
    if [ "$BIRD6" = "yes" ];then
        _stop bird6
    fi
    echo
    ;;
  status)
    if [ "$BIRD4" = "yes" ];then
        _status bird
    fi
    if [ "$BIRD6" = "yes" ];then
        _status bird6
    fi
    echo
    ;;
  restart)
    $0 stop
    $0 start
    RETVAL=$?
    ;;
  reload)
    if [ "$BIRD4" = "yes" ];then
        _reload bird
    fi
    if [ "$BIRD6" = "yes" ];then
        _reload bird6
    fi
    ;;
  *)
    echo "Usage: bird.init {start|stop|status|restart|reload}"
    exit 1
esac

exit $RETVAL
