#! /bin/sh
# Restart htpdate when an interface comes up.
# Based on Debian SSH ifup script. Thanks!

set -e

# Is active the ifup procedure?
. /etc/default/htpdate || exit 0

if [ "$HTP_IFUP" = "no" ]; then
    exit 0
fi

# Ignore loopback
if [ "$IFACE" = lo ]; then
        exit 0
fi

# ifup only...
if [ "$MODE" != start ]; then
        exit 0
fi

# restart
if   [ -d /run/systemd/system ]; then
        systemctl restart --no-block htpdate >/dev/null 2>&1 || true
elif [ -x /usr/sbin/invoke-rc.d ]; then
        invoke-rc.d htpdate restart >/dev/null 2>&1 || true
else
        /etc/init.d/htpdate restart >/dev/null 2>&1 || true
fi

exit 0
