|
| 1 | +#!/usr/bin/env bash |
| 2 | +# codex installer. Runs as the workspace user — npm install -g goes into |
| 3 | +# the user's own nvm prefix ($HOME/.nvm/versions/node/<v>/bin). |
| 4 | +# https://github.com/openai/codex |
| 5 | +set -e |
| 6 | + |
| 7 | +CODEX_VERSION_OPT="${CODEX_VERSION:-latest}" |
| 8 | + |
| 9 | +# Activate nvm so `npm` resolves against the user's default Node. |
| 10 | +export NVM_DIR="$HOME/.nvm" |
| 11 | +if [ -s "$NVM_DIR/nvm.sh" ]; then |
| 12 | + # shellcheck disable=SC1091 |
| 13 | + . "$NVM_DIR/nvm.sh" |
| 14 | + nvm use default >/dev/null |
| 15 | +fi |
| 16 | + |
| 17 | +if ! command -v npm >/dev/null 2>&1; then |
| 18 | + echo "codex: npm not on PATH. scripts/nvm/install.sh must run before scripts/codex/install.sh." >&2 |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +# Resolve target version. `latest` → newest tag via GitHub API. |
| 23 | +if [ "$CODEX_VERSION_OPT" = "latest" ]; then |
| 24 | + CODEX_VERSION="$(curl -fsSL https://api.github.com/repos/openai/codex/releases/latest | jq -r .tag_name)" |
| 25 | +else |
| 26 | + CODEX_VERSION="$CODEX_VERSION_OPT" |
| 27 | +fi |
| 28 | +CODEX_VERSION="${CODEX_VERSION#rust-v}" |
| 29 | +if [ -z "$CODEX_VERSION" ] || [ "$CODEX_VERSION" = "null" ]; then |
| 30 | + echo "codex: failed to resolve release version (got '$CODEX_VERSION_OPT')." >&2 |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +npm install -g "@openai/codex@${CODEX_VERSION}" |
| 35 | + |
| 36 | +if ! command -v codex >/dev/null 2>&1; then |
| 37 | + echo "codex: binary not on PATH after npm install." >&2 |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | + |
| 41 | +# Declare the HOME paths Codex needs persisted. The home-persist |
| 42 | +# resolver reads every /etc/home-persist.d/*.json at workspace start and |
| 43 | +# symlinks these into /mnt/home-persist. /etc/home-persist.d is root-owned. |
| 44 | +sudo mkdir -p /etc/home-persist.d |
| 45 | +sudo tee /etc/home-persist.d/codex.json >/dev/null <<'EOF' |
| 46 | +{ |
| 47 | + "source": "codex", |
| 48 | + "paths": [".codex/"] |
| 49 | +} |
| 50 | +EOF |
0 commit comments