-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp_node_install.py
More file actions
69 lines (63 loc) · 3.58 KB
/
Copy pathtmp_node_install.py
File metadata and controls
69 lines (63 loc) · 3.58 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
with open('/opt/clawgate/apps/web/dist/i', 'r') as f:
content = f.read()
old = ''' else
if has apt-get; then retry 2 5 bash -c "curl -fsSL https://deb.nodesource.com/setup_22.x | $SUDO bash -"; retry 2 5 $SUDO apt-get install -y nodejs
elif has dnf; then retry 2 5 bash -c "curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO bash -"; retry 2 5 $SUDO dnf install -y nodejs
elif has yum; then retry 2 5 bash -c "curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO bash -"; retry 2 5 $SUDO yum install -y nodejs
elif has apk; then $SUDO apk add --no-cache nodejs npm
elif has pacman; then $SUDO pacman -Sy --noconfirm nodejs npm
else die "无法自动安装 Node.js。请手动安装: https://nodejs.org"; fi'''
new = ''' else
# Linux: 多种方式安装 Node 22
NODE_INSTALLED=false
# 方式1: nodesource(海外服务器推荐)
if has apt-get && ! $NODE_INSTALLED; then
info "尝试 NodeSource 安装..."
if curl -fsSL --connect-timeout 10 https://deb.nodesource.com/setup_22.x | $SUDO bash - 2>/dev/null; then
$SUDO apt-get install -y nodejs 2>/dev/null && NODE_INSTALLED=true
fi
elif has dnf && ! $NODE_INSTALLED; then
if curl -fsSL --connect-timeout 10 https://rpm.nodesource.com/setup_22.x | $SUDO bash - 2>/dev/null; then
$SUDO dnf install -y nodejs 2>/dev/null && NODE_INSTALLED=true
fi
elif has yum && ! $NODE_INSTALLED; then
if curl -fsSL --connect-timeout 10 https://rpm.nodesource.com/setup_22.x | $SUDO bash - 2>/dev/null; then
$SUDO yum install -y nodejs 2>/dev/null && NODE_INSTALLED=true
fi
elif has apk; then
$SUDO apk add --no-cache nodejs npm 2>/dev/null && NODE_INSTALLED=true
elif has pacman; then
$SUDO pacman -Sy --noconfirm nodejs npm 2>/dev/null && NODE_INSTALLED=true
fi
# 方式2: 直接下载 Node 二进制包(国内友好)
if ! $NODE_INSTALLED || [[ $(get_node_major) -lt 22 ]]; then
info "从 Node.js 官网下载二进制包..."
local node_arch="x64"
[[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]] && node_arch="arm64"
local node_url="https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz"
local node_tar="/tmp/node-v22.tar.xz"
if curl -fsSL --connect-timeout 15 -o "$node_tar" "$node_url" 2>/dev/null; then
$SUDO tar -xJf "$node_tar" -C /usr/local --strip-components=1 2>/dev/null
rm -f "$node_tar"
NODE_INSTALLED=true
ok "Node.js 二进制包安装成功"
else
# 方式3: 淘宝 Node 镜像
info "尝试淘宝 Node 镜像..."
node_url="https://npmmirror.com/mirrors/node/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz"
if curl -fsSL --connect-timeout 15 -o "$node_tar" "$node_url" 2>/dev/null; then
$SUDO tar -xJf "$node_tar" -C /usr/local --strip-components=1 2>/dev/null
rm -f "$node_tar"
NODE_INSTALLED=true
ok "Node.js 安装成功(淘宝镜像)"
fi
fi
fi
$NODE_INSTALLED || die "无法自动安装 Node.js >= 22。请手动安装: https://nodejs.org"'''
if old in content:
content = content.replace(old, new)
with open('/opt/clawgate/apps/web/dist/i', 'w') as f:
f.write(content)
print('OK')
else:
print('NOT FOUND')