TheJackBright's picture
Deploy GitHub root master to Space
c296d62
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "$ROOT_DIR/scripts/venv_utils.sh"
RUNTIME_CHECK="false"
for arg in "$@"; do
case "$arg" in
--runtime-check) RUNTIME_CHECK="true" ;;
--help|-h)
cat <<'USAGE'
Usage: bash scripts/bootstrap_openenv.sh [--runtime-check]
Bootstraps OpenEnv CLI/runtime dependencies and validates the local environment
structure. Optionally performs a runtime contract check against a local server.
USAGE
exit 0
;;
*)
echo "Unknown flag: $arg"
exit 1
;;
esac
done
echo "[bootstrap_openenv] syncing dependencies"
ensure_polyguard_venv
if ! sync_polyguard_requirements >/dev/null 2>&1; then
echo "[bootstrap_openenv] dependency sync skipped (offline/restricted), continuing"
fi
activate_polyguard_path
if ! command -v openenv >/dev/null 2>&1; then
echo "[bootstrap_openenv] openenv CLI not found in environment"
exit 1
fi
echo "[bootstrap_openenv] validating local structure"
openenv validate "$ROOT_DIR"
if [[ "$RUNTIME_CHECK" == "true" ]]; then
echo "[bootstrap_openenv] running runtime contract check"
"$POLYGUARD_PYTHON_BIN" -m app.env.fastapi_app >/tmp/polyguard_openenv_bootstrap.log 2>&1 &
ENV_PID="$!"
cleanup() {
if [[ -n "${ENV_PID:-}" ]] && kill -0 "$ENV_PID" >/dev/null 2>&1; then
kill "$ENV_PID" >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT
sleep 2
if ! openenv validate --url "http://127.0.0.1:8100"; then
echo "[bootstrap_openenv] runtime validation unavailable in current sandbox; continuing with local structure validation"
fi
cleanup
trap - EXIT
fi
echo "openenv_ready"