#!/usr/bin/env bash
# Production mode (no OPG_TEST_MODE, root-owned config): which hostname does OPG report?
# Run as root in the lab container. No Oracle needed: "status" on an empty run only reads state.
set -u
mkdir -p /etc/oracle-patch-guard /srv/opg/{patches,opatch,runs,locks}
cat > /etc/oracle-patch-guard/patchGD_guard.conf <<CONF
PATCH_ROOT=/srv/opg/patches
OPATCH_ROOT=/srv/opg/opatch
RUN_ROOT=/srv/opg/runs
LOCK_ROOT=/srv/opg/locks
LOCAL_MEDIA_MODE=required
CONF
chmod 0644 /etc/oracle-patch-guard/patchGD_guard.conf
cd /opt/opg/project
echo "hostname -f says: $(hostname -f)"
for o in "" host-a; do
  if [[ -n $o ]]; then export OPG_HOSTNAME_OVERRIDE=$o; fi
  printf 'OPG_HOSTNAME_OVERRIDE=%-8s -> ' "${o:-<unset>}"
  bash patchGD_guard.sh status --run-id PROD1 2>&1 | grep -oE 'host=[^|]*' | head -1
done
if [[ ${1:-} == fixed ]]; then :; fi
