#!/bin/sh # SBX Connect bootstrap (download only). Read it before you run it. # 1. Detects your OS/CPU and downloads the matching SBX Connect file from connect.sbx360.com. # 2. Verifies its SHA-256 against the release manifest (and against --sha256 if you pass one). # 3. Saves it to ~/.sbx-connect/bin and makes it executable. Nothing else is touched. # It never installs a service, never uses sudo/admin, never runs the downloaded file. # Uninstall: delete the folder ~/.sbx-connect. Help: sh install.sh --help set -eu BASE_URL="https://connect.sbx360.com" VERSION="" EXPECT_SHA="" TOOL="sbx-connect" DRY_RUN=0 say() { printf '%s\n' "$*"; } die() { printf 'error: %s\n' "$*" >&2; exit 1; } usage() { cat <<'USAGE' Usage: install.sh [--version X.Y.Z] [--sha256 HEX] [--tool sbx-connect|sbx-sap-test] [--base-url URL] [--dry-run] --version pin a release (default: latest) --sha256 expected hash obtained out-of-band (phone/chat); refuse on mismatch --tool which file to fetch (default sbx-connect) --base-url https only (http://localhost allowed for testing) --dry-run show what would happen; download only the manifest USAGE } while [ $# -gt 0 ]; do case "$1" in --version) [ $# -ge 2 ] || die "--version needs a value"; VERSION="$2"; shift 2 ;; --sha256) [ $# -ge 2 ] || die "--sha256 needs a value"; EXPECT_SHA="$2"; shift 2 ;; --tool) [ $# -ge 2 ] || die "--tool needs a value"; TOOL="$2"; shift 2 ;; --base-url) [ $# -ge 2 ] || die "--base-url needs a value"; BASE_URL="$2"; shift 2 ;; --dry-run) DRY_RUN=1; shift ;; -h|--help) usage; exit 0 ;; *) usage >&2; die "unknown argument: $1" ;; esac done BASE_URL="${BASE_URL%/}" case "$BASE_URL" in https://*) ;; http://localhost|http://localhost:*|http://localhost/*|http://127.0.0.1|http://127.0.0.1:*|http://127.0.0.1/*) ;; *) die "--base-url must be https (or http://localhost for testing)" ;; esac case "$TOOL" in sbx-connect|sbx-sap-test) ;; *) die "--tool must be sbx-connect or sbx-sap-test" ;; esac if [ -n "$VERSION" ]; then printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$' || die "invalid --version" fi if [ -n "$EXPECT_SHA" ]; then EXPECT_SHA="$(printf '%s' "$EXPECT_SHA" | tr 'A-F' 'a-f')" printf '%s' "$EXPECT_SHA" | grep -Eq '^[0-9a-f]{64}$' || die "--sha256 must be 64 hex characters" fi # --- platform --- case "$(uname -s)" in Linux) OS="linux" ;; Darwin) OS="darwin" ;; *) die "unsupported OS $(uname -s). On Windows use install.ps1." ;; esac case "$(uname -m)" in x86_64|amd64) ARCH="amd64" ;; aarch64|arm64) ARCH="arm64" ;; *) die "unsupported CPU $(uname -m)" ;; esac NAME="$TOOL-$OS-$ARCH" # --- tools --- if command -v curl >/dev/null 2>&1; then fetch() { curl --fail --silent --show-error --location --proto '=https,http' --proto-redir '=https,http' --max-time 300 --output "$2" "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget --quiet --output-document="$2" "$1"; } else die "need curl or wget" fi if command -v sha256sum >/dev/null 2>&1; then hash_of() { sha256sum "$1" | cut -d ' ' -f 1; } elif command -v shasum >/dev/null 2>&1; then hash_of() { shasum -a 256 "$1" | cut -d ' ' -f 1; } elif command -v openssl >/dev/null 2>&1; then hash_of() { openssl dgst -sha256 "$1" | sed 's/^.*= *//'; } else die "need sha256sum, shasum or openssl" fi DEST_DIR="${HOME:?HOME is not set}/.sbx-connect/bin" TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/sbx-connect.XXXXXX")" trap 'rm -rf "$TMP_DIR"' EXIT INT TERM # --- manifest --- if [ -n "$VERSION" ]; then MANIFEST_URL="$BASE_URL/releases/$VERSION/manifest.json" else MANIFEST_URL="$BASE_URL/releases/latest/manifest.json" fi say "Fetching manifest: $MANIFEST_URL" fetch "$MANIFEST_URL" "$TMP_DIR/manifest.json" || die "could not download the manifest" REL_VERSION="$(sed -n 's/^ *"version": *"\([^"]*\)".*/\1/p' "$TMP_DIR/manifest.json" | head -n 1)" printf '%s' "$REL_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$' || die "manifest has no valid version" if [ -n "$VERSION" ] && [ "$VERSION" != "$REL_VERSION" ]; then die "manifest version $REL_VERSION does not match requested $VERSION"; fi ENTRY="$(grep -F "\"name\":\"$NAME\"" "$TMP_DIR/manifest.json" | head -n 1 || true)" [ -n "$ENTRY" ] || die "release $REL_VERSION has no file $NAME for this computer" MANIFEST_SHA="$(printf '%s' "$ENTRY" | sed -n 's/.*"sha256":"\([0-9a-f]\{64\}\)".*/\1/p')" [ -n "$MANIFEST_SHA" ] || die "manifest entry for $NAME has no valid sha256" # The URL is built from the version and the file name we computed, never taken from the manifest. FILE_URL="$BASE_URL/releases/$REL_VERSION/$NAME" TARGET="$DEST_DIR/$NAME" say "Release: $REL_VERSION" say "File: $NAME" say "Manifest sha256: $MANIFEST_SHA" say "Source: $FILE_URL" say "Target: $TARGET" if [ "$DRY_RUN" -eq 1 ]; then say "Dry run: nothing downloaded or written." exit 0 fi # --- download + verify --- mkdir -p "$DEST_DIR" chmod 700 "$HOME/.sbx-connect" 2>/dev/null || true PART="$TMP_DIR/$NAME" say "Downloading..." fetch "$FILE_URL" "$PART" || die "download failed" GOT="$(hash_of "$PART")" say "Computed sha256: $GOT" if [ "$GOT" != "$MANIFEST_SHA" ]; then die "sha256 does not match the manifest. File discarded." fi if [ -n "$EXPECT_SHA" ]; then [ "$GOT" = "$EXPECT_SHA" ] || die "sha256 does not match the value you passed (--sha256). File discarded." say "Matches the value you passed." else say "Tip: compare this hash with the one your SBX360 contact gives you by phone or chat (--sha256)." fi chmod 755 "$PART" if [ "$OS" = "darwin" ] && command -v xattr >/dev/null 2>&1; then xattr -d com.apple.quarantine "$PART" 2>/dev/null || true fi mv -f "$PART" "$TARGET" say "" say "Saved: $TARGET" say "Run it: \"$TARGET\"" say "Uninstall: rm -rf \"$HOME/.sbx-connect\""