mirror of
https://github.com/SHOGGOTH-SECTOR/sica-fondt.git
synced 2026-07-31 16:16:26 +00:00
Hook: hard fail on toolchain install errors
Replaced warn-and-continue pattern with set -euo pipefail and die(). If a toolchain install fails, the session cannot build — stop immediately. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3bdf25509d
commit
980504b28b
@ -1,21 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
# SessionStart hook — install the polyglot build toolchains for this repo.
|
# SessionStart hook — install the polyglot build toolchains for this repo.
|
||||||
#
|
#
|
||||||
# Claude Code on the web runs in an ephemeral container: anything installed
|
# Claude Code on the web runs in an ephemeral container: anything installed
|
||||||
# outside the cached project tree vanishes on restart. This hook reinstalls the
|
# outside the cached project tree vanishes on restart. This hook reinstalls the
|
||||||
# toolchains the project depends on at the start of every session:
|
# toolchains the project depends on at the start of every session.
|
||||||
# * GNAT + gprbuild + GnuCOBOL (apt: gnat gprbuild gnucobol)
|
|
||||||
# * Pony (ponyc) via ponyup
|
|
||||||
# * Alire (alr) 2.1.1 (prebuilt release zip)
|
|
||||||
#
|
#
|
||||||
# Design rules:
|
# Design rules:
|
||||||
# * IDEMPOTENT — each tool is skipped if it is already on PATH (command -v).
|
# * IDEMPOTENT — each tool is skipped if it is already on PATH (command -v).
|
||||||
# * NON-FATAL — a failed download/install must NOT break the session. We never
|
# * HARD FAIL — if an install fails, the session cannot build. Stop.
|
||||||
# run `set -e`; every step is guarded and the script always exits 0.
|
|
||||||
# * Warnings (not errors) are logged so failures are visible in the session log.
|
|
||||||
|
|
||||||
log() { echo "[install-toolchains] $*"; }
|
log() { echo "[install-toolchains] $*"; }
|
||||||
warn() { echo "[install-toolchains] WARNING: $*" >&2; }
|
die() { echo "[install-toolchains] FATAL: $*" >&2; exit 1; }
|
||||||
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
@ -26,9 +23,7 @@ if command -v gnatmake >/dev/null 2>&1 && command -v cobc >/dev/null 2>&1; then
|
|||||||
log "GNAT/gprbuild/GnuCOBOL already present; skipping apt install."
|
log "GNAT/gprbuild/GnuCOBOL already present; skipping apt install."
|
||||||
else
|
else
|
||||||
log "Installing gnat gprbuild gnucobol via apt-get ..."
|
log "Installing gnat gprbuild gnucobol via apt-get ..."
|
||||||
if ! sudo apt-get install -y gnat gprbuild gnucobol; then
|
sudo apt-get install -y gnat gprbuild gnucobol || die "apt-get install of gnat/gprbuild/gnucobol failed."
|
||||||
warn "apt-get install of gnat/gprbuild/gnucobol failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -38,13 +33,8 @@ if command -v ponyc >/dev/null 2>&1; then
|
|||||||
log "ponyc already present; skipping ponyup install."
|
log "ponyc already present; skipping ponyup install."
|
||||||
else
|
else
|
||||||
log "Installing ponyc via ponyup ..."
|
log "Installing ponyc via ponyup ..."
|
||||||
if sh -c "$(curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ponylang/ponyup/latest-release/ponyup-init.sh)"; then
|
sh -c "$(curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ponylang/ponyup/latest-release/ponyup-init.sh)" || die "ponyup-init.sh failed."
|
||||||
if ! /root/.local/share/ponyup/bin/ponyup update ponyc release; then
|
/root/.local/share/ponyup/bin/ponyup update ponyc release || die "ponyup update ponyc release failed."
|
||||||
warn "ponyup update ponyc release failed; continuing."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "ponyup-init.sh download/run failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -54,15 +44,9 @@ if command -v alr >/dev/null 2>&1; then
|
|||||||
log "alr already present; skipping Alire install."
|
log "alr already present; skipping Alire install."
|
||||||
else
|
else
|
||||||
log "Installing Alire (alr) 2.1.1 ..."
|
log "Installing Alire (alr) 2.1.1 ..."
|
||||||
if curl -sSL -o /tmp/alr.zip https://github.com/alire-project/alire/releases/download/v2.1.1/alr-2.1.1-bin-x86_64-linux.zip; then
|
curl -sSL -o /tmp/alr.zip https://github.com/alire-project/alire/releases/download/v2.1.1/alr-2.1.1-bin-x86_64-linux.zip || die "Alire download failed."
|
||||||
if ( cd /tmp && unzip -o -q alr.zip && sudo cp bin/alr /usr/local/bin/alr && chmod +x /usr/local/bin/alr ); then
|
( cd /tmp && unzip -o -q alr.zip && sudo cp bin/alr /usr/local/bin/alr && chmod +x /usr/local/bin/alr ) || die "Alire unzip/copy failed."
|
||||||
log "alr installed to /usr/local/bin/alr"
|
log "alr installed to /usr/local/bin/alr"
|
||||||
else
|
|
||||||
warn "Alire unzip/copy failed; continuing."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Alire download failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -72,9 +56,7 @@ if command -v gfortran >/dev/null 2>&1; then
|
|||||||
log "gfortran already present; skipping."
|
log "gfortran already present; skipping."
|
||||||
else
|
else
|
||||||
log "Installing gfortran libopenblas-dev via apt-get ..."
|
log "Installing gfortran libopenblas-dev via apt-get ..."
|
||||||
if ! sudo apt-get install -y gfortran libopenblas-dev; then
|
sudo apt-get install -y gfortran libopenblas-dev || die "apt-get install of gfortran/libopenblas-dev failed."
|
||||||
warn "apt-get install of gfortran/libopenblas-dev failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -85,12 +67,9 @@ if command -v fpm >/dev/null 2>&1; then
|
|||||||
else
|
else
|
||||||
log "Installing fpm ..."
|
log "Installing fpm ..."
|
||||||
FPM_URL="https://github.com/fortran-lang/fpm/releases/download/v0.10.1/fpm-0.10.1-linux-x86_64"
|
FPM_URL="https://github.com/fortran-lang/fpm/releases/download/v0.10.1/fpm-0.10.1-linux-x86_64"
|
||||||
if curl -sSL -o /tmp/fpm "$FPM_URL"; then
|
curl -sSL -o /tmp/fpm "$FPM_URL" || die "fpm download failed."
|
||||||
sudo cp /tmp/fpm /usr/local/bin/fpm && sudo chmod +x /usr/local/bin/fpm
|
sudo cp /tmp/fpm /usr/local/bin/fpm && sudo chmod +x /usr/local/bin/fpm || die "fpm install failed."
|
||||||
log "fpm installed to /usr/local/bin/fpm"
|
log "fpm installed to /usr/local/bin/fpm"
|
||||||
else
|
|
||||||
warn "fpm download failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -100,9 +79,7 @@ if command -v tclsh >/dev/null 2>&1; then
|
|||||||
log "tclsh already present; skipping."
|
log "tclsh already present; skipping."
|
||||||
else
|
else
|
||||||
log "Installing tcl via apt-get ..."
|
log "Installing tcl via apt-get ..."
|
||||||
if ! sudo apt-get install -y tcl; then
|
sudo apt-get install -y tcl || die "apt-get install of tcl failed."
|
||||||
warn "apt-get install of tcl failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -113,15 +90,10 @@ if command -v eclipse >/dev/null 2>&1 || [ -x /opt/eclipseclp/bin/x86_64_linux/e
|
|||||||
else
|
else
|
||||||
log "Installing ECLiPSe Prolog ..."
|
log "Installing ECLiPSe Prolog ..."
|
||||||
ECLIPSE_URL="https://eclipseclp.org/Distribution/Current/7.1_13/x86_64_linux/eclipse_basic.tgz"
|
ECLIPSE_URL="https://eclipseclp.org/Distribution/Current/7.1_13/x86_64_linux/eclipse_basic.tgz"
|
||||||
if curl -sSL -o /tmp/eclipse_basic.tgz "$ECLIPSE_URL"; then
|
curl -sSL -o /tmp/eclipse_basic.tgz "$ECLIPSE_URL" || die "ECLiPSe download failed."
|
||||||
if sudo mkdir -p /opt/eclipseclp && sudo tar -xzf /tmp/eclipse_basic.tgz -C /opt/eclipseclp; then
|
sudo mkdir -p /opt/eclipseclp || die "Could not create /opt/eclipseclp."
|
||||||
log "ECLiPSe installed to /opt/eclipseclp"
|
sudo tar -xzf /tmp/eclipse_basic.tgz -C /opt/eclipseclp || die "ECLiPSe extraction failed."
|
||||||
else
|
log "ECLiPSe installed to /opt/eclipseclp"
|
||||||
warn "ECLiPSe extraction failed; continuing."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "ECLiPSe download failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -132,15 +104,10 @@ if command -v zig >/dev/null 2>&1; then
|
|||||||
else
|
else
|
||||||
log "Installing Zig ..."
|
log "Installing Zig ..."
|
||||||
ZIG_URL="https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz"
|
ZIG_URL="https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz"
|
||||||
if curl -sSL -o /tmp/zig.tar.xz "$ZIG_URL"; then
|
curl -sSL -o /tmp/zig.tar.xz "$ZIG_URL" || die "Zig download failed."
|
||||||
if sudo tar -xJf /tmp/zig.tar.xz -C /opt && sudo ln -sf /opt/zig-linux-x86_64-0.13.0/zig /usr/local/bin/zig; then
|
sudo tar -xJf /tmp/zig.tar.xz -C /opt || die "Zig extraction failed."
|
||||||
log "zig installed to /usr/local/bin/zig"
|
sudo ln -sf /opt/zig-linux-x86_64-0.13.0/zig /usr/local/bin/zig || die "Zig symlink failed."
|
||||||
else
|
log "zig installed to /usr/local/bin/zig"
|
||||||
warn "Zig extraction/linking failed; continuing."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Zig download failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -150,30 +117,22 @@ if command -v forge >/dev/null 2>&1; then
|
|||||||
log "forge (Foundry) already present; skipping."
|
log "forge (Foundry) already present; skipping."
|
||||||
else
|
else
|
||||||
log "Installing Foundry (forge, anvil) ..."
|
log "Installing Foundry (forge, anvil) ..."
|
||||||
if curl -sSL https://foundry.paradigm.xyz | bash; then
|
curl -sSL https://foundry.paradigm.xyz | bash || die "Foundry install script failed."
|
||||||
if "$HOME/.foundry/bin/foundryup"; then
|
"$HOME/.foundry/bin/foundryup" || die "foundryup failed."
|
||||||
log "Foundry installed"
|
log "Foundry installed"
|
||||||
else
|
|
||||||
warn "foundryup failed; continuing."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Foundry install script failed; continuing."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Ensure ponyc is on PATH for future shells.
|
# PATH for tools not in standard locations.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
EXTRA_PATHS='/root/.local/share/ponyup/bin:/opt/eclipseclp/bin/x86_64_linux'
|
EXTRA_PATHS='/root/.local/share/ponyup/bin:/opt/eclipseclp/bin/x86_64_linux'
|
||||||
FOUNDRY_PATH="$HOME/.foundry/bin"
|
FOUNDRY_PATH="$HOME/.foundry/bin"
|
||||||
FULL_PATH_LINE="export PATH=$EXTRA_PATHS:$FOUNDRY_PATH:\$PATH"
|
FULL_PATH_LINE="export PATH=$EXTRA_PATHS:$FOUNDRY_PATH:\$PATH"
|
||||||
if [ -f "$HOME/.bashrc" ] && grep -qF "eclipseclp" "$HOME/.bashrc"; then
|
if [ -f "$HOME/.bashrc" ] && grep -qF "eclipseclp" "$HOME/.bashrc"; then
|
||||||
log "Economy-organ PATH lines already in ~/.bashrc; skipping."
|
log "Toolchain PATH lines already in ~/.bashrc; skipping."
|
||||||
else
|
else
|
||||||
log "Appending toolchain PATH lines to ~/.bashrc"
|
log "Appending toolchain PATH lines to ~/.bashrc"
|
||||||
echo "$FULL_PATH_LINE" >> "$HOME/.bashrc" || warn "Could not append to ~/.bashrc; continuing."
|
echo "$FULL_PATH_LINE" >> "$HOME/.bashrc" || die "Could not append to ~/.bashrc."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "Done."
|
log "Done."
|
||||||
# Never fail the session, regardless of what happened above.
|
|
||||||
exit 0
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user