diff --git a/scripts/dist/Makefile b/scripts/dist/Makefile index a19189e34..f48a51c99 100755 --- a/scripts/dist/Makefile +++ b/scripts/dist/Makefile @@ -36,6 +36,8 @@ install-tensorflow: tensorflow-gpu: install-tensorflow-gpu install-tensorflow-gpu: /scripts/install-tensorflow.sh gpu +codex: + /scripts/install-codex.sh davfs: install-davfs install-davfs: /scripts/install-davfs.sh diff --git a/scripts/dist/install-codex.sh b/scripts/dist/install-codex.sh new file mode 100755 index 000000000..5567dad2c --- /dev/null +++ b/scripts/dist/install-codex.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# Installs the Codex CLI coding agent on Linux. +# bash <(curl -s https://raw.githubusercontent.com/photoprism/photoprism/develop/scripts/dist/install-codex.sh) + +set -Eeuo pipefail + +echo "Installing Codex CLI..." + +# Ensure npm exists +if ! command -v npm >/dev/null 2>&1; then + echo "ERROR: npm not found. Please install Node.js (npm) and re-run." >&2 + exit 1 +fi + +# Create CODEX_HOME if set (and not '/') +if [ -n "${CODEX_HOME:-}" ]; then + if [ "${CODEX_HOME}" = "/" ]; then + echo "ERROR: refusing to use CODEX_HOME='/'" >&2 + exit 2 + fi + install -d -m 700 -- "${CODEX_HOME}" +fi + +# Choose sudo only if available and not already root +SUDO="" +if command -v sudo >/dev/null 2>&1 && [ "$(id -u)" -ne 0 ]; then + SUDO="sudo" +fi + +# Some npm versions don’t support --location=global; detect and adapt +if npm help install 2>/dev/null | grep -q -- '--location'; then + NPM_GLOBAL_OPTS=(install -g --location=global --no-fund --no-audit) +else + NPM_GLOBAL_OPTS=(install -g --no-fund --no-audit) +fi + +# Install / update Codex CLI +$SUDO npm "${NPM_GLOBAL_OPTS[@]}" "@openai/codex@latest" + +# Show result +if command -v codex >/dev/null 2>&1; then + echo "Codex installed at: $(command -v codex)" + codex --version || true +fi + +echo "Done."