#!/usr/bin/env sh set -eu APP="resh" BASE_URL="${RESH_BASE_URL:-https://get.reshshell.dev}" VERSION="${RESH_VERSION:-0.9.1}" fatal() { echo "ERROR: $*" >&2; exit 1; } info() { echo "INFO: $*" >&2; } need() { command -v "$1" >/dev/null 2>&1 || fatal "Missing dependency: $1"; } need uname need curl need mktemp need tar OS="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m)" [ "$OS" = "linux" ] || fatal "This installer supports Linux only (detected: $OS)" case "$ARCH" in x86_64|amd64) ARCH_TOKEN="x86_64" ;; aarch64|arm64) ARCH_TOKEN="aarch64" ;; # adjust if your artifacts differ armv7l) ARCH_TOKEN="armv7l" ;; *) fatal "Unsupported architecture: $ARCH" ;; esac ASSET="${APP}-${VERSION}-${OS}-${ARCH_TOKEN}.tar.gz" url_exists() { curl -fsSIL "$1" >/dev/null 2>&1; } pick_asset_url() { u1="${BASE_URL}/releases/${VERSION}/${ASSET}" u2="${BASE_URL}/releases/${ASSET}" u3="${BASE_URL}/releases/latest/${ASSET}" if url_exists "$u1"; then echo "$u1"; return 0; fi if url_exists "$u2"; then echo "$u2"; return 0; fi if url_exists "$u3"; then echo "$u3"; return 0; fi fatal "Release artifact not found (404). Tried: - $u1 - $u2 - $u3" } URL="$(pick_asset_url)" SHA_URL="${URL}.sha256" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT info "Downloading: $URL" curl -fL "$URL" -o "$TMP/$ASSET" # Optional checksum verify if available if command -v sha256sum >/dev/null 2>&1; then if curl -fsSL "$SHA_URL" -o "$TMP/$ASSET.sha256" 2>/dev/null; then info "Verifying checksum..." ( cd "$TMP" HASH="$(awk '{print $1}' "$ASSET.sha256" | head -n1)" [ -n "${HASH:-}" ] || fatal "Invalid checksum file" echo "${HASH} ${ASSET}" > "${ASSET}.sha256.check" sha256sum -c "${ASSET}.sha256.check" ) else info "No checksum found; skipping verification." fi fi # Extract into a dedicated directory EXTRACT_DIR="$TMP/extract" mkdir -p "$EXTRACT_DIR" tar -xzf "$TMP/$ASSET" -C "$EXTRACT_DIR" # --- FIX: Find the binary inside the archive --- # Prefer an executable file named exactly "resh" BIN_PATH="$(find "$EXTRACT_DIR" -type f -name "$APP" -perm -111 2>/dev/null | head -n 1 || true)" # If not found, try any file named "resh" (some archives ship without exec bit) if [ -z "${BIN_PATH:-}" ]; then BIN_PATH="$(find "$EXTRACT_DIR" -type f -name "$APP" 2>/dev/null | head -n 1 || true)" fi # If still not found, show a helpful listing for debugging if [ -z "${BIN_PATH:-}" ]; then info "Archive contents (top 50 files):" find "$EXTRACT_DIR" -maxdepth 4 -type f | head -n 50 >&2 fatal "Archive did not contain a file named: $APP" fi info "Found binary at: $BIN_PATH" chmod +x "$BIN_PATH" DEST="/usr/local/bin/$APP" # Install (requires root) if [ "$(id -u)" -eq 0 ]; then install -m 0755 "$BIN_PATH" "$DEST" else need sudo sudo install -m 0755 "$BIN_PATH" "$DEST" fi info "Installed $APP to $DEST" "$DEST" --version || true echo "Done."