#!/bin/sh # Installer for the published rdy release. No sudo required. # Usage: curl -fsSL https://getrdy.dev/install.sh | sh # Keep the version and pinned archive hashes in sync with the website. set -eu fail() { printf '\nError: %s\n' "$*" >&2; exit 1; } confirm() { if [ "$assume_yes" = yes ]; then return 0; fi printf '%s [Y/n] ' "$1" >&3 IFS= read -r answer <&3 || fail 'Terminal input closed. Installation stopped.' case "$answer" in ''|y|Y|yes|YES) return 0 ;; *) return 1 ;; esac } cleanup() { [ -z "$staged_binary" ] || rm -f "$staged_binary" [ -z "$work_dir" ] || rm -rf "$work_dir" } download() { curl --fail --show-error --silent --location --proto '=https' --proto-redir '=https' \ --connect-timeout 15 --max-time 300 --retry 2 --max-filesize "$3" \ --header 'Cache-Control: no-cache' --output "$2" "$1" || fail 'Download failed. No binary was installed.' } verify_release() { # The reviewed installer pins one signer. Fetch its current version range each # time, so a later revocation also reaches copies of this installer. download 'https://getrdy.dev/release-keys/versions.txt' "$work_dir/versions" 65536 LC_ALL=C awk -v version="$version" -v pin="$release_key_fingerprint" ' function minor(n) {return n ~ /^[1-9][0-9]*$/ && length(n) <= 10 && n + 0 <= 4294967295} BEGIN { if (split(version, v, /[.]/) != 3 || v[1] != "0" || !minor(v[2]) || v[3] != "0") exit 1 } { if (NF != 5 || $0 != $1 " " $2 " " $3 " " $4 " " $5 || !minor($1) || ($2 != "*" && (!minor($2) || $2+0 < $1+0)) || open_ended || $1+0 <= previous || ($3 != "ssh-ed25519" && $3 != "sk-ssh-ed25519@openssh.com") || $4 !~ /^[A-Za-z0-9+\/]+=*$/ || $5 !~ /^SHA256:[A-Za-z0-9+\/]+$/ || length($5) != 50) { invalid = 1; exit } open_ended = ($2 == "*"); previous = $2 + 0 if (v[2]+0 >= $1+0 && (open_ended || v[2]+0 <= $2+0)) { matches++; if ($5 != pin) {invalid = 1; exit} print $3 " " $4 } } END {if (invalid || matches != 1) exit 1} ' "$work_dir/versions" > "$work_dir/signer.pub" || fail 'Release signer is unavailable, changed, or revoked.' fingerprint=$(ssh-keygen -E sha256 -lf "$work_dir/signer.pub" | awk 'NR == 1 {print $2}') [ "$fingerprint" = "$release_key_fingerprint" ] || fail 'Release signer fingerprint mismatch.' IFS= read -r signer < "$work_dir/signer.pub" || fail 'Missing release signer.' printf 'rdy-release namespaces="rdy-release-v1" %s\n' "$signer" > "$work_dir/allowed-signers" download "$release_url/SHA256SUMS" "$work_dir/SHA256SUMS" 8192 download "$release_url/SHA256SUMS.sig" "$work_dir/SHA256SUMS.sig" 8192 ssh-keygen -Y verify -f "$work_dir/allowed-signers" -I rdy-release -n rdy-release-v1 \ -s "$work_dir/SHA256SUMS.sig" < "$work_dir/SHA256SUMS" || fail 'Release signature verification failed.' LC_ALL=C awk -v version="$version" -v prefix="rdy-$version-" -v archive="$archive" -v pin="$checksum" ' BEGIN {split(version, v, /[.]/); sample = (v[1]+0 > 0 || v[2]+0 >= 48)} { name = $2 if (NF != 2 || length($1) != 64 || $1 !~ /^[0-9a-f]+$/ || $0 != $1 " " name || (name != prefix "aarch64-apple-darwin.tar.gz" && name != prefix "x86_64-unknown-linux-gnu.tar.gz" && name != prefix "x86_64-pc-windows-msvc.tar.gz" && !(sample && name == "tally.rdydump")) || seen[name]++) {invalid = 1; exit} if (name == archive && $1 == pin) matched = 1 } END {if (invalid || NR != 3 + sample || !matched) exit 1} ' "$work_dir/SHA256SUMS" || fail 'Signed release manifest mismatch.' } main() { version=0.61.0 release_key_fingerprint='SHA256:Tj8hfra0U07asaeSZkt1b5e1HGJ+w8vMzLrn+G6/+/M' assume_yes=no modify_path=yes install_dir=${RDY_INSTALL_DIR:-"${HOME:?HOME must be set}/.local/bin"} work_dir='' staged_binary='' while [ "$#" -gt 0 ]; do case "$1" in --yes|-y) assume_yes=yes ;; --no-modify-path) modify_path=no ;; --install-dir) [ "$#" -ge 2 ] || fail '--install-dir needs an absolute directory.' install_dir=$2; shift ;; --help|-h) printf '%s\n' 'Install rdy 0.61.0 (macOS Apple Silicon or Linux x86_64).' \ 'Usage: sh install.sh [--yes] [--no-modify-path] [--install-dir /absolute/path]' \ ' --yes Accept installation and PATH setup without prompts.' \ ' --no-modify-path Leave shell startup files unchanged.' \ ' --install-dir Install directory (default: $HOME/.local/bin).' \ 'RDY_INSTALL_DIR also sets the install directory. No sudo is used.' return 0 ;; *) fail "Unknown option: $1 (use --help)." ;; esac shift done case "$install_dir" in /*) ;; *) fail 'Install directory must be an absolute path.' ;; esac # PATH and shell startup files cannot represent these directory names safely. case "$install_dir" in *:*) fail 'Install directory cannot contain a colon.' ;; esac case "$install_dir" in *' '*) fail 'Install directory cannot contain a newline.' ;; esac for tool in uname curl tar mktemp install mkdir mv rm sed awk grep ssh-keygen; do command -v "$tool" >/dev/null 2>&1 || fail "Required command is missing: $tool" done platform=$(uname -s) architecture=$(uname -m) case "$platform/$architecture" in Darwin/arm64|Darwin/aarch64) target=aarch64-apple-darwin checksum=2ce57363e3f4be18bcbddbf30a1cee2d8616f2d7ad8232315fa68b8dfd4d654a platform_name='macOS Apple Silicon' ;; Linux/x86_64|Linux/amd64) target=x86_64-unknown-linux-gnu checksum=471f39c3c4c2c50ede70e2cd6f998d5c00013705f58912c3e2e5b2805ff05689 platform_name='Linux x86_64 (glibc)' ;; *) fail "No download for $platform/$architecture. Supported: macOS Apple Silicon and Linux x86_64 (glibc). See https://github.com/adrenickchrome/rdy-core/releases/tag/v$version" ;; esac if command -v sha256sum >/dev/null 2>&1; then hash_tool=sha256sum elif command -v shasum >/dev/null 2>&1; then hash_tool=shasum else fail 'SHA-256 verification needs sha256sum or shasum.' fi if [ "$assume_yes" = no ]; then if ( : <>/dev/tty ) 2>/dev/null; then exec 3<>/dev/tty else fail 'An interactive terminal is required. For unattended installation, use: curl -fsSL https://getrdy.dev/install.sh | sh -s -- --yes' fi fi printf '\nrdy %s\nPlatform: %s\nInstall to: %s/rdy\n\n' "$version" "$platform_name" "$install_dir" printf '%s\n' 'Release 1: later rdy versions read every dump this version writes.' if [ -e "$install_dir/rdy" ]; then printf '%s\n' 'An existing rdy binary will be replaced. Your projects are left unchanged.' \ 'If a preview project is refused with E_STORE_FORMAT, use the old binary to dump it first.' \ 'If an old daemon runs, use rdy serve --stop in that project once.' \ 'For previews older than 0.35.0, stop old sessions and daemons first.' \ 'Use the old binary to run: rdy dump --out /path/to/project.dump' \ 'Keep the old binary and project. Load the dump into a new directory with no store:' \ 'rdy load /path/to/project.dump /path/to/new-project' \ 'Then check the new project with rdy fsck.' \ 'Historical migration guide: https://github.com/adrenickchrome/rdy-core/releases/tag/v0.35.0' fi if ! confirm 'Install rdy?'; then printf '%s\n' 'Cancelled. No changes made.'; return 0; fi trap cleanup 0 trap 'exit 130' INT trap 'exit 143' HUP TERM work_dir=$(mktemp -d "${TMPDIR:-/tmp}/rdy-install.XXXXXXXX") archive="rdy-$version-$target.tar.gz" printf '\nDownloading %s...\n' "$archive" release_url="https://github.com/adrenickchrome/rdy-core/releases/download/v$version" verify_release download "$release_url/$archive" "$work_dir/$archive" 536870912 if [ "$hash_tool" = sha256sum ]; then actual=$(sha256sum "$work_dir/$archive" | awk '{print $1}') else actual=$(shasum -a 256 "$work_dir/$archive" | awk '{print $1}') fi [ "$actual" = "$checksum" ] || fail 'Download checksum mismatch. No binary was installed.' printf '%s\n' 'SHA-256 verified.' # Extract only the expected binary from the verified, version-pinned archive. tar -xzf "$work_dir/$archive" -C "$work_dir" "rdy-$version-$target/rdy" || fail 'Could not extract rdy.' binary="$work_dir/rdy-$version-$target/rdy" [ -f "$binary" ] && [ ! -L "$binary" ] || fail 'Release archive does not contain the expected binary.' installed_version=$("$binary" --version) || fail 'This binary could not run. Linux requires a compatible glibc system; Alpine/musl is unsupported.' [ "$installed_version" = "rdy $version" ] || fail "Unexpected binary version: $installed_version" mkdir -p "$install_dir" || fail "Cannot create $install_dir. Choose a writable --install-dir." [ ! -d "$install_dir/rdy" ] || fail "A directory already exists at $install_dir/rdy." staged_binary=$(mktemp "$install_dir/.rdy-install.XXXXXXXX") install -m 755 "$binary" "$staged_binary" mv -f "$staged_binary" "$install_dir/rdy" staged_binary='' printf '\nInstalled %s to %s/rdy\n' "$installed_version" "$install_dir" # Quote the directory as data before including it in a shell startup file. quoted_dir=$(printf '%s' "$install_dir" | sed "s/'/'\\\\''/g") path_line="export PATH='$quoted_dir':\"\$PATH\"" case ":${PATH:-}:" in *":$install_dir:"*) path_needed=no ;; *) path_needed=yes ;; esac profile='' case "${SHELL:-}" in */zsh) profile="${ZDOTDIR:-$HOME}/.zshrc" ;; */bash) if [ "$platform" = Darwin ]; then profile="$HOME/.bash_profile"; else profile="$HOME/.bashrc"; fi ;; esac if [ "$path_needed" = yes ] && [ "$modify_path" = yes ] && [ -n "$profile" ]; then if [ -e "$profile" ] && [ ! -f "$profile" ]; then printf '\nCannot update %s: it is not a regular file.\n' "$profile" elif [ -f "$profile" ] && grep -F -x -q "$path_line" "$profile"; then printf '\nPATH is already configured in %s.\n' "$profile" elif confirm "Add $install_dir to PATH in $profile?"; then if (printf '\n# rdy command-line tool\n%s\n' "$path_line" >> "$profile"); then printf 'Updated %s.\n' "$profile" else printf 'Could not update %s. Add the PATH line below manually.\n' "$profile" >&2 fi fi fi if [ "$path_needed" = yes ]; then printf '\nTo use rdy in this terminal, run:\n\n %s\n' "$path_line" printf '\nRun the command above now, or open a new terminal if you accepted PATH setup.\n' fi printf '\nNext: rdy init ~/my-design\nThen connect your agent: https://getrdy.dev/#connect\n' } # Keep execution after the complete script, so an interrupted script download # cannot begin installing from a partially received function definition. main "$@"