#!/bin/sh set -e VERSION="${SHARK_VERSION:-v0.1.0}" REPO="shark-auth/shark" BIN_NAME="shark" say() { printf '%s\n' "$*" } err() { printf 'Error: %s\n' "$*" >&2 exit 1 } need_cmd() { command -v "$1" >/dev/null 2>&1 || err "$1 is required" } OS_RAW="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH_RAW="$(uname -m | tr '[:upper:]' '[:lower:]')" case "$OS_RAW" in linux*) OS="linux"; EXT="tar.gz" ;; darwin*) OS="darwin"; EXT="tar.gz" ;; mingw*|msys*|cygwin*) OS="windows"; EXT="zip"; BIN_NAME="shark.exe" ;; *) err "unsupported OS: $OS_RAW. Download manually from https://github.com/${REPO}/releases/tag/${VERSION}" ;; esac case "$ARCH_RAW" in x86_64|amd64) ARCH="x86_64" ;; arm64|aarch64) ARCH="arm64" ;; *) err "unsupported architecture: $ARCH_RAW" ;; esac need_cmd curl if [ "$EXT" = "tar.gz" ]; then need_cmd tar fi ASSET="shark_${OS}_${ARCH}.${EXT}" BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}" URL="${BASE_URL}/${ASSET}" CHECKSUMS_URL="${BASE_URL}/checksums.txt" if [ -n "$SHARK_INSTALL_DIR" ]; then INSTALL_DIR="$SHARK_INSTALL_DIR" elif [ "$OS" = "windows" ]; then INSTALL_DIR="$HOME/.local/bin" elif [ -w "/usr/local/bin" ]; then INSTALL_DIR="/usr/local/bin" else INSTALL_DIR="$HOME/.local/bin" fi TMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t shark)" trap 'rm -rf "$TMP_DIR"' EXIT INT TERM say "--- SharkAuth Installer ---" say "Version: ${VERSION}" say "System: ${OS}/${ARCH}" say "Install dir: ${INSTALL_DIR}" say "" say "Downloading ${ASSET}..." curl -fL --retry 3 --retry-delay 2 --connect-timeout 10 -o "$TMP_DIR/$ASSET" "$URL" say "Downloading checksums..." curl -fL --retry 3 --retry-delay 2 --connect-timeout 10 -o "$TMP_DIR/checksums.txt" "$CHECKSUMS_URL" say "Verifying checksum..." EXPECTED="$(grep " ${ASSET}$" "$TMP_DIR/checksums.txt" | awk '{print $1}')" [ -n "$EXPECTED" ] || err "checksum for ${ASSET} not found" if command -v sha256sum >/dev/null 2>&1; then ACTUAL="$(sha256sum "$TMP_DIR/$ASSET" | awk '{print $1}')" elif command -v shasum >/dev/null 2>&1; then ACTUAL="$(shasum -a 256 "$TMP_DIR/$ASSET" | awk '{print $1}')" else err "sha256sum or shasum is required to verify the download" fi [ "$EXPECTED" = "$ACTUAL" ] || err "checksum mismatch" say "Extracting..." if [ "$EXT" = "zip" ]; then if command -v unzip >/dev/null 2>&1; then unzip -q "$TMP_DIR/$ASSET" -d "$TMP_DIR" elif command -v powershell.exe >/dev/null 2>&1; then powershell.exe -NoProfile -Command "Expand-Archive -LiteralPath '$TMP_DIR/$ASSET' -DestinationPath '$TMP_DIR' -Force" else err "unzip or powershell.exe is required to extract Windows archives" fi else tar -xzf "$TMP_DIR/$ASSET" -C "$TMP_DIR" fi mkdir -p "$INSTALL_DIR" cp "$TMP_DIR/$BIN_NAME" "$INSTALL_DIR/$BIN_NAME" chmod +x "$INSTALL_DIR/$BIN_NAME" say "" say "SharkAuth ${VERSION} installed successfully." say "Binary: ${INSTALL_DIR}/${BIN_NAME}" say "" case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) say "Note: ${INSTALL_DIR} is not on your PATH." say "Add it with:" say " export PATH=\"${INSTALL_DIR}:\$PATH\"" say "" ;; esac say "Start the server:" say " shark serve" say "" say "Show commands:" say " shark --help"