#!/bin/sh set -eu core_root=${1:?usage: checkout-active-release.sh CORE_ROOT RELEASE_REF} active_release_ref=${2:-} if [ -z "$active_release_ref" ]; then exit 0 fi case "$active_release_ref" in refs/sammo/*) ;; *) echo 'GATEWAY_ACTIVE_RELEASE_GIT_REF must be below refs/sammo/' >&2 exit 64 ;; esac if ! git check-ref-format "$active_release_ref" >/dev/null 2>&1; then echo 'GATEWAY_ACTIVE_RELEASE_GIT_REF is not a valid Git ref' >&2 exit 64 fi if ! git -C "$core_root" show-ref --verify --quiet "$active_release_ref"; then exit 0 fi if ! git -C "$core_root" diff --quiet || ! git -C "$core_root" diff --cached --quiet; then echo 'Core bootstrap checkout has tracked changes; refusing to switch the active release ref' >&2 exit 65 fi active_release_sha=$(git -C "$core_root" rev-parse --verify "${active_release_ref}^{commit}") git -C "$core_root" checkout --quiet --detach "$active_release_sha" echo "Using persistent Gateway release $active_release_sha for runtime bootstrap."