#!/bin/sh # Install the exact Utah terminal release for this user. set -eu # Use the first Python 3.9 or newer that can make secure connections. utah_python='' utah_seen='' for utah_candidate in python3 python3.15 python3.14 python3.13 python3.12 python3.11 python3.10 python3.9 /opt/homebrew/bin/python3 /usr/local/bin/python3 /Library/Frameworks/Python.framework/Versions/Current/bin/python3; do utah_found=$(command -v "$utah_candidate" 2>/dev/null) || continue # Until Apple's developer tools are installed, macOS ships /usr/bin/python3 as a placeholder that only opens an install dialog. if [ "$utah_found" = /usr/bin/python3 ] && [ "$(uname -s)" = Darwin ] && ! xcode-select -p >/dev/null 2>&1; then continue fi utah_seen=$utah_found if "$utah_found" -c 'import ssl, sys; sys.exit(0 if sys.version_info >= (3, 9) else 1)' >/dev/null 2>&1; then utah_python=$utah_found break fi done if [ "${UTAH_MANAGED_PYTHON:-0}" = 1 ]; then utah_python=''; fi if [ -z "$utah_python" ]; then printf 'Installing the private Utah Python runtime (no administrator access)...\n' utah_os=$(uname -s) utah_arch=$(uname -m) case "$utah_os/$utah_arch" in Darwin/arm64|Darwin/aarch64) utah_target=aarch64-apple-darwin; utah_sha=7a2384641584ab9984221fcb0fc9265df465922af71be71410529e2a9c3f0540 ;; Darwin/x86_64) utah_target=x86_64-apple-darwin; utah_sha=d27d59a722db9f69926eb6d9564071247221f45a04da920ea7f3001c97e32f9b ;; Linux/aarch64|Linux/arm64) utah_target=aarch64-unknown-linux-gnu; utah_sha=55c00325f7c1fddf325dfc621aabdfbbac4dc54adda224af88ec411dc12db239 ;; Linux/x86_64) utah_target=x86_64-unknown-linux-gnu; utah_sha=f2d2199eb25880e07863b391cf7124e7ffa1338b0d65600dfcec117c4223a7fb ;; *) printf 'Automatic Python setup supports macOS and glibc Linux on ARM64 or x86-64. Install Python 3.9+ for this system and retry.\n' >&2; exit 1 ;; esac utah_data="${XDG_DATA_HOME:-$HOME/.local/share}/utah" utah_runtime="$utah_data/python-3.13.18-20261110-$utah_target" if [ -L "$utah_data" ] || [ -L "$utah_runtime" ]; then printf 'The private runtime folder must not be a symbolic link. Choose a different XDG_DATA_HOME.\n' >&2; exit 1 fi umask 077 mkdir -p "$utah_data" if [ ! -d "$utah_runtime" ]; then utah_stage=$(mktemp -d "$utah_data/.python-install-XXXXXXXX") trap 'rm -rf "$utah_stage"' EXIT HUP INT TERM utah_url="https://github.com/astral-sh/python-build-standalone/releases/download/20261110/cpython-3.13.18%2B20261110-$utah_target-install_only_stripped.tar.gz" curl --fail --location --silent --show-error --proto '=https' --proto-redir '=https' --tlsv1.2 --connect-timeout 15 --max-time 120 --max-filesize 45000000 --retry 2 "$utah_url" -o "$utah_stage/runtime.tar.gz" if command -v sha256sum >/dev/null 2>&1; then utah_observed=$(sha256sum "$utah_stage/runtime.tar.gz" | cut -d ' ' -f 1) elif command -v shasum >/dev/null 2>&1; then utah_observed=$(shasum -a 256 "$utah_stage/runtime.tar.gz" | cut -d ' ' -f 1) else printf 'A SHA-256 verifier is required (sha256sum or shasum). No runtime was installed.\n' >&2; exit 1 fi if [ "$utah_observed" != "$utah_sha" ]; then printf 'Python download verification failed. Your existing Utah installation was preserved.\n' >&2; exit 1 fi mkdir "$utah_stage/runtime" tar -xzf "$utah_stage/runtime.tar.gz" -C "$utah_stage/runtime" --strip-components=1 if ! "$utah_stage/runtime/bin/python3" -E -S -c 'import ssl,sys; assert sys.version_info[:3] == (3,13,18)' >/dev/null 2>&1; then printf 'The private Python runtime cannot run on this system. Install a compatible Python 3.9+ and retry.\n' >&2; exit 1 fi printf '%s\n' "$utah_sha" > "$utah_stage/runtime/.utah-runtime-sha256" mv "$utah_stage/runtime" "$utah_runtime" rm -rf "$utah_stage" trap - EXIT HUP INT TERM fi if [ ! -f "$utah_runtime/.utah-runtime-sha256" ] || [ "$(cat "$utah_runtime/.utah-runtime-sha256")" != "$utah_sha" ]; then printf 'An unrelated runtime folder is present. Choose a different XDG_DATA_HOME.\n' >&2; exit 1 fi utah_python="$utah_runtime/bin/python3" fi UTAH_INSTALLER_PATH="$0" export UTAH_INSTALLER_PATH "$utah_python" - <<'PY' import ast import hashlib import http.client import os from pathlib import Path import shlex import shutil import socket import ssl import subprocess import sys import tempfile import time import urllib.error import urllib.request # UTAH_SYSTEM_CERTIFICATES_20261109 # Python from python.org ships without a certificate bundle on macOS, so every # secure request fails there. When this Python has none of its own, use the # operating system's bundle. Verification stays on. _UTAH_CA_BUNDLES = ( '/etc/ssl/cert.pem', '/etc/ssl/certs/ca-certificates.crt', '/etc/pki/tls/certs/ca-bundle.crt', '/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem', '/etc/ssl/ca-bundle.pem', '/var/lib/ca-certificates/ca-bundle.pem', '/opt/homebrew/etc/ca-certificates/cert.pem', '/usr/local/etc/ca-certificates/cert.pem', ) def _utah_system_certificates(): """Return the system bundle now in use, or None when Python's own certificates are present.""" import os import ssl import sys if sys.platform == 'win32': return None try: paths = ssl.get_default_verify_paths() if paths.cafile: return None # A certificate directory counts only when it holds hashed certificates # (names like 4042bcee.0); an empty or placeholder directory verifies nothing. if paths.capath and any(len(name) > 9 and name[8] == '.' and name[9:].isdigit() and all(char in '0123456789abcdef' for char in name[:8]) for name in os.listdir(paths.capath)): return None except (OSError, ValueError): return None for bundle in _UTAH_CA_BUNDLES: if not os.path.isfile(bundle): continue try: ssl.create_default_context(cafile=bundle) except (OSError, ValueError): continue # Read by OpenSSL whenever a connection is prepared, here and in the # tools this process starts. os.environ['SSL_CERT_FILE'] = bundle return bundle return None _UTAH_SYSTEM_CERTIFICATES = _utah_system_certificates() def atomic(path, content, mode): path.parent.mkdir(parents=True, exist_ok=True) fd, temporary = tempfile.mkstemp(prefix='.utah-', dir=path.parent) try: with os.fdopen(fd, 'wb') as stream: stream.write(content) os.chmod(temporary, mode) os.replace(temporary, path) finally: if os.path.exists(temporary): os.unlink(temporary) def download(request, host): """Fetch the release. Brief network trouble is retried; every failure reads as a plain instruction.""" problem = '' for attempt in range(3): try: with urllib.request.urlopen(request, timeout=45) as response: return response.read(2_500_001) except urllib.error.HTTPError as error: if error.code not in (408, 425, 429, 500, 502, 503, 504): raise RuntimeError('The Utah download is not available right now (HTTP ' + str(error.code) + '). Run the install command again in a few minutes. Nothing was changed.') from None problem = 'the server answered HTTP ' + str(error.code) except urllib.error.URLError as error: reason = getattr(error, 'reason', None) if isinstance(reason, ssl.SSLCertVerificationError): raise RuntimeError('This computer could not verify the secure connection to ' + host + ' (' + str(reason.verify_message) + '). Check its date and time and any security software that inspects web traffic, then run the install command again. Nothing was changed.') from None problem = str(reason) except (socket.timeout, TimeoutError, ConnectionError, http.client.HTTPException) as error: problem = str(error) or type(error).__name__ if attempt < 2: time.sleep(2 * (attempt + 1)) raise RuntimeError('Could not reach ' + host + ' (' + problem + '). Check your internet connection and run the install command again. Nothing was changed.') def main(): if sys.version_info < (3, 9) or sys.platform not in ('darwin', 'linux'): raise RuntimeError('Use Python 3.9 or newer on macOS or Linux.') home_dir = Path.home() bin_dir = Path(os.environ.get('UTAH_INSTALL_DIR', str(home_dir / '.local/bin'))).expanduser().resolve() data_dir = Path(os.environ.get('XDG_DATA_HOME', str(home_dir / '.local/share'))).expanduser().resolve() / 'utah' launcher = bin_dir / 'utah' if launcher.is_symlink(): raise RuntimeError('An existing utah symlink is present. Choose a different UTAH_INSTALL_DIR.') if launcher.exists(): existing_head = launcher.read_text(encoding='utf-8', errors='ignore')[:400] if '# Utah terminal launcher' not in existing_head and 'Project Utah terminal agent.' not in existing_head: raise RuntimeError('An unrelated utah command is present. Choose a different UTAH_INSTALL_DIR.') print('Downloading and verifying Utah...', flush=True) request = urllib.request.Request("https://aithatsee.com/utah/terminal.py", headers={'User-Agent':'ProjectUtah-Installer/2'}) installer = Path(os.environ.get('UTAH_INSTALLER_PATH', '')) adjacent = installer.resolve().parent / 'terminal.py' local_release = installer.is_file() and adjacent.is_file() and os.environ.get('UTAH_DOWNLOAD_RELEASE') != '1' source = adjacent.read_bytes() if local_release else download(request, "aithatsee.com") expected = '43b0631b0891dc44a42c480407220a51614ebc3925a19c3f19f65377a4186e88' if len(source) > 2_500_000 or hashlib.sha256(source).hexdigest() != expected: raise RuntimeError('The download does not match this installer. Nothing was replaced. Download the current installer and try again.') tree = ast.parse(source.decode('utf-8')) versions = [ast.literal_eval(node.value) for node in tree.body if isinstance(node, ast.Assign) and any(isinstance(target, ast.Name) and target.id == 'VERSION' for target in node.targets)] if not versions or not isinstance(versions[0], str): raise RuntimeError('The downloaded release has no version.') # The active launcher is replaced only after this immutable release runs. agent = data_dir / ('terminal-' + expected[:16] + '.py') if agent.exists(): if agent.is_symlink() or hashlib.sha256(agent.read_bytes()).hexdigest() != expected: raise RuntimeError('The existing release was modified. Choose another XDG_DATA_HOME.') else: atomic(agent, source, 0o644) result = subprocess.run([sys.executable, '-E', '-S', str(agent), '--version'], capture_output=True, text=True, timeout=20) if result.returncode != 0 or result.stdout.strip() != 'Utah ' + versions[0]: raise RuntimeError('The new terminal did not start correctly. Your existing launcher was preserved.') script = '#!/bin/sh\n# Utah terminal launcher\nPATH=' + shlex.quote(str(Path(sys.executable).parent)) + ':"$PATH"\nexport PATH\nexec ' + shlex.quote(sys.executable) + ' -E -S -u ' + shlex.quote(str(agent)) + ' "$@"\n' atomic(launcher, script.encode(), 0o755) operator = '#!/bin/sh\n# Utah Operator pairing\nexec ' + shlex.quote(str(launcher)) + ' --operator-handoff\n' atomic(bin_dir / 'utah-operator-handoff', operator.encode(), 0o755) active = shutil.which('utah') command_ready = active is not None and Path(active).resolve() == launcher if not command_ready and os.environ.get('UTAH_NO_PATH') != '1': shell_name = Path(os.environ.get('SHELL', '')).name if shell_name == 'zsh': profiles = [Path(os.environ.get('ZDOTDIR') or home_dir).expanduser() / '.zshrc'] elif shell_name == 'bash': profiles = [home_dir / '.bashrc', home_dir / '.bash_profile'] elif shell_name == 'fish': profiles = [home_dir / '.config/fish/config.fish'] else: profiles = [home_dir / '.profile'] line = 'set -gx PATH ' + shlex.quote(str(bin_dir)) + ' $PATH' if shell_name == 'fish' else 'export PATH=' + shlex.quote(str(bin_dir)) + ':"$PATH"' entry = '# Utah terminal command\n' + line + '\n' for profile in profiles: profile.parent.mkdir(parents=True, exist_ok=True) previous = profile.read_text() if profile.exists() else '' # A configured directory can still be shadowed later in the profile. if not previous.rstrip().endswith(entry.rstrip()): with profile.open('a') as stream: stream.write('\n' + entry) print('Installed and verified: ' + result.stdout.strip()) print('In a new terminal, connect your account: utah --setup') print('In your project folder, start with: utah') if not command_ready: print('Run now: ' + shlex.quote(str(launcher))) try: main() except (OSError, ValueError, SyntaxError, RuntimeError, subprocess.SubprocessError) as error: print('Installation stopped: ' + str(error), file=sys.stderr) sys.exit(1) PY