#!/usr/bin/env bash
set -euo pipefail
# Installation is permitted only in a disposable GitHub-hosted release job.
if [[ "${GITHUB_ACTIONS:-}" != true || "${RUNNER_ENVIRONMENT:-}" != github-hosted || "${JURIS_CI:-}" != 1 ]]; then
  echo 'Refusing tool installation outside the disposable GitHub-hosted CI environment.' >&2
  exit 1
fi
cd "$(dirname "$0")/.."
node ci/prerequisites.mjs approvals
source /etc/os-release
if [[ "$ID" != ubuntu || "$VERSION_ID" != 24.04 ]]; then
  echo 'Release tooling requires the reviewed Ubuntu 24.04 runner image.' >&2
  exit 1
fi
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends python3-venv python3-pikepdf python3-pypdf poppler-utils ghostscript pandoc libreoffice-writer
# Packages come from Ubuntu's signed repositories; no unpinned pip download or global pip writes.
python3 -m venv --system-site-packages storage/app/imm/.venv
python="$PWD/storage/app/imm/.venv/bin/python"
"$python" -c 'import pikepdf, pypdf; print("Release Python PDF modules available")'
printf 'IMM_PYTHON=%s\nPSTQ_PYTHON=%s\n' "$python" "$python" >> "$GITHUB_ENV"
dpkg-query -W python3-pikepdf python3-pypdf poppler-utils ghostscript pandoc libreoffice-writer
