#!/usr/bin/env bash

[ -n "$CONNECTION_UUID" ] || exit 0

INTERFACE=$1
ACTION=$2
NTP_SERVERS=$DHCP4_NTP_SERVERS

case $ACTION in
    up)
        if [ -n "$NTP_SERVERS" ]; then
    	    mkdir -p /etc/systemd/timesyncd.conf.d
	    exec > /etc/systemd/timesyncd.conf.d/$CONNECTION_UUID.conf
	    echo "[Time]"
    	    echo "NTP=$NTP_SERVERS"
    	    systemctl is-enabled systemd-timesyncd >/dev/null && systemctl restart systemd-timesyncd
        fi
    ;;
    down)
        rm -f /etc/systemd/timesyncd.conf.d/$CONNECTION_UUID.conf
        systemctl is-enabled systemd-timesyncd >/dev/null && systemctl restart systemd-timesyncd
    ;;
esac

exit 0