
#!/bin/bash
# Post-receive hook: checkout werkcopy + sync naar nlxfsd19 na elke git push
# Locatie op nlxfsd18: /home/automation/NL-FSOD.git/hooks/post-receive
#
# $GIT_DIR is automatisch ingesteld door Git op het bare-repo pad.
# git --work-tree checkt de nieuwste commit uit naar de werkdirectory.

NLXFSD19="automation@161.89.52.126"
REPO_DIR="/home/automation/NL-FSOD"

echo "=== Checkout naar werkcopy ==="
git --work-tree="${REPO_DIR}" checkout -f \
  && echo "=== Checkout OK ===" \
  || { echo "=== Checkout FOUT ==="; exit 1; }

echo "=== Sync naar nlxfsd19 ==="
rsync -a --delete \
  --exclude=".git" \
  --exclude="terraform-clusters/*/ontap_facts.yml" \
  --exclude="inventory/" \
  --exclude="ansible/group_vars/all/vault.yml" \
  "${REPO_DIR}/" "${NLXFSD19}:${REPO_DIR}/" \
  && echo "=== Sync OK ===" \
  || echo "=== Sync FOUT ==="

