#!/bin/sh
# vim: set ts=4 sw=4:
set -eu

# /etc/ntpd.conf: OpenNTPD, /etc/ntp.conf: ISC ntp
readonly CONF_FILES='/etc/ntpd.conf /etc/ntp.conf'

if [ -z "${NTP:-}" ]; then
	exit 0
fi

. "$(dirname "$(readlink -f "$0")")"/utils.sh

ntp_conf=$(echo "$NTP" \
	| tr -s ' \t' '\n\n' \
	| xargs -I% printf 'server %\n')

for file in $CONF_FILES; do
	if [ -e "$file" ]; then
		update_config "$file" "$(readlink -f "$0")" "$ntp_conf"
	fi
done
