Files
RelayDock/relaydock-reconcile.sh
T
2026-05-21 23:14:36 +02:00

24 lines
827 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
CONFIG_FILE="${1:-/etc/relaydock/config.json}"
PREFIX="${RELAYDOCK_PREFIX:-relaydock}"
command -v jq >/dev/null 2>&1 || { echo "Fehlt: jq" >&2; exit 1; }
[[ -f "$CONFIG_FILE" ]] || { echo "Config fehlt: $CONFIG_FILE" >&2; exit 1; }
mapfile -t desired < <(jq -r '.rules[].name' "$CONFIG_FILE" | sort -u)
mapfile -t current < <(systemctl list-units --full --all "${PREFIX}@*.service" --no-legend | awk '{print $1}' | sed -E "s/^${PREFIX}@(.*)\\.service$/\\1/" | sort -u)
for name in "${desired[@]}"; do
systemctl enable --now "${PREFIX}@${name}.service"
done
for name in "${current[@]}"; do
if ! printf '%s\n' "${desired[@]}" | grep -qx "$name"; then
systemctl disable --now "${PREFIX}@${name}.service" || true
else
systemctl restart "${PREFIX}@${name}.service"
fi
done