#!/bin/sh # Public CLI bootstrap. Release automation publishes the version, archive and # checksum together only after the matching CLI package has passed qualification. set -eu umask 077 fail() { printf 'eden installer: %s\n' "$*" >&2; exit 1; } for tool in curl tar mktemp uname; do command -v "$tool" >/dev/null 2>&1 || fail "$tool is required" done case "$(uname -s)" in Linux) os=linux ;; Darwin) os=darwin ;; *) fail 'supported systems are Linux and macOS' ;; esac case "$(uname -m)" in x86_64|amd64) arch=amd64 ;; arm64|aarch64) arch=arm64 ;; *) fail 'supported CPU architectures are amd64 and arm64' ;; esac platform="$os-$arch" base=https://eden.dev/eden/releases download() { curl --proto '=https' --tlsv1.2 --fail --silent --show-error \ --connect-timeout 15 --max-time 300 "$1" -o "$2" } work=$(mktemp -d "${TMPDIR:-/tmp}/eden-install.XXXXXXXX") install_tmp= cleanup() { rm -rf "$work" if [ -n "$install_tmp" ]; then rm -f "$install_tmp"; fi } trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM download "$base/latest/VERSION" "$work/VERSION" || fail 'no qualified CLI release is available' # Keep release markers to one stable SemVer line with three canonical decimal # components of at most nine digits, matching the public Worker archive paths. [ "$(wc -c < "$work/VERSION")" -le 30 ] || fail 'invalid release version' version=$(LC_ALL=C awk ' NR == 1 && /^(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})$/ { print; next } { exit 1 } END { if (NR != 1) exit 1 } ' "$work/VERSION") || fail 'invalid release version' archive="$base/$version/$platform/eden-cli.tar.gz" download "$archive.sha256" "$work/checksum" || fail "CLI $version is not published for $platform" expected=$(cat "$work/checksum") [ "${#expected}" -eq 64 ] || fail 'invalid checksum metadata' case "$expected" in *[!0-9a-f]*) fail 'invalid checksum metadata' ;; esac download "$archive" "$work/eden-cli.tar.gz" || fail 'CLI download failed' if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$work/eden-cli.tar.gz") elif command -v shasum >/dev/null 2>&1; then actual=$(shasum -a 256 "$work/eden-cli.tar.gz") else fail 'sha256sum or shasum is required' fi actual=${actual%% *} [ "$actual" = "$expected" ] || fail 'CLI checksum mismatch; nothing was installed' # Extract only the expected file into a private directory; ignore archive paths. tar -xzOf "$work/eden-cli.tar.gz" eden > "$work/eden" || fail 'invalid CLI archive' chmod 700 "$work/eden" [ "$("$work/eden" --version)" = "eden $version" ] || fail 'CLI version or platform check failed' destination=${EDEN_INSTALL_DIR:-${HOME:?HOME or EDEN_INSTALL_DIR is required}/.local/bin} case "$destination" in /*) ;; *) fail 'EDEN_INSTALL_DIR must be an absolute path' ;; esac mkdir -p "$destination" [ ! -d "$destination/eden" ] || fail 'installation target is a directory' install_tmp=$(mktemp "$destination/.eden-install.XXXXXXXX") cat "$work/eden" > "$install_tmp" chmod 755 "$install_tmp" mv -f "$install_tmp" "$destination/eden" install_tmp= printf 'Installed Eden CLI %s at %s/eden\n' "$version" "$destination" case ":${PATH:-}:" in *":$destination:"*) ;; *) printf 'Add this directory to PATH: %s\n' "$destination" ;; esac printf 'Next: eden login\nThen: eden image pull\n'