#!/bin/bash
#---------------
# Testing quagga
#---------------
set -eu

DAEMONS=("bgpd" "isisd" "ospf6d" "ospfd" "pimd" "ripd" "ripngd")

# configure
for daemon in "${DAEMONS[@]}" zebra
do
    cp /usr/share/doc/quagga-core/examples/${daemon}.conf.sample \
      /etc/quagga/${daemon}.conf
done

# start (no zebra - it's brought up automaticall as a dependency)
for daemon in "${DAEMONS[@]}"
do
    systemctl start ${daemon}
done

# reload quagga by restarting zebra - dependent daemons will restart.
systemctl restart zebra

# wait for things to settle
sleep 5

# check daemons
for daemon in "${DAEMONS[@]}" zebra
do
    echo -n "check ${daemon}  -  "
    if systemctl -q is-active ${daemon}; then
        echo "${daemon} OK"
    else
        echo "ERROR: ${daemon} IS NOT RUNNING"
        exit 1
    fi
done