Files
challenge_status_tracker/install-timer.sh
T

38 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env sh
# Install the 30-minute HedgeDoc refresh as systemd *user* units.
# Run it as the user that owns ctf_status.env, on the machine that should do the
# polling. Re-running it is safe; it just overwrites the units.
set -eu
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
units="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
[ -x "$dir/ctf_status.py" ] || { echo "no executable ctf_status.py in $dir" >&2; exit 1; }
[ -f "$dir/ctf_status.env" ] || {
echo "no $dir/ctf_status.env — copy ctf_status.env.example to it first" >&2; exit 1; }
grep -q '^HEDGEDOC_NOTE=..*' "$dir/ctf_status.env" || {
echo "set HEDGEDOC_NOTE=<note url> in $dir/ctf_status.env first" >&2; exit 1; }
grep -q '^CHALLS_REPO_URL=..*' "$dir/ctf_status.env" || {
echo "set CHALLS_REPO_URL=<deployment repo url> in $dir/ctf_status.env first" >&2; exit 1; }
chmod 600 "$dir/ctf_status.env"
mkdir -p "$units"
for u in ctf-status.service ctf-status.timer; do
sed "s|__DIR__|$dir|g" "$dir/$u" > "$units/$u"
echo "installed $units/$u"
done
systemctl --user daemon-reload
systemctl --user enable --now ctf-status.timer
# without lingering, user units are torn down as soon as you log out
if ! loginctl show-user "$(id -un)" -p Linger --value 2>/dev/null | grep -qx yes; then
loginctl enable-linger "$(id -un)" 2>/dev/null \
|| echo "could not enable linger; run: sudo loginctl enable-linger $(id -un)" >&2
fi
echo
echo "one run now, to prove it works:"
systemctl --user start ctf-status.service && echo " ok"
systemctl --user list-timers ctf-status.timer --no-pager