#!/bin/sh # OpenEDK installer — `curl -LsSf https://openedk.com/install.sh | sh` # # Detects OS+arch, downloads the matching prebuilt binary from the OpenEDK # distribution host (openedk.com), drops it into ~/.local/bin (override via # OPENEDK_INSTALL_DIR), and verifies SHA256. # # Env knobs: # OPENEDK_VERSION Version dir to install (default: latest). # OPENEDK_INSTALL_DIR Where to put the binaries (default: ~/.local/bin). # OPENEDK_BASE_URL Override distribution host (default: https://openedk.com/dl). # # Exit codes: # 0 success 1 fatal error 2 unsupported platform set -eu VERSION="${OPENEDK_VERSION:-latest}" INSTALL_DIR="${OPENEDK_INSTALL_DIR:-$HOME/.local/bin}" BASE_URL="${OPENEDK_BASE_URL:-https://openedk.com/dl}" # ── pretty output ────────────────────────────────────────────────────────── if [ -t 1 ]; then BOLD='\033[1m'; DIM='\033[2m'; GREEN='\033[1;32m'; YELLOW='\033[1;33m'; RED='\033[1;31m'; RESET='\033[0m' else BOLD=''; DIM=''; GREEN=''; YELLOW=''; RED=''; RESET='' fi info() { printf '%b\n' "${DIM}→${RESET} $*"; } ok() { printf '%b\n' "${GREEN}✓${RESET} $*"; } warn() { printf '%b\n' "${YELLOW}!${RESET} $*" >&2; } die() { printf '%b\n' "${RED}✗${RESET} $*" >&2; exit 1; } # ── detect platform ──────────────────────────────────────────────────────── OS="$(uname -s | tr '[:upper:]' '[:lower:]')" case "$OS" in darwin) OS="darwin" ;; linux) OS="linux" ;; *) die "unsupported OS: $OS (only darwin/linux supported)" ;; esac ARCH="$(uname -m)" case "$ARCH" in x86_64|amd64) ARCH="amd64" ;; aarch64|arm64) ARCH="arm64" ;; *) die "unsupported arch: $ARCH (only amd64/arm64 supported)" ;; esac TARGET="${OS}-${ARCH}" info "detected platform: ${BOLD}${TARGET}${RESET}" BASE="${BASE_URL}/${VERSION}" info "fetching from: ${DIM}${BASE}${RESET}" # ── download helpers ────────────────────────────────────────────────────── have() { command -v "$1" >/dev/null 2>&1; } # Prefer curl; fall back to wget so the install line works in stripped-down # Linux base images (Alpine + busybox + wget, no curl). if have curl; then DL='curl -fLsS --retry 3' DL_OUT='-o' elif have wget; then DL='wget -q --tries=3' DL_OUT='-O' else die "neither curl nor wget found" fi # ── install ─────────────────────────────────────────────────────────────── mkdir -p "$INSTALL_DIR" || die "cannot create install dir: $INSTALL_DIR" TMPDIR="$(mktemp -d)" trap 'rm -rf "$TMPDIR"' EXIT for bin in openedk openedk-mcp; do url="${BASE}/${bin}-${TARGET}" info "downloading ${BOLD}${bin}${RESET}" if ! $DL $DL_OUT "${TMPDIR}/${bin}" "$url"; then die "download failed: $url No prebuilt ${TARGET} binary for version '${VERSION}'. Build from source: git clone https://github.com/jeremy0612/OpenEDK.git && cd OpenEDK && make build" fi chmod +x "${TMPDIR}/${bin}" done # ── verify checksums ─────────────────────────────────────────────────────── if $DL $DL_OUT "${TMPDIR}/SHA256SUMS" "${BASE}/SHA256SUMS" 2>/dev/null; then info "verifying SHA256" if have sha256sum; then SUM_TOOL='sha256sum' else SUM_TOOL='shasum -a 256' fi for bin in openedk openedk-mcp; do expected="$(grep "${bin}-${TARGET}$" "${TMPDIR}/SHA256SUMS" | awk '{print $1}' || true)" if [ -z "$expected" ]; then warn "no checksum entry for ${bin}-${TARGET}, skipping" continue fi actual="$(cd "$TMPDIR" && $SUM_TOOL "$bin" | awk '{print $1}')" [ "$expected" = "$actual" ] || die "checksum mismatch for $bin (expected $expected got $actual)" done ok "checksums match" else warn "no SHA256SUMS published — skipping verification" fi # ── move into place ─────────────────────────────────────────────────────── for bin in openedk openedk-mcp; do mv -f "${TMPDIR}/${bin}" "${INSTALL_DIR}/${bin}" done ok "installed openedk + openedk-mcp into ${BOLD}${INSTALL_DIR}${RESET}" # ── PATH check ──────────────────────────────────────────────────────────── case ":$PATH:" in *:"$INSTALL_DIR":*) ;; *) warn "${INSTALL_DIR} is NOT on PATH" # $SHELL is often unset in containers / CI; guard against `set -u`. sh_name="${SHELL:-}"; sh_name="${sh_name##*/}" case "$sh_name" in zsh) rcfile="$HOME/.zshrc" ;; bash) rcfile="$HOME/.bashrc" ;; *) rcfile="your shell rc file" ;; esac printf ' add this line to %b%s%b:\n export PATH="%s:$PATH"\n' "$BOLD" "$rcfile" "$RESET" "$INSTALL_DIR" ;; esac # ── next steps ──────────────────────────────────────────────────────────── cat <