Files
tripocli/install.sh
T

95 lines
3.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# tripocli 一行安装脚本(Linux / macOS,无需预装 Python)
#
# curl -fsSL https://git.usetoks.com/Mrpzx/tripocli/raw/branch/main/install.sh | sh
#
# 可选环境变量:
# TRIPOCLI_VERSION=v2.0.0 指定版本(默认取最新 release)
# TRIPOCLI_INSTALL_DIR=/usr/local/bin 指定安装目录
#
set -eu
REPO="Mrpzx/tripocli"
HOST="${TRIPOCLI_HOST:-https://git.usetoks.com}"
BIN="tripocli"
info() { printf '%s\n' "$*"; }
die() { printf '错误: %s\n' "$*" >&2; exit 1; }
need() { command -v "$1" >/dev/null 2>&1 || die "缺少命令:$1"; }
need curl
need uname
# ---- 1) 识别平台 -----------------------------------------------------------
os=$(uname -s)
arch=$(uname -m)
case "$os" in
Linux) os_tag="linux" ;;
Darwin) os_tag="macos" ;;
*) die "暂不支持的系统:$os(Windows 请用:pip install git+$HOST/$REPO.git)" ;;
esac
case "$arch" in
x86_64|amd64) arch_tag="x86_64" ;;
arm64|aarch64) arch_tag="arm64" ;;
*) die "暂不支持的架构:$arch" ;;
esac
info "==> 平台:$os_tag / $arch_tag"
# ---- 2) 解析版本(默认最新 release)----------------------------------------
version="${TRIPOCLI_VERSION:-}"
if [ -z "$version" ]; then
info "==> 查询最新版本…"
version=$(curl -fsSL "$HOST/api/v1/repos/$REPO/releases/latest" 2>/dev/null \
| tr ',' '\n' | sed -n 's/.*"tag_name":"\([^"]*\)".*/\1/p' | head -1)
[ -n "$version" ] || die "无法获取最新版本,可用 TRIPOCLI_VERSION=v2.0.0 指定"
fi
# 资产名里版本号不带前导 v(tag=v2.0.0 → 资产 tripocli-2.0.0-…)
ver_num="${version#v}"
asset="${BIN}-${ver_num}-${os_tag}-${arch_tag}"
url="$HOST/$REPO/releases/download/$version/$asset"
info "==> 版本:$version"
# ---- 3) 下载 ---------------------------------------------------------------
tmp="$(mktemp "${TMPDIR:-/tmp}/tripocli.XXXXXX")"
trap 'rm -f "$tmp"' EXIT INT TERM
info "==> 下载:$asset"
curl -fL --progress-bar -o "$tmp" "$url" || die "下载失败:$url"
chmod +x "$tmp"
# 简单校验:确认是可执行文件而不是错误页面
size=$(wc -c < "$tmp" | tr -d ' ')
[ "$size" -gt 1000000 ] || die "下载内容异常(仅 ${size} 字节),可能是版本或平台不存在"
# ---- 4) 安装 ---------------------------------------------------------------
dir="${TRIPOCLI_INSTALL_DIR:-}"
if [ -z "$dir" ]; then
if [ -w /usr/local/bin ] 2>/dev/null; then
dir=/usr/local/bin
else
dir="$HOME/.local/bin"
mkdir -p "$dir"
fi
fi
[ -d "$dir" ] || mkdir -p "$dir" 2>/dev/null || die "无法创建安装目录:$dir"
mv "$tmp" "$dir/$BIN"
trap - EXIT INT TERM
chmod +x "$dir/$BIN"
info "==> 已安装到:$dir/$BIN"
# ---- 5) 校验 & 提示 --------------------------------------------------------
if command -v "$BIN" >/dev/null 2>&1; then
info "==> 安装成功:$("$BIN" --version 2>/dev/null || echo "$BIN")"
else
info "==> 安装成功,但 $dir 不在 PATH 里。请把下面这行加到 ~/.zshrc 或 ~/.bashrc:"
info " export PATH=\"$dir:\$PATH\""
fi
cat <<'EOF'
下一步:
1) 从浏览器复制 Tripo 的 Cookie(ory_kratos_session)
2) tripocli account add --cookie "ory_kratos_session=..."
3) tripocli balance # 验证连通
4) tripocli --help # 查看全部命令
也可以跑 tripocli serve,在本地网页里管理账号。
EOF