#! /bin/sh
# Restart htpdate when NetworkManager brings an interface up.
# Native dispatcher script. Thanks to the htpdate ifup script, the
# base for this one.

set -e

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

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

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

# Interface up only
if [ "$2" != up ]; 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
