#!/bin/sh
#
# Commands to send to chronyd when the link goes online and
# offline respectively.
#

Online()
{
  test -e @PREFIX@/var/run/chrony/chronyd.online && exit 0
  @PREFIX@/bin/chronyc << EOF
online
burst 5/10
EOF
  err=$?
  if [ $err -ne 0 ]; then
    logger -is -p user.err -t chrony-netchange "Error switching chronyd on."
    exit $err
  fi
  touch @PREFIX@/var/run/chrony/chronyd.online
}

Offline()
{
  test -e @PREFIX@/var/run/chrony/chronyd.online || exit 0
  @PREFIX@/bin/chronyc -m offline dump
  err=$?
  if [ $err -ne 0 ]; then
    logger -is -p user.err -t chrony-netchange "Error switching chronyd off."
    exit $err
  fi
  rm -f @PREFIX@/var/run/chrony/chronyd.online
}

Run()
{
case $1 in
  online ) Online ;;
  offline) Offline;;
  *      ) echo "$0: unknown argument: $1"; exit 1;;
esac
}

Run $1
exit 0
