#!/usr/bin/env bash
set -u

# Put this script and cron-canary.mode inside the active HERMES_HOME/scripts/.
# Allowed mode-file contents: silent, alert, fail. Missing means silent.
script_dir="$(cd "$(dirname "$0")" && pwd)"
mode_file="$script_dir/cron-canary.mode"
mode="silent"

if [[ -f "$mode_file" ]]; then
  IFS= read -r mode < "$mode_file"
fi

case "$mode" in
  silent)
    exit 0
    ;;
  alert)
    printf '%s\n' 'CRON-WATCHDOG-732'
    ;;
  fail)
    printf '%s\n' 'CRON-WATCHDOG-732 deliberate failure' >&2
    exit 23
    ;;
  *)
    printf '%s\n' 'cron-canary.mode must be silent, alert, or fail' >&2
    exit 64
    ;;
esac
