diff --git a/README.md b/README.md index e1379906..98e3ef23 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,6 @@ The official [GitLink](https://www.gitlink.org.cn) CLI tool — built for humans ### Requirements -- Node.js 14+ (`npm`/`npx`) — for npm installation - Supported platforms: macOS, Linux, Windows (x64/arm64) - Go 1.26+ — only required for building from source @@ -54,10 +53,15 @@ The official [GitLink](https://www.gitlink.org.cn) CLI tool — built for humans #### Install -**From npm (recommended):** +**一键安装(推荐) — 无需 npm、无需 Go:** + +```bash +curl -sSL https://www.gitlink.org.cn/Gitlink/gitlink-cli/raw/master/install.sh | bash +``` + +**From npm:** ```bash -# One command: installs CLI binary + all 12 AI Agent Skills npm install -g @gitlink-ai/cli ``` diff --git a/README.zh-CN.md b/README.zh-CN.md index 0eb0fcdf..40bca579 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -44,7 +44,6 @@ ### 前置条件 -- Node.js 14+(`npm`/`npx`)— 用于 npm 安装 - 支持平台:macOS、Linux、Windows(x64/arm64) - Go 1.26+ — 仅从源码构建时需要 @@ -56,17 +55,16 @@ 选择以下**任一**方式: -**方式 1 — 从 npm 安装(推荐):** +**方式 1 — 一键安装(推荐,无需 npm、无需 Go):** + +```bash +curl -sSL https://www.gitlink.org.cn/Gitlink/gitlink-cli/raw/master/install.sh | bash +``` + +**方式 2 — 从 npm 安装:** ```bash -# 安装 CLI npm install -g @gitlink-ai/cli - -# 安装 CLI Skill(必须,全平台通用) -gitlink-cli-install-skills - -# 也可使用 npx 安装 Skill -npx skills add ccfos/gitlink-cli/skills -y -g ``` **方式 2 — 从源码构建:** diff --git a/install.sh b/install.sh new file mode 100755 index 00000000..9295383c --- /dev/null +++ b/install.sh @@ -0,0 +1,196 @@ +#!/bin/bash +# GitLink CLI 一键安装脚本 +# 自动检测平台,下载预编译二进制,安装 skills +# 用法: curl -sSL https://www.gitlink.org.cn/Gitlink/gitlink-cli/raw/master/install.sh | bash +set -e + +REPO_OWNER="Gitlink" +REPO_NAME="gitlink-cli" +BINARY_NAME="gitlink-cli" +API_BASE="https://www.gitlink.org.cn" +INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" +SKILLS_DIR="${HOME}/.gitlink/skills" +VERSION="${VERSION:-latest}" + +# ---------- 颜色输出 ---------- +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +NC='\033[0m' + +info() { echo -e "${GREEN}[INFO]${NC} $*"; } +warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } +error() { echo -e "${RED}[ERROR]${NC} $*"; } +step() { echo -e "${CYAN}[STEP]${NC} $*"; } + +# ---------- 平台检测 ---------- +detect_platform() { + local os arch + case "$(uname -s)" in + Linux) os="linux" ;; + Darwin) os="darwin" ;; + MINGW*|MSYS*|CYGWIN*) os="windows" ;; + *) error "不支持的操作系统: $(uname -s)"; exit 1 ;; + esac + case "$(uname -m)" in + x86_64|amd64) arch="amd64" ;; + aarch64|arm64) arch="arm64" ;; + *) error "不支持的架构: $(uname -m)"; exit 1 ;; + esac + echo "${os}/${arch}" +} + +# ---------- 获取最新版本 ---------- +fetch_latest_version() { + local releases_url="${API_BASE}/api/${REPO_OWNER}/${REPO_NAME}/releases.json" + + info "获取最新版本..." + + local releases + releases=$(curl -sSL --connect-timeout 10 --max-time 30 "${releases_url}" 2>/dev/null || true) + + if [ -z "$releases" ]; then + error "无法获取发布列表: ${releases_url}" + exit 1 + fi + + # 尝试解析第一个 release 的 tag_name + local tag + tag=$(echo "$releases" | grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"\([^"]*\)"$/\1/') + + if [ -z "$tag" ]; then + # 备选:尝试直接匹配数组第一个元素的 tag_name + tag=$(echo "$releases" | grep -oP '"tag_name"\s*:\s*"\K[^"]+' | head -1) + fi + + echo "${tag:-v0.1.0}" +} + +# ---------- 下载二进制 ---------- +download_binary() { + local platform="$1" + local version="$2" + local os="${platform%/*}" + local arch="${platform#*/}" + local archive_name="${BINARY_NAME}_${version}_${os}_${arch}.tar.gz" + local download_url="${API_BASE}/api/${REPO_OWNER}/${REPO_NAME}/releases/${version}/assets/${archive_name}" + + step "下载: ${archive_name}" + info "URL: ${download_url}" + + local tmpdir + tmpdir="$(mktemp -d)" + trap "rm -rf ${tmpdir}" EXIT + + curl -sSL --connect-timeout 10 --max-time 120 -o "${tmpdir}/${archive_name}" "${download_url}" + + if [ ! -s "${tmpdir}/${archive_name}" ]; then + error "下载失败,文件为空或不存在" + error "请确认以下版本已发布: ${version}" + error "发布页: ${API_BASE}/${REPO_OWNER}/${REPO_NAME}/releases" + exit 1 + fi + + step "解压..." + tar -xzf "${tmpdir}/${archive_name}" -C "${tmpdir}" + + local binary_path="${tmpdir}/${BINARY_NAME}" + if [ ! -f "${binary_path}" ]; then + # 可能在子目录中 + binary_path=$(find "${tmpdir}" -name "${BINARY_NAME}" -type f 2>/dev/null | head -1) + fi + + if [ ! -f "${binary_path}" ]; then + error "解压后未找到二进制文件" + exit 1 + fi + + chmod +x "${binary_path}" + + # ---------- 安装 ---------- + step "安装到 ${INSTALL_DIR}/${BINARY_NAME}" + + if [ ! -w "${INSTALL_DIR}" ]; then + warn "需要管理员权限写入 ${INSTALL_DIR}" + sudo mkdir -p "${INSTALL_DIR}" + sudo mv "${binary_path}" "${INSTALL_DIR}/${BINARY_NAME}" + sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}" + else + mkdir -p "${INSTALL_DIR}" + mv "${binary_path}" "${INSTALL_DIR}/${BINARY_NAME}" + fi + + info "二进制: ${INSTALL_DIR}/${BINARY_NAME}" +} + +# ---------- 安装 skills ---------- +install_skills() { + local version="$1" + step "安装 skills..." + + mkdir -p "${SKILLS_DIR}" + + local skills_url="${API_BASE}/api/${REPO_OWNER}/${REPO_NAME}/releases/${version}/assets/${BINARY_NAME}_${version}_skills.tar.gz" + local tmpdir + tmpdir="$(mktemp -d)" + + curl -sSL --connect-timeout 10 --max-time 60 -o "${tmpdir}/skills.tar.gz" "${skills_url}" 2>/dev/null || true + + if [ -s "${tmpdir}/skills.tar.gz" ]; then + tar -xzf "${tmpdir}/skills.tar.gz" -C "${SKILLS_DIR}" 2>/dev/null || true + info "Skills 安装到: ${SKILLS_DIR}" + else + warn "Skills 包不可用(可稍后通过 gitlink-cli-install-skills 安装)" + fi + + rm -rf "${tmpdir}" +} + +# ---------- 验证安装 ---------- +verify() { + step "验证安装..." + if command -v "${BINARY_NAME}" >/dev/null 2>&1; then + info "安装成功! $("${BINARY_NAME}" version 2>/dev/null || echo "${BINARY_NAME}")" + elif [ -x "${INSTALL_DIR}/${BINARY_NAME}" ]; then + info "安装成功! $("${INSTALL_DIR}/${BINARY_NAME}" version 2>/dev/null || echo "${INSTALL_DIR}/${BINARY_NAME}")" + warn "请将 ${INSTALL_DIR} 添加到 PATH: export PATH=${INSTALL_DIR}:\$PATH" + else + error "安装验证失败" + exit 1 + fi +} + +# ---------- main ---------- +main() { + echo "" + echo " ╔══════════════════════════════════════╗" + echo " ║ GitLink CLI 一键安装 ║" + echo " ╚══════════════════════════════════════╝" + echo "" + + local platform + platform=$(detect_platform) + info "检测到平台: ${platform}" + + local version + if [ "${VERSION}" = "latest" ]; then + version=$(fetch_latest_version) + info "最新版本: ${version}" + else + version="${VERSION}" + info "指定版本: ${version}" + fi + + download_binary "${platform}" "${version}" + install_skills "${version}" + verify + + echo "" + info "快速开始:" + info " gitlink-cli auth login # 登录账号" + info " gitlink-cli --help # 查看所有命令" + echo "" +} + +main "$@" diff --git a/npm/package.json b/npm/package.json index d4ab32af..3f37a7c4 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@gitlink-ai/cli", - "version": "0.1.13", + "version": "0.2.0", "description": "GitLink 平台官方命令行工具 — 代码托管、协作开发和自动化", "bin": { "gitlink-cli": "bin/cli.js",