#!/bin/sh -e
# Copyright (c) 2007-2014 Axis Communications AB

RUNDIR=/run/ntp
NC=$RUNDIR/ntpd.conf
PID=$RUNDIR/ntpd.pid
ARG_FILE=$RUNDIR/ntpd.cmd_arg

. /lib/rcscripts/sh/error.sh

sf=/usr/local/sbin/ntp-tools
[ ! -r $sf ] || . $sf || error "Source '$sf' failed"

mkdir -p $RUNDIR || error "Failed to create directories $RUNDIR"
# Get list of ntp servers and print it to $NC
get_ntp_servers servers
printf "%s" "$servers">$NC || error "Failed to write configuration to '$NC'"
# Create argument string and write it to $ARG_FILE
echo "NTP_ARG=\"-s -p $PID -f $NC\"" > $ARG_FILE || error "Failed to write argument to '$ARG_FILE'"
