#!/bin/sh -u

PATH="$PATH:/sbin"

. shell-config
. shell-error
. alterator-sh-functions
. alterator-datetime-functions

DATADIR="$1"; shift

[ -n "$DATADIR" -a -f "$DATADIR"/timesync_data ] || \
	fatal "Couldn't find data file in $DATADIR"

ntp_pool="$(shell_config_get "$DATADIR"/timesync_data timesync_ntp_pool)"
status="$(shell_config_get "$DATADIR"/timesync_data timesync_status)"

write_pool "$ntp_pool"
write_ntp_status "$status"

# Check

[ "$(read_pool)" = "$ntp_pool" ] || exit 1
if test_bool "$status"; then
	test_ntp_status || exit 1
elif test_ntp_status; then
	exit 1
fi

exit 0
