#!/bin/sh

case "$0" in
*if-up.d*)
    ACTION=up
;;
*if-down.d*)
    ACTION=down
;;
*)
    exit 1
;;
esac

CONFIG=$1
shift

if [ -n "$1" -a "$1" != "-o" ]
then
    INTERFACE=$1
else
    INTERFACE=$CONFIG
fi

shift
[ "$1" = "-o" ] || exit 0
OPTIONS="$@"

[ "$INTERFACE" != lo ] || exit 0

case "$ACTION" in
up)
    if [ -x /usr/bin/logger ]
    then
        logger=/usr/bin/logger
    else
        logger=true
    fi

    /usr/bin/systemctl start epoptes-client-ethtool@$INTERFACE
    /usr/bin/systemctl start epoptes-client-fetch-certificate
    /usr/bin/systemctl start epoptes-client
    $logger -t epoptes -p syslog.info "Running epoptes-client, IFACE=$INTERFACE, pid=$$"
;;
down)
    /usr/bin/systemctl stop epoptes-client
;;
esac

exit 0

