-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.sh
More file actions
123 lines (109 loc) · 5.37 KB
/
install.sh
File metadata and controls
123 lines (109 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
# ============================================================
# weixin-ai-bridge 一键安装脚本(macOS / Linux)
# 作者:花椒
# 用法:curl -fsSL https://cdn.jsdelivr.net/gh/yansc153/weixin-ai-bridge/install.sh | bash
# ============================================================
set -euo pipefail
# ── 颜色 ────────────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
CYAN='\033[0;36m'; BOLD='\033[1m'; RESET='\033[0m'
ok() { echo -e "${GREEN}✓${RESET} $*"; }
info() { echo -e "${CYAN}→${RESET} $*"; }
warn() { echo -e "${YELLOW}!${RESET} $*"; }
fail() { echo -e "${RED}✗${RESET} $*"; exit 1; }
echo ""
echo -e "${BOLD}╔══════════════════════════════════════════╗${RESET}"
echo -e "${BOLD}║ weixin-ai-bridge 一键安装 ║${RESET}"
echo -e "${BOLD}║ 作者:花椒 ║${RESET}"
echo -e "${BOLD}╚══════════════════════════════════════════╝${RESET}"
echo ""
OS="$(uname -s)"
# ── 1. macOS: Xcode Command Line Tools ──────────────────────
if [[ "$OS" == "Darwin" ]]; then
if ! xcode-select -p &>/dev/null; then
info "安装 Xcode Command Line Tools(弹出安装窗口后请点击安装)..."
xcode-select --install 2>/dev/null || true
echo "等待 Xcode CLT 安装完成,请在弹出窗口点击【安装】..."
until xcode-select -p &>/dev/null; do
sleep 5
done
ok "Xcode Command Line Tools 已安装"
else
ok "Xcode Command Line Tools 已就绪"
fi
fi
# ── 2. macOS: Homebrew(国内镜像)───────────────────────────
if [[ "$OS" == "Darwin" ]]; then
if ! command -v brew &>/dev/null; then
info "安装 Homebrew(使用国内 Gitee 镜像)..."
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
/bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" || \
fail "Homebrew 安装失败,请手动安装后重试"
ok "Homebrew 已安装"
else
ok "Homebrew 已就绪 ($(brew --version | head -1))"
fi
# 配置 Homebrew 国内源(加速后续安装)
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_NO_AUTO_UPDATE=1
fi
# ── 3. Node.js ≥ 18 ─────────────────────────────────────────
need_node=false
if ! command -v node &>/dev/null; then
need_node=true
else
node_ver=$(node -e "process.exit(parseInt(process.version.slice(1)) < 18 ? 1 : 0)" 2>/dev/null && echo "ok" || echo "old")
[[ "$node_ver" == "old" ]] && need_node=true
fi
if [[ "$need_node" == "true" ]]; then
info "安装 Node.js LTS..."
if [[ "$OS" == "Darwin" ]]; then
brew install node
elif command -v apt-get &>/dev/null; then
# NodeSource LTS
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
elif command -v yum &>/dev/null; then
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs
else
fail "无法自动安装 Node.js,请手动安装 Node.js ≥ 18: https://nodejs.org"
fi
ok "Node.js $(node --version) 已安装"
else
ok "Node.js $(node --version) 已就绪"
fi
# ── 4. npm 国内镜像 ──────────────────────────────────────────
info "配置 npm 镜像(npmmirror.com)..."
npm config set registry https://registry.npmmirror.com
ok "npm 镜像已配置"
# ── 5. pip 国内镜像 ──────────────────────────────────────────
PIP_CMD=""
if command -v pip3 &>/dev/null; then PIP_CMD="pip3"
elif command -v pip &>/dev/null; then PIP_CMD="pip"
fi
if [[ -n "$PIP_CMD" ]]; then
info "配置 pip 镜像(清华 TUNA)..."
$PIP_CMD config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 2>/dev/null || true
ok "pip 镜像已配置"
fi
# ── 6. 安装并启动 weixin-ai-bridge ───────────────────────────
echo ""
echo -e "${BOLD}${GREEN}环境准备完成,正在安装 weixin-ai-bridge...${RESET}"
echo ""
# Download tarball (pure HTTPS, no git/SSH needed), build, and install globally
WAB_TMP=$(mktemp -d)
trap 'rm -rf "$WAB_TMP"' EXIT
curl -fsSL https://github.com/yansc153/weixin-ai-bridge/archive/refs/heads/main.tar.gz \
| tar xz -C "$WAB_TMP" --strip-components=1
cd "$WAB_TMP"
npm install
npm run build
npm install -g --ignore-scripts .
cd /
exec weixin-ai-bridge "$@" </dev/tty