|
| 1 | +#!/usr/bin/env bash |
| 2 | +# ───────────────────────────────────────────────────────────── |
| 3 | +# setup-scenarios-prerequisites.sh — Install all scenario test |
| 4 | +# dependencies so that scenario scripts only run tests, not setup. |
| 5 | +# |
| 6 | +# Installs (if not already present): |
| 7 | +# 1. Foundry (cast, forge) |
| 8 | +# 2. Portable Python 3.10 (for cqlsh / Cassandra compatibility) |
| 9 | +# 3. cqlsh via Apache Cassandra tarball |
| 10 | +# |
| 11 | +# Also verifies that git, node, and pnpm are available. |
| 12 | +# |
| 13 | +# Usage: |
| 14 | +# ./scripts/setup-scenarios-prerequisites.sh |
| 15 | +# ───────────────────────────────────────────────────────────── |
| 16 | +set -euo pipefail |
| 17 | + |
| 18 | +RED='\033[0;31m' |
| 19 | +GREEN='\033[0;32m' |
| 20 | +BLUE='\033[0;34m' |
| 21 | +NC='\033[0m' |
| 22 | + |
| 23 | +pass() { printf "${GREEN}✓${NC} %s\n" "$1"; } |
| 24 | +fail() { printf "${RED}✗${NC} %s\n" "$1"; exit 1; } |
| 25 | +info() { printf "${BLUE}ℹ${NC} %s\n" "$1"; } |
| 26 | + |
| 27 | +# ── Constants ──────────────────────────────────────────────── |
| 28 | +CASSANDRA_VERSION="5.0.6" |
| 29 | +PYTHON_VERSION="3.10" |
| 30 | +CASSANDRA_URL="https://dlcdn.apache.org/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz" |
| 31 | +CASSANDRA_DIR="$HOME/.foc-devnet/artifacts/cassandra" |
| 32 | +CASSANDRA_HOME="${CASSANDRA_DIR}/apache-cassandra-${CASSANDRA_VERSION}" |
| 33 | + |
| 34 | +# ── 0. Verify basic system tools ──────────────────────────── |
| 35 | +info "Checking basic system tools..." |
| 36 | + |
| 37 | +for tool in git node pnpm npm; do |
| 38 | + if command -v "$tool" &>/dev/null; then |
| 39 | + pass "$tool is installed ($(command -v "$tool"))" |
| 40 | + else |
| 41 | + fail "$tool is required but not found. Please install it first." |
| 42 | + fi |
| 43 | +done |
| 44 | + |
| 45 | +# ── 1. Foundry (cast / forge) ─────────────────────────────── |
| 46 | +info "Checking Foundry..." |
| 47 | + |
| 48 | +if command -v cast &>/dev/null; then |
| 49 | + pass "Foundry already installed (cast @ $(command -v cast))" |
| 50 | +else |
| 51 | + info "Installing Foundry..." |
| 52 | + curl -sSL https://foundry.paradigm.xyz | bash |
| 53 | + export PATH="$HOME/.foundry/bin:$PATH" |
| 54 | + "$HOME/.foundry/bin/foundryup" |
| 55 | + if command -v cast &>/dev/null; then |
| 56 | + pass "Foundry installed successfully" |
| 57 | + else |
| 58 | + fail "Foundry installation failed — cast not found on PATH" |
| 59 | + fi |
| 60 | +fi |
| 61 | + |
| 62 | +# ── 2. Portable Python (for cqlsh) ────────────────────────── |
| 63 | +info "Checking portable Python ${PYTHON_VERSION}..." |
| 64 | + |
| 65 | +NPM_ROOT="$(npm root -g)" |
| 66 | +PKG_DIR="${NPM_ROOT}/@bjia56/portable-python-${PYTHON_VERSION}" |
| 67 | +CUSTOM_PYTHON="" |
| 68 | + |
| 69 | +if [[ -d "$PKG_DIR" ]]; then |
| 70 | + CUSTOM_PYTHON="$(find "$PKG_DIR" -path '*/bin/python*' -type f | head -n1)" |
| 71 | +fi |
| 72 | + |
| 73 | +if [[ -n "$CUSTOM_PYTHON" ]]; then |
| 74 | + pass "Portable Python ${PYTHON_VERSION} already installed (${CUSTOM_PYTHON})" |
| 75 | +else |
| 76 | + info "Installing portable Python ${PYTHON_VERSION} via npm..." |
| 77 | + npm i --global --silent "@bjia56/portable-python-${PYTHON_VERSION}" |
| 78 | + CUSTOM_PYTHON="$(find "$PKG_DIR" -path '*/bin/python*' -type f | head -n1)" |
| 79 | + if [[ -n "$CUSTOM_PYTHON" ]]; then |
| 80 | + pass "Portable Python ${PYTHON_VERSION} installed (${CUSTOM_PYTHON})" |
| 81 | + else |
| 82 | + fail "Portable Python ${PYTHON_VERSION} installation failed — binary not found under ${PKG_DIR}" |
| 83 | + fi |
| 84 | +fi |
| 85 | + |
| 86 | +# ── 3. cqlsh (Apache Cassandra tarball) ────────────────────── |
| 87 | +info "Checking cqlsh..." |
| 88 | + |
| 89 | +CQLSH="${CASSANDRA_HOME}/bin/cqlsh" |
| 90 | + |
| 91 | +if [[ -x "$CQLSH" ]]; then |
| 92 | + CQLSH_VERSION="$(CQLSH_PYTHON="$CUSTOM_PYTHON" "$CQLSH" --version 2>&1 || true)" |
| 93 | + pass "cqlsh already installed (${CQLSH_VERSION})" |
| 94 | +else |
| 95 | + info "Downloading Apache Cassandra ${CASSANDRA_VERSION} for cqlsh..." |
| 96 | + mkdir -p "$CASSANDRA_DIR" |
| 97 | + TARBALL="${CASSANDRA_DIR}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz" |
| 98 | + curl -fL -o "$TARBALL" "$CASSANDRA_URL" |
| 99 | + tar -xzf "$TARBALL" -C "$CASSANDRA_DIR" |
| 100 | + if [[ -x "$CQLSH" ]]; then |
| 101 | + CQLSH_VERSION="$(CQLSH_PYTHON="$CUSTOM_PYTHON" "$CQLSH" --version 2>&1 || true)" |
| 102 | + pass "cqlsh installed (${CQLSH_VERSION})" |
| 103 | + else |
| 104 | + fail "cqlsh installation failed — ${CQLSH} not found after extraction" |
| 105 | + fi |
| 106 | +fi |
| 107 | + |
| 108 | +# ── Done ───────────────────────────────────────────────────── |
| 109 | +echo "" |
| 110 | +echo "════════════════════════════════════════════════════════" |
| 111 | +printf "${GREEN}✓ All scenario prerequisites are installed.${NC}\n" |
| 112 | +echo "════════════════════════════════════════════════════════" |
0 commit comments