mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-06-10 11:39:50 +00:00
Install specific foundry anvil version directly (#3937)
* Install specific foundry anvil version directly * clean verbose comments
This commit is contained in:
parent
c7350abb58
commit
362c35f2fb
@ -1,52 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Install Anvil
|
||||
# Install Foundry binaries (forge, cast, anvil, chisel).
|
||||
#
|
||||
# We bypass `foundryup` and pull the release tarball straight from GitHub.
|
||||
|
||||
REQUIRED_FOUNDRY_VERSION="$1"
|
||||
set -euo pipefail
|
||||
|
||||
if command -v anvil &> /dev/null; then
|
||||
# Foundry is already installed; check the current version.
|
||||
REQUIRED_FOUNDRY_VERSION="${1:-}"
|
||||
if [ -z "$REQUIRED_FOUNDRY_VERSION" ]; then
|
||||
echo "usage: install_anvil.sh <foundry-version>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command -v anvil >/dev/null 2>&1; then
|
||||
CURRENT_FOUNDRY_VERSION=$(anvil --version 2>/dev/null | awk '{print $2}')
|
||||
|
||||
if [ -n "$CURRENT_FOUNDRY_VERSION" ]; then
|
||||
# Compare CURRENT_FOUNDRY_VERSION < REQUIRED_FOUNDRY_VERSION using sort -V
|
||||
lower_version=$(printf '%s\n%s\n' "$CURRENT_FOUNDRY_VERSION" "$REQUIRED_FOUNDRY_VERSION" | sort -V | head -n1)
|
||||
|
||||
if [ "$lower_version" != "$REQUIRED_FOUNDRY_VERSION" ]; then
|
||||
echo "Anvil is already installed with version $CURRENT_FOUNDRY_VERSION, which is older than the required $REQUIRED_FOUNDRY_VERSION. Please update Foundry manually if needed."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
BASE_DIR="${XDG_CONFIG_HOME:-$HOME}"
|
||||
FOUNDRY_DIR="${FOUNDRY_DIR:-"$BASE_DIR/.foundry"}"
|
||||
FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Installing Foundry..."
|
||||
curl -L https://foundry.paradigm.xyz | bash
|
||||
case "$(uname -s)" in
|
||||
Darwin) PLATFORM=darwin ;;
|
||||
Linux) PLATFORM=linux ;;
|
||||
*) echo "Unsupported platform: $(uname -s)" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# Add Foundry to PATH for this script session
|
||||
export PATH="$FOUNDRY_BIN_DIR:$PATH"
|
||||
case "$(uname -m)" in
|
||||
x86_64|amd64) ARCH=amd64 ;;
|
||||
arm64|aarch64) ARCH=arm64 ;;
|
||||
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# Verify foundryup is available
|
||||
if ! command -v foundryup >/dev/null 2>&1; then
|
||||
echo "Error: foundryup installation failed or not found in $FOUNDRY_BIN_DIR"
|
||||
exit 1
|
||||
fi
|
||||
BASE_DIR="${XDG_CONFIG_HOME:-$HOME}"
|
||||
FOUNDRY_DIR="${FOUNDRY_DIR:-"$BASE_DIR/.foundry"}"
|
||||
FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin"
|
||||
|
||||
# Run foundryup to install the required version
|
||||
if [ -n "$REQUIRED_FOUNDRY_VERSION" ]; then
|
||||
echo "Installing Foundry tools version $REQUIRED_FOUNDRY_VERSION..."
|
||||
foundryup --install "$REQUIRED_FOUNDRY_VERSION"
|
||||
else
|
||||
echo "Installing latest Foundry tools..."
|
||||
foundryup
|
||||
fi
|
||||
TAG="v${REQUIRED_FOUNDRY_VERSION}"
|
||||
ASSET="foundry_${TAG}_${PLATFORM}_${ARCH}.tar.gz"
|
||||
URL="https://github.com/foundry-rs/foundry/releases/download/${TAG}/${ASSET}"
|
||||
|
||||
# Verify anvil was installed
|
||||
if ! command -v anvil >/dev/null 2>&1; then
|
||||
echo "Error: anvil installation failed"
|
||||
exit 1
|
||||
fi
|
||||
echo "Installing Foundry ${TAG} for ${PLATFORM}/${ARCH}..."
|
||||
mkdir -p "$FOUNDRY_BIN_DIR"
|
||||
|
||||
echo "Anvil successfully installed: $(anvil --version)"
|
||||
fi
|
||||
tmpdir=$(mktemp -d)
|
||||
trap 'rm -rf "$tmpdir"' EXIT
|
||||
archive="$tmpdir/foundry.tar.gz"
|
||||
|
||||
curl -fL --retry 5 --retry-delay 2 --retry-all-errors -o "$archive" "$URL"
|
||||
|
||||
# Validate the archive before extracting -- catches truncated/HTML responses
|
||||
# loudly instead of leaving a half-installed Foundry on disk.
|
||||
tar tzf "$archive" >/dev/null
|
||||
|
||||
tar -xzf "$archive" -C "$FOUNDRY_BIN_DIR" forge cast anvil chisel
|
||||
chmod +x "$FOUNDRY_BIN_DIR"/{forge,cast,anvil,chisel}
|
||||
|
||||
export PATH="$FOUNDRY_BIN_DIR:$PATH"
|
||||
if [ -n "${GITHUB_PATH:-}" ]; then
|
||||
echo "$FOUNDRY_BIN_DIR" >> "$GITHUB_PATH"
|
||||
fi
|
||||
|
||||
if ! command -v anvil >/dev/null 2>&1; then
|
||||
echo "Error: anvil installation failed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Anvil successfully installed: $(anvil --version)"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user