#!/bin/bash

. ${TOOLKIT}-functions.sh

#----------------------------------------------------------------
# build ntp time servers list, store them in ntp.conf file
#----------------------------------------------------------------
#
file=$(filepath ntp.conf) || exit $?
out="ntp.conf.tmp"
servers=$(jtconf service.time)
buf=

for entry in $(echo $servers | tr ',' ' ')
do
	if echo "$entry" | grep -q ':'
	then
		srv=$(echo $entry | cut -d':' -f1)
		opts=$(echo $entry | cut -d':' -f2)
	else
		srv="$entry"
		opts=
	fi
	buf="$buf\nserver $srv $opts"

	# the first one is preferred, then clear the var
	preferred=
done

sed -e "s/--ku-tag-to-insert-servers-ku--/$buf/" $file >$out || exit $?

exit 0
