#!/usr/bin/env bash set -e REPO="yunyingk/seal-home" echo "==> Detecting platform and architecture..." OS="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m)" case "$OS" in darwin) PLATFORM="darwin" ;; linux) PLATFORM="linux" ;; *) echo "Unsupported operating system: $OS" >&2 exit 1 ;; esac case "$ARCH" in x86_64|amd64) ARCH_NAME="x64" ;; arm64|aarch64) ARCH_NAME="arm64" ;; *) echo "Unsupported architecture: $ARCH" >&2 exit 1 ;; esac # Resolve best writable bin directory without requiring sudo TARGET_DIR="" for candidate in "/opt/homebrew/bin" "/usr/local/bin" "$HOME/.local/bin" "$HOME/bin"; do if [ -d "$candidate" ] && [ -w "$candidate" ]; then TARGET_DIR="$candidate" break fi done if [ -z "$TARGET_DIR" ]; then mkdir -p "$HOME/.local/bin" TARGET_DIR="$HOME/.local/bin" fi ASSET_NAME="seal-home-${PLATFORM}-${ARCH_NAME}" TARGET_PATH="${TARGET_DIR}/seal-home" echo "==> Downloading seal-home (${PLATFORM}-${ARCH_NAME}) into ${TARGET_DIR}..." TMP_FILE="$(mktemp)" DOWNLOAD_SUCCESS=false # Multi-source candidate mirrors GITEA_BASE="https://git.ying-qing.cn/gitea/seal-home" GITHUB_BASE="https://github.com/${REPO}" GHPROXY_BASE="https://ghfast.top/https://github.com/${REPO}" # 1. Check Gitea mirror if responsive if [ "${SEAL_HOME_MIRROR:-auto}" = "gitea" ] || [ "${SEAL_HOME_MIRROR:-auto}" = "auto" ]; then if curl -s --connect-timeout 2 -I "https://git.ying-qing.cn" >/dev/null 2>&1; then GITEA_URL="${GITEA_BASE}/releases/download/latest/${ASSET_NAME}" if curl -fL --connect-timeout 4 "$GITEA_URL" -o "$TMP_FILE" 2>/dev/null; then echo "✓ Downloaded from high-speed mirror (git.ying-qing.cn)" DOWNLOAD_SUCCESS=true fi fi fi # 2. Try direct GitHub if [ "$DOWNLOAD_SUCCESS" = "false" ]; then GITHUB_URL="${GITHUB_BASE}/releases/latest/download/${ASSET_NAME}" if curl -fL --connect-timeout 6 "$GITHUB_URL" -o "$TMP_FILE" 2>/dev/null; then echo "✓ Downloaded from GitHub Releases" DOWNLOAD_SUCCESS=true fi fi # 3. Fallback to GitHub CDN proxy if [ "$DOWNLOAD_SUCCESS" = "false" ]; then GHPROXY_URL="${GHPROXY_BASE}/releases/latest/download/${ASSET_NAME}" echo "==> Trying CDN fallback mirror..." if curl -fL "$GHPROXY_URL" -o "$TMP_FILE" 2>/dev/null; then echo "✓ Downloaded from CDN mirror" DOWNLOAD_SUCCESS=true fi fi if [ "$DOWNLOAD_SUCCESS" = "false" ]; then echo "Error: Failed to download ${ASSET_NAME} from any available mirror." >&2 rm -f "$TMP_FILE" exit 1 fi chmod +x "$TMP_FILE" mv "$TMP_FILE" "$TARGET_PATH" # Ad-hoc sign on macOS if [ "$PLATFORM" = "darwin" ] && command -v codesign >/dev/null 2>&1; then codesign --force --sign - "$TARGET_PATH" 2>/dev/null || true fi echo "==> Initializing agent skill..." "$TARGET_PATH" skill install >/dev/null 2>&1 || true echo "" echo "✨ seal-home successfully installed to ${TARGET_PATH}!" "$TARGET_PATH" version echo "" echo "Quick start:" echo " 1. Add enterprise: seal-home corps add-hose --json '{...}'" echo " 2. View MCP config: seal-home mcp-config" echo " 3. Self-update: seal-home update" echo ""