#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")/.." unraid_host="${UNRAID_SSH_HOST:-unraid-itworx}" remote_root="${UNRAID_APP_ROOT:-/mnt/user/appdata/VacatureRadar}" archive_name="vacatureradar-deploy-$$.tar.gz" local_archive="$(mktemp -t "${archive_name}.XXXXXX")" trap 'rm -f "$local_archive"' EXIT ssh_config="$(ssh -G "$unraid_host" 2>/dev/null)" ssh_user="$(printf '%s\n' "$ssh_config" | awk '$1 == "user" { print $2; exit }')" identity_file="$(printf '%s\n' "$ssh_config" | awk '$1 == "identityfile" { print $2; exit }')" if [[ "$unraid_host" == *.* ]] || [[ "$ssh_user" != "root" ]] || [[ "$identity_file" == *"id_ed25519" ]]; then echo "Onveilig of onvolledig Unraid-SSH-profiel: '$unraid_host'." >&2 echo "Gebruik een Host-alias met User root, IdentitiesOnly yes en een afzonderlijke deploysleutel." >&2 echo "Verwacht lokaal standaard: Host unraid-itworx / IdentityFile ~/.ssh/itworx_unraid_deploy" >&2 exit 2 fi ssh -o BatchMode=yes -o ConnectTimeout=8 "$unraid_host" "test \"\$(id -un)\" = root && docker info >/dev/null" git ls-files --cached --others --exclude-standard -z \ | while IFS= read -r -d '' tracked_path; do [[ -e "$tracked_path" ]] && printf '%s\0' "$tracked_path" done \ | tar --null --files-from=- --create --gzip --file="$local_archive" scp -q "$local_archive" "$unraid_host:/tmp/$archive_name" ssh "$unraid_host" "set -eu mkdir -p '$remote_root' tar -xzf '/tmp/$archive_name' -C '$remote_root' rm -f '/tmp/$archive_name' cd '$remote_root' docker compose -f docker-compose.unraid.yml up -d --build timeout 120 sh -c 'until docker inspect VacatureRadar --format=\"{{.State.Health.Status}}\" 2>/dev/null | grep -qx healthy; do sleep 3; done' curl --fail --silent --show-error http://127.0.0.1:1226/health/ready/ >/dev/null docker ps --filter name=VacatureRadar --format '{{.Names}} {{.Status}} {{.Image}}'"