#!/bin/bash

set -eEuo pipefail

ntp_backend="$(ngcpcfg get ntp.backend)"

if [[ "${ntp_backend}" == 'ntpd' ]]; then
  # shellcheck disable=SC2086
  chroot /ngcp-fallback ${APT_CMD} ${APT_OPTS} install \
    --no-install-recommends ntpsec systemd-timesyncd-
  echo "Removing broken systemd service symlink, if any..."
  # shellcheck disable=SC2038
  chroot /ngcp-fallback find -L /etc/systemd/system -type l \
    | chroot /ngcp-fallback xargs -r rm
fi
