#!/usr/bin/env bash
# backup-node/apply — install restic + jq on a backup source/storage server.
# restic >= 0.17 is required: backup-run relies on exit code 10 for "repository does not exist".
# outputs: restic (version)
set -euo pipefail
cat >/dev/null
DEBIAN_FRONTEND=noninteractive apt-get update -qq >&2
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends restic jq >&2
v=$(restic version | awk '{print $2}')
if ! [[ "$v" =~ ^([0-9]+)\.([0-9]+) ]]; then echo "ERROR: cannot parse restic version '$v'" >&2; exit 1; fi
if [ "${BASH_REMATCH[1]}" -eq 0 ] && [ "${BASH_REMATCH[2]}" -lt 17 ]; then
  echo "ERROR: restic $v too old (need >= 0.17)" >&2; exit 1
fi
jq -n --arg v "$v" '{restic:$v}' > "$SSR_OUTPUTS"
