- 在 scripts/install.sh 中默认安装至用户目录 ~/.local/bin,并自动清理历史遗留的 /opt/homebrew/bin/seal-use - 在 scripts/dev-override.ts 中优先命中 ~/.local/bin/seal-use,忽略 Homebrew 路径并自动清理残留 - 在 seal-use update 中支持 --system(提权迁移至 /usr/local/bin)与 --user(降权回归至 ~/.local/bin)选项,添加 seal-use migrate 别名 - 迁移与更新时自动清理另一端的非活动实体二进制(恪守 Single Binary Invariant) - 自更新权限预检:当目标位于系统目录且缺少写权限时,友好提示 sudo seal-use update 而非底层报错 - 在 seal-use doctor 中增加执行模式识别与多份二进制(PATH 阴影)检测告警
300 lines
8.8 KiB
Bash
Executable File
300 lines
8.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
REPO="${SEAL_USE_GITHUB_REPO:-${SEAL_HOME_GITHUB_REPO:-yunyingk/seal-use}}"
|
|
REQ_VERSION="${SEAL_USE_VERSION:-${SEAL_HOME_VERSION:-latest}}"
|
|
if [ "$REQ_VERSION" != "latest" ] && [[ "$REQ_VERSION" != v* ]]; then
|
|
REQ_VERSION="v${REQ_VERSION}"
|
|
fi
|
|
|
|
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.
|
|
# SEAL_USE_INSTALL_DIR overrides the search, which also lets the installer be exercised against a
|
|
# scratch directory instead of a real global bin.
|
|
TARGET_DIR="${SEAL_USE_INSTALL_DIR:-${SEAL_HOME_INSTALL_DIR:-}}"
|
|
if [ -n "$TARGET_DIR" ]; then
|
|
mkdir -p "$TARGET_DIR"
|
|
else
|
|
# Default to user directory (~/.local/bin) unless an active writable system command is already in use.
|
|
EXISTING_COMMAND="$(command -v seal-use || true)"
|
|
if [ -n "$EXISTING_COMMAND" ] && [ -f "$EXISTING_COMMAND" ] && [ -w "$(dirname "$EXISTING_COMMAND")" ] && [ "$(dirname "$EXISTING_COMMAND")" != "/opt/homebrew/bin" ]; then
|
|
TARGET_DIR="$(dirname "$EXISTING_COMMAND")"
|
|
else
|
|
for candidate in "$HOME/.local/bin" "$HOME/bin" "/usr/local/bin"; do
|
|
if [ -d "$candidate" ] && [ -w "$candidate" ]; then
|
|
TARGET_DIR="$candidate"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
fi
|
|
|
|
if [ -z "$TARGET_DIR" ]; then
|
|
mkdir -p "$HOME/.local/bin"
|
|
TARGET_DIR="$HOME/.local/bin"
|
|
fi
|
|
|
|
ASSET_NAME="seal-use-${PLATFORM}-${ARCH_NAME}"
|
|
ARCHIVE_NAME="${ASSET_NAME}.tar.gz"
|
|
TARGET_PATH="${TARGET_DIR}/seal-use"
|
|
|
|
get_file_size() {
|
|
local file="$1"
|
|
if [ ! -f "$file" ]; then
|
|
echo "0"
|
|
return
|
|
fi
|
|
local sz
|
|
sz=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || wc -c < "$file" | tr -d ' ')
|
|
echo "$sz"
|
|
}
|
|
|
|
format_bytes() {
|
|
local bytes="$1"
|
|
if [ -z "$bytes" ] || [ "$bytes" -le 0 ]; then
|
|
echo "0 B"
|
|
return
|
|
fi
|
|
if [ "$bytes" -ge 1048576 ]; then
|
|
awk "BEGIN {printf \"%.2f MB (%'d bytes)\", $bytes / 1048576, $bytes}" 2>/dev/null || awk "BEGIN {printf \"%.2f MB (%d bytes)\", $bytes / 1048576, $bytes}"
|
|
elif [ "$bytes" -ge 1024 ]; then
|
|
awk "BEGIN {printf \"%.2f KB (%d bytes)\", $bytes / 1024, $bytes}"
|
|
else
|
|
echo "${bytes} bytes"
|
|
fi
|
|
}
|
|
|
|
extract_host() {
|
|
local url="$1"
|
|
echo "$url" | sed -e 's|^[^/]*//||' -e 's|/.*$||'
|
|
}
|
|
|
|
download_candidate() {
|
|
local url="$1"
|
|
local dest="$2"
|
|
local label="$3"
|
|
local host
|
|
host="$(extract_host "$url")"
|
|
|
|
echo "==> Downloading from ${label}"
|
|
echo " Source Host: ${host}"
|
|
echo " Source URL: ${url}"
|
|
|
|
# Test connectivity & headers first
|
|
if ! curl -fIs --connect-timeout 4 "$url" >/dev/null 2>&1; then
|
|
echo " ↳ Source unreachable or asset not ready (404), falling back to next mirror..."
|
|
return 1
|
|
fi
|
|
|
|
# Download with progress bar (-# / --progress-bar)
|
|
if curl -fL --progress-bar "$url" -o "$dest"; then
|
|
local size_bytes
|
|
size_bytes="$(get_file_size "$dest")"
|
|
if [ "$size_bytes" -gt 1000000 ]; then
|
|
echo "✓ Download complete! Total size: $(format_bytes "$size_bytes")"
|
|
echo "✓ Successfully fetched from host: ${host}"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
rm -f "$dest"
|
|
return 1
|
|
}
|
|
|
|
verify_checksum() {
|
|
local file="$1"
|
|
local asset="$2"
|
|
local checksum_url="$3"
|
|
local tmp_sum
|
|
tmp_sum="$(mktemp)"
|
|
|
|
if curl -fsSL --connect-timeout 4 "$checksum_url" -o "$tmp_sum" 2>/dev/null; then
|
|
local expected_hash
|
|
# Exact filename match, not a regex: `grep seal-use-darwin-arm64` also matches the
|
|
# `seal-use-darwin-arm64.tar.gz` line and `head -n1` then picks the wrong hash.
|
|
expected_hash="$(awk -v name="$asset" '$2 == name { print $1; exit }' "$tmp_sum")"
|
|
if [ -n "$expected_hash" ]; then
|
|
local actual_hash=""
|
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
actual_hash="$(sha256sum "$file" | awk '{print $1}')"
|
|
elif command -v shasum >/dev/null 2>&1; then
|
|
actual_hash="$(shasum -a 256 "$file" | awk '{print $1}')"
|
|
fi
|
|
|
|
if [ -n "$actual_hash" ]; then
|
|
if [ "$actual_hash" = "$expected_hash" ]; then
|
|
echo "✓ Checksum verification passed (SHA-256: ${actual_hash:0:12}...)"
|
|
else
|
|
echo "::warning::Checksum mismatch for ${asset}! Expected: ${expected_hash}, got: ${actual_hash}"
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
rm -f "$tmp_sum"
|
|
}
|
|
|
|
echo "==> Target install location: ${TARGET_PATH}"
|
|
echo "==> Requested version: ${REQ_VERSION}"
|
|
TMP_FILE="$(mktemp)"
|
|
DOWNLOAD_SUCCESS=false
|
|
IS_ARCHIVE=false
|
|
USED_ASSET=""
|
|
|
|
# Candidate mirrors. The compressed archive is preferred over the raw binary: it is about a third
|
|
# of the size (25-39 MB against 67-102 MB), and it is the asset the Gitea mirror publishes first
|
|
# (Tier 1 for darwin-arm64, Tier 2 for the rest). The raw binary stays as a fallback for releases
|
|
# or mirrors that only carry it.
|
|
if [ "$REQ_VERSION" = "latest" ]; then
|
|
GITEA_TAG="latest"
|
|
GH_RELEASE_PATH="latest/download"
|
|
else
|
|
GITEA_TAG="$REQ_VERSION"
|
|
GH_RELEASE_PATH="$REQ_VERSION"
|
|
fi
|
|
|
|
GITEA_BASE="https://git.ying-qing.cn/gitea/seal-use/releases/download/${GITEA_TAG}"
|
|
GITEA_LEGACY_BASE="https://git.ying-qing.cn/gitea/seal-home/releases/download/${GITEA_TAG}"
|
|
GITHUB_BASE="https://github.com/${REPO}/releases/${GH_RELEASE_PATH}"
|
|
GHPROXY_BASE="https://ghfast.top/${GITHUB_BASE}"
|
|
CHECKSUM_URL="https://github.com/${REPO}/releases/${GH_RELEASE_PATH}/checksums.txt"
|
|
|
|
MIRROR_MODE="${SEAL_USE_MIRROR:-${SEAL_HOME_MIRROR:-auto}}"
|
|
|
|
candidate_urls() {
|
|
local name="$1"
|
|
if [ "$MIRROR_MODE" != "github" ]; then
|
|
echo "${GITEA_BASE}/${name}"
|
|
echo "${GITEA_LEGACY_BASE}/${name}"
|
|
fi
|
|
if [ "$MIRROR_MODE" != "gitea" ]; then
|
|
echo "${GITHUB_BASE}/${name}"
|
|
echo "${GHPROXY_BASE}/${name}"
|
|
fi
|
|
}
|
|
|
|
try_asset() {
|
|
local name="$1"
|
|
local url
|
|
while IFS= read -r url; do
|
|
[ -n "$url" ] || continue
|
|
if download_candidate "$url" "$TMP_FILE" "$(extract_host "$url")"; then
|
|
return 0
|
|
fi
|
|
done < <(candidate_urls "$name")
|
|
return 1
|
|
}
|
|
|
|
if try_asset "$ARCHIVE_NAME"; then
|
|
DOWNLOAD_SUCCESS=true
|
|
IS_ARCHIVE=true
|
|
USED_ASSET="$ARCHIVE_NAME"
|
|
elif try_asset "$ASSET_NAME"; then
|
|
DOWNLOAD_SUCCESS=true
|
|
USED_ASSET="$ASSET_NAME"
|
|
fi
|
|
|
|
if [ "$DOWNLOAD_SUCCESS" = "false" ]; then
|
|
echo "Error: Failed to download ${ARCHIVE_NAME} or ${ASSET_NAME} (${REQ_VERSION}) from all candidate mirrors." >&2
|
|
rm -f "$TMP_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
verify_checksum "$TMP_FILE" "$USED_ASSET" "$CHECKSUM_URL"
|
|
|
|
if [ "$IS_ARCHIVE" = "true" ]; then
|
|
EXTRACT_DIR="$(mktemp -d)"
|
|
echo "==> Extracting ${USED_ASSET}..."
|
|
if ! tar -xzf "$TMP_FILE" -C "$EXTRACT_DIR"; then
|
|
echo "Error: failed to extract ${USED_ASSET}." >&2
|
|
rm -rf "$EXTRACT_DIR" "$TMP_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
EXTRACTED="$(find "$EXTRACT_DIR" -type f -name "$(basename "$ASSET_NAME")" -print -quit 2>/dev/null || true)"
|
|
if [ -z "$EXTRACTED" ]; then
|
|
EXTRACTED="$(find "$EXTRACT_DIR" -type f -print -quit 2>/dev/null || true)"
|
|
fi
|
|
if [ -z "$EXTRACTED" ]; then
|
|
echo "Error: ${USED_ASSET} did not contain a seal-use binary." >&2
|
|
rm -rf "$EXTRACT_DIR" "$TMP_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
chmod +x "$EXTRACTED"
|
|
mv "$EXTRACTED" "$TARGET_PATH"
|
|
rm -rf "$EXTRACT_DIR" "$TMP_FILE"
|
|
else
|
|
chmod +x "$TMP_FILE"
|
|
mv "$TMP_FILE" "$TARGET_PATH"
|
|
fi
|
|
|
|
# Ad-hoc sign on macOS
|
|
if [ "$PLATFORM" = "darwin" ] && command -v codesign >/dev/null 2>&1; then
|
|
echo "==> Applying macOS code signature..."
|
|
codesign --force --sign - "$TARGET_PATH" 2>/dev/null || true
|
|
fi
|
|
|
|
# Clean up stale/shadowed Homebrew binaries
|
|
for stale in "/opt/homebrew/bin/seal-use" "/opt/homebrew/bin/seal-home"; do
|
|
if [ -e "$stale" ] || [ -L "$stale" ]; then
|
|
if [ "$stale" != "$TARGET_PATH" ]; then
|
|
if [ -w "$stale" ] || [ -w "$(dirname "$stale")" ]; then
|
|
echo "==> Cleaning up legacy/shadowed Homebrew binary at ${stale}..."
|
|
rm -f "$stale" 2>/dev/null || true
|
|
else
|
|
echo "::warning::Legacy binary found at ${stale}. Remove it with: rm -f ${stale}"
|
|
fi
|
|
fi
|
|
fi
|
|
done
|
|
|
|
# Clean legacy skill to avoid model routing collisions, then install new seal-use skill
|
|
LEGACY_SKILL_DIR="$HOME/.agents/skills/seal-home"
|
|
if [ -e "$LEGACY_SKILL_DIR" ]; then
|
|
echo "==> Removing legacy agent skill at ${LEGACY_SKILL_DIR}..."
|
|
rm -rf "$LEGACY_SKILL_DIR"
|
|
fi
|
|
|
|
echo "==> Initializing agent skill to ~/.agents/skills/seal-use..."
|
|
"$TARGET_PATH" skill install >/dev/null 2>&1 || true
|
|
echo "✓ Agent skill installed to ~/.agents/skills/seal-use"
|
|
|
|
echo ""
|
|
echo "✨ seal-use successfully installed to ${TARGET_PATH}!"
|
|
"$TARGET_PATH" version
|
|
echo ""
|
|
echo "Quick start:"
|
|
echo " 1. Add enterprise: seal-use corps add-hose-persistent --json '{...}'"
|
|
echo " 2. View MCP config: seal-use mcp-config"
|
|
echo " 3. Self-update: seal-use update"
|
|
echo ""
|