#!/bin/sh set -eu BASE="https://stet.fyi" sanitize() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | tr -cd '[:lower:][:digit:]'; } os="$(uname -s)" case "$os" in Linux) os=linux ;; Darwin) os=darwin ;; MINGW*|MSYS*|CYGWIN*) os=windows ;; *) os="$(sanitize "$os")" ;; esac arch="$(uname -m)" case "$arch" in x86_64|amd64) arch=amd64 ;; aarch64|arm64) arch=arm64 ;; armv6l|armv7l|armv8l) arch=arm ;; i386|i686) arch=386 ;; *) arch="$(sanitize "$arch")" ;; esac if [ "$os" = "darwin" ] && [ "$arch" = "amd64" ]; then if [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = "1" ]; then arch=arm64; fi fi if [ "$os" = "windows" ]; then machine_arch="$(MSYS2_ARG_CONV_EXCL='*' reg query 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' /v PROCESSOR_ARCHITECTURE 2>/dev/null | tr -d '\r' | awk '/PROCESSOR_ARCHITECTURE/ { print $NF }' || true)" case "$machine_arch" in ARM64) arch=arm64 ;; AMD64) arch=amd64 ;; esac fi ext="" [ "$os" = "windows" ] && ext=".exe" dest_dir="$HOME/.local/bin" dest="$dest_dir/stet$ext" tmp="$dest.tmp" url="$BASE/cli/stet/$os-$arch$ext" mkdir -p "$dest_dir" rm -f "$tmp" echo "installing $url -> $dest" code="$(curl -sSL --compressed -w '%{http_code}' -o "$tmp" "$url")" || code=000 if [ "$code" != "200" ]; then echo "install.sh: download failed (HTTP $code) for $os-$arch" >&2 case "$code" in 4??|5??) if [ -s "$tmp" ]; then { head -c 2000 "$tmp" | tr -cd '[:print:]\t\n'; echo; } >&2; fi ;; esac rm -f "$tmp" exit 1 fi rm -f "$dest" mv "$tmp" "$dest" chmod +x "$dest" case ":$PATH:" in *":$dest_dir:"*) : ;; *) echo "note: $dest_dir is not on PATH — add: export PATH=\"\$HOME/.local/bin:\$PATH\"" ;; esac found="$(command -v stet 2>/dev/null || true)" if [ -n "$found" ] && [ "$found" != "$dest" ] && [ "$found" != "$dest_dir/stet" ]; then echo "warning: $found comes first on PATH and shadows $dest — remove it or put $dest_dir first on PATH" >&2 fi printf 'installed stet ' "$dest" version