Files
openrig/scripts/install.sh
T
Mike Schwarz f86a80285a fix(install): say the CLI is installed and setup is not complete when rig setup isn't ready (#1547)
When `rig setup` (step 4 of the one-line installer) finishes without being ready, the installer now ends with `INSTALLED, SETUP NOT COMPLETE (exit N).` instead of `FAILED [4/4] … (exit 1)`, which read as "OpenRig didn't install" though the CLI was installed and the compatibility check ran. The summary gives the installed CLI path, the Node/SQLite check result (`passed`, or `SKIPPED (not checked; see above)`), a pointer to setup's own "Some steps need attention" list, with a Fix where setup gives one, or to the error that stopped it, and "Fix those, then run rig setup again; the CLI does not need reinstalling."

- Setup's exit status passes through exactly, and setup's own output stays above the summary.
- Steps 1-3 keep their `FAILED [n/4]` line, and a ready setup keeps today's closing line.
- It names no cause that setup's result doesn't establish: a provider check fails for a missing sign-in but also for a probe that timed out or errored, and the installer sees only setup's exit status, so the summary doesn't say "sign in".
- A skipped compatibility check is never reported as passed. Setup's readiness and exit behaviour, provider selection and every other exit status are unchanged, with no extra probe.

The README and getting-started are unchanged on purpose: they show the pinned release's installer, which still ends with `FAILED [4/4]`. They move together with the pin, at the first release tag that contains this script.

Tests: the wrapper tests cover setup exit 1, 40 and a piped run's 43, unchanged early failures, a skipped check and the ready ending; five setup-boundary cases cover sign-in only, a mixed failure, ready, an unselected provider and an uncertain probe.
2026-10-19 13:16:39 -07:00

118 lines
5.5 KiB
Bash

#!/bin/sh
# Opt-in wrapper over the manual install commands. Also accepts a download piped
# to sh; define the complete program before starting any child commands.
install_failed() {
install_exit=$1
shift
printf '\nFAILED %s (exit %s). See the command output above.\n' "$*" "$install_exit" >&2
exit "$install_exit"
}
install_step() {
install_label=$1
shift
printf '\n[%s] %s\n' "$install_label" "$*"
# Keep native output and the actual status; a formatting pipe would lose it.
if "$@"; then
return 0
else
install_failed "$?" "[$install_label] $*"
fi
}
# Step 4 is the one failure after which OpenRig itself is installed: say so, and that setup is
# not complete, keeping setup's own status. Its output above names what is left; this summary
# names nothing it cannot see (a failed provider check is not proof of a missing sign-in).
install_setup_incomplete() {
install_exit=$1
printf '\nINSTALLED, SETUP NOT COMPLETE (exit %s).\n' "$install_exit" >&2
printf 'The OpenRig CLI is installed: %s\n' "$install_rig" >&2
printf 'Node/SQLite compatibility check: %s.\n' "$install_abi" >&2
printf '%s\n' 'rig setup did not finish ready. Its output above lists what is left under' \
'"Some steps need attention", with a Fix where setup gives one, or shows the error that stopped it.' \
'Fix those, then run rig setup again; the CLI does not need reinstalling.' >&2
exit "$install_exit"
}
install_main() {
case "$#:$1" in
0:|1:--dry-run) ;;
1:--help|1:-h)
printf '%s\n' 'Usage: sh install.sh [--dry-run]' 'For a piped preview: ... | sh -s -- --dry-run'
return 0 ;;
*) printf '%s\n' 'Usage: sh install.sh [--dry-run]' >&2; return 2 ;;
esac
printf '%s\n' \
'OpenRig install plan (macOS or Linux):' \
' [1/4] Check node and npm on PATH; print their versions.' \
' [2/4] npm install -g @openrig/cli' \
' Installs the published CLI and dependencies into your npm global prefix.' \
' npm prefix -g locates that installation; its bin/rig is used below.' \
' Run node "$(npm root -g)/@openrig/cli/scripts/check-abi.mjs" if present.' \
' Check Node/SQLite explicitly even if npm skipped postinstall; report if unavailable.' \
' [3/4] rig setup --dry-run' \
" Show the installed version's setup plan without applying it." \
' [4/4] rig setup' \
' Checks both Claude Code and Codex; may install missing tools.' \
' Checks tmux and writes its defaults. rig setup installs herdr by default;' \
' an unavailable herdr install is a warning. Existing cmux settings stay unchanged.' \
' On macOS, an installing agent offers Ghostty; rig setup --ghostty attempts it after acceptance.' \
'This broader setup is optional for the manual selected-provider path.' \
'The wrapper does not log in, choose a permission policy, launch a team or open a kernel conversation.' \
'Node advice: Node.js 22 or 24 with npm; use 22 on Apple silicon.' \
'Distribution packages can be older; check node --version.' \
'Use the official Node installer, or the Linux route (NodeSource or nvm):' \
'https://github.com/mvschwarz/openrig/blob/main/docs/reference/getting-started.md' \
'The installed package checker owns compatibility checks: below 22 and odd majors' \
'are rejected; later even majors warn as untested. No automatic Node or permission repair.'
if [ "$1" = '--dry-run' ]; then
printf '\n%s\n' 'Dry run: no commands executed or changes made.'
return 0
fi
for install_tool in node npm; do
if ! command -v "$install_tool" >/dev/null 2>&1; then
printf 'Missing prerequisite: %s. Install Node.js 22 or 24 with npm, then retry.\nDistribution packages can be older; check node --version.\nUse the official Node installer, or the Linux route (NodeSource or nvm):\nhttps://github.com/mvschwarz/openrig/blob/main/docs/reference/getting-started.md\n' "$install_tool" >&2
install_failed 127 '[1/4] prerequisite check'
fi
done
install_step 1/4 node --version
install_step 1/4 npm --version
install_step 2/4 npm install -g @openrig/cli
if install_prefix=$(npm prefix -g); then :; else
install_failed "$?" '[2/4] npm prefix -g'
fi
install_rig="$install_prefix/bin/rig"
if [ ! -x "$install_rig" ]; then
printf 'Installed rig is not executable: %s\n' "$install_rig" >&2
install_failed 127 '[2/4] locate installed rig'
fi
PATH="$install_prefix/bin:$PATH"
export PATH
if install_modules=$(npm root -g); then :; else
install_failed "$?" '[2/4] npm root -g'
fi
install_checker="$install_modules/@openrig/cli/scripts/check-abi.mjs"
if [ -f "$install_checker" ]; then
install_step 2/4 node "$install_checker"
printf '\n%s\n' 'Node/SQLite compatibility check passed.'
install_abi=passed
else
printf '\nNode/SQLite compatibility check SKIPPED: installed checker not found at %s\n' "$install_checker" >&2
install_abi='SKIPPED (not checked; see above)'
fi
install_step 3/4 "$install_rig" setup --dry-run
printf '\n[%s] %s\n' 4/4 "$install_rig setup"
# Keep native output and the actual status, as install_step does.
if "$install_rig" setup; then :; else
install_setup_incomplete "$?"
fi
printf '\n%s\n' 'Follow the next steps printed by rig setup: start the daemon, open the OpenRig view, then tell the operator what you want to build.'
}
# Setup prints policy guidance, not an input prompt. EOF keeps children from
# consuming the rest of a streamed script; no implicit answer is supplied.
install_main "$@" </dev/null