#!/usr/bin/env bash conductor_install() ( set -eu umask 077 version='0.1.5' requirements_url='https://install.conductorquantum.com/releases/0.1.5/requirements.txt' requirements_sha='ecfa525790be0e86825e98dffe20b101d243f4b8bdfbdbe742033e353b247bea' fail() { printf 'Conductor installer: %s\n' "$*" >&2; exit 1; } case "$(uname -s)-$(uname -m)" in Linux-x86_64|Linux-aarch64|Darwin-x86_64|Darwin-arm64) ;; *) fail 'Supported platforms: Linux x86_64/aarch64 and macOS x86_64/arm64' ;; esac [ "$(id -u)" != 0 ] || fail 'Run as your normal user, not with sudo' command -v curl >/dev/null || fail 'Install curl first' if [ -z "${HOME:-}" ] || [ "${HOME#/}" = "$HOME" ]; then fail 'HOME must be an absolute path' fi root="$HOME/.local/share/conductor" bin="$HOME/.local/bin" python="$(command -v python3.12 || true)" if [ -z "$python" ] || ! "$python" -I -c 'import ensurepip, sys, venv; assert sys.version_info[:2] == (3, 12); assert sys.implementation.name == "cpython"' 2>/dev/null; then uv="$(command -v uv || true)" if [ -z "$uv" ] && [ -x "$bin/uv" ]; then uv="$bin/uv" fi if [ -z "$uv" ]; then printf 'CPython 3.12 with venv/pip support was not found; installing uv into %s to provide it\n' "$bin" uv_installer="$(curl --proto '=https' --tlsv1.2 --fail --silent --show-error --location --proto-redir '=https' https://astral.sh/uv/install.sh)" || fail 'uv installer download failed; nothing was installed. Retry when connected, or install CPython 3.12 with venv/pip support and rerun' printf '%s\n' "$uv_installer" | UV_INSTALL_DIR="$bin" UV_NO_MODIFY_PATH=1 sh || fail 'uv installation failed; the Conductor CLI was not installed. Install CPython 3.12 with venv/pip support and rerun' uv="$bin/uv" fi printf 'Providing CPython 3.12 with %s\n' "$uv" "$uv" python install 3.12 || fail 'uv could not install CPython 3.12; the Conductor CLI was not installed. Install CPython 3.12 with venv/pip support and rerun' python="$(UV_PYTHON_PREFERENCE=only-managed "$uv" python find 3.12)" || fail 'uv could not find its CPython 3.12; the Conductor CLI was not installed' "$python" -I -c 'import ensurepip, sys, venv; assert sys.version_info[:2] == (3, 12); assert sys.implementation.name == "cpython"' || fail 'CPython 3.12 is required' fi mkdir -p "$root/releases" "$bin" mkdir "$root/install.lock" 2>/dev/null || fail "Another installation is active. If it was killed, remove $root/install.lock only after confirming no installer is running" candidate='' link='' trap ' [ -z "$link" ] || rm -f "$link" if [ -n "$candidate" ] && [ "$(readlink "$bin/conductor" 2>/dev/null || true)" != "$candidate/bin/conductor" ]; then rm -rf "$candidate" fi rmdir "$root/install.lock" ' EXIT trap 'exit 130' INT trap 'exit 143' TERM HUP if [ -e "$bin/conductor" ] || [ -L "$bin/conductor" ]; then target="$(readlink "$bin/conductor" 2>/dev/null || true)" case "$target" in "$root/releases/"*/bin/conductor) ;; *) fail "$bin/conductor already exists and is not managed by this installer; remove or relocate it explicitly first" ;; esac fi candidate="$(mktemp -d "$root/releases/$version.XXXXXXXX")" curl --proto '=https' --tlsv1.2 --fail --silent --show-error --location --proto-redir '=https' \ "$requirements_url" --output "$candidate/requirements.txt" || fail 'Download failed; the existing installation is unchanged. Retry when connected' "$python" -I - "$candidate/requirements.txt" "$requirements_sha" <<'PY' import hashlib, pathlib, sys if hashlib.sha256(pathlib.Path(sys.argv[1]).read_bytes()).hexdigest() != sys.argv[2]: sys.exit('Requirements checksum mismatch; nothing was installed') PY "$python" -I -m venv "$candidate" || fail 'CPython 3.12 venv creation failed; the previous CLI is unchanged' PIP_CONFIG_FILE=/dev/null "$candidate/bin/python" -I -m pip --isolated --disable-pip-version-check install \ --index-url https://pypi.org/simple --require-hashes --only-binary=:all: --no-deps --no-cache-dir \ --requirement "$candidate/requirements.txt" || fail 'Pinned PyPI installation failed. Check connectivity and wheel support for this OS, then retry; the previous CLI is unchanged' "$candidate/bin/python" -I -m pip --isolated check || fail 'Installed dependencies are incomplete; the previous CLI is unchanged' actual="$("$candidate/bin/conductor" --version)" [ "$actual" = "conductor $version" ] || fail "Unexpected CLI version: $actual" link="$bin/.conductor-link-$$" ln -s "$candidate/bin/conductor" "$link" "$python" -I - "$link" "$bin/conductor" <<'PY' import os, sys os.replace(sys.argv[1], sys.argv[2]) PY link='' candidate='' printf '\nInstalled %s at %s/conductor\n' "$actual" "$bin" path_line='export PATH="$HOME/.local/bin:$PATH"' case ":${PATH:-}:" in *":$bin:"*) ;; *) if [ -n "${CONDUCTOR_NO_MODIFY_PATH:-}" ]; then printf 'Add this directory to PATH in your shell profile, then open a new terminal:\n %s\n' "$path_line" else shell="${SHELL:-}" case "${shell##*/}" in zsh) set -- "${ZDOTDIR:-$HOME}/.zshrc" ;; fish) set -- "${XDG_CONFIG_HOME:-$HOME/.config}/fish/conf.d/conductor.fish" mkdir -p "${1%/*}" || true ;; bash) if [ -e "$HOME/.bash_profile" ]; then set -- "$HOME/.bashrc" "$HOME/.bash_profile" elif [ -e "$HOME/.bash_login" ]; then set -- "$HOME/.bashrc" "$HOME/.bash_login" else set -- "$HOME/.bashrc" "$HOME/.profile" fi ;; *) set -- "$HOME/.profile" ;; esac for profile in "$@"; do if grep -qsxF "$path_line" "$profile"; then printf '%s already adds %s to PATH\n' "$profile" "$bin" elif printf '\n%s\n' "$path_line" >> "$profile"; then printf 'Added %s to PATH in %s\n' "$bin" "$profile" else printf 'Could not update %s. Add this line to your shell profile:\n %s\n' "$profile" "$path_line" fi done printf 'Open a new terminal to use it. Set CONDUCTOR_NO_MODIFY_PATH=1 to skip shell profile changes.\n' fi ;; esac resolved="$(command -v conductor || true)" if [ -n "$resolved" ] && [ "$resolved" != "$bin/conductor" ]; then printf 'Another conductor shadows this installation: %s\nPut %s first in PATH or use the absolute command below.\n' "$resolved" "$bin" fi printf 'Verify: "%s/conductor" --version\nNext (explicit, may request networking privileges): "%s/conductor" login --profile user\nFor a lab computer use --profile lab instead. No login, VPN, or service was started.\n' "$bin" "$bin" ) conductor_install