#!/bin/bash

set -eu

source "./custom/defines.sh"

setman-restore "timedated-ntp" "timesyncd.conf" > "${TIMEDATED_CONFIG_DIR}/timesyncd.conf"
setman-restore "timedated-ntp" "settings.json" > "${DYNAMIC_CONFIG_DIR}/settings.json"

timeZone=$(cat ${DYNAMIC_CONFIG_DIR}/settings.json | jq -r '.datetime.TimeZone')
timedatectl set-timezone ${timeZone}

ntp=$(cat ${DYNAMIC_CONFIG_DIR}/settings.json | jq -r '.ntp.Enabled')
timedatectl set-ntp ${ntp}