-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
92 lines (79 loc) · 2.87 KB
/
setup.sh
File metadata and controls
92 lines (79 loc) · 2.87 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
#!/bin/bash
if [ -z "$1" ]; then
echo "Error: 参数为你的域名!"
echo "Usage: $0 domain"
exit 1
fi
domain=$1
username=$(whoami)
random_port=$((RANDOM % 40001 + 20000))
echo "to /home/$username/domains/$domain/public_html/index.js"
curl -s -o "/home/$username/domains/$domain/public_html/index.js" "https://raw.githubusercontent.com/banfeng-git/node-ws/main/index.js"
if [ $? -ne 0 ]; then
echo "Error: 下载脚本 index.js 失败!"
exit 1
fi
curl -s -o "/home/$username/cron.sh" "https://raw.githubusercontent.com/banfeng-git/node-ws/main/cron.sh"
if [ $? -ne 0 ]; then
echo "Error: 下载脚本 cron.sh 失败!"
exit 1
fi
chmod +x /home/$username/cron.sh
read -p "输入UUID:" uuid
if [ -z "$uuid" ]; then
echo "Error: UUID不能为空!"
exit 1
fi
echo "你输入的UUID: $uuid"
read -p "是否安装探针? [y/n] [n]:" input
input=${input:-n}
if [ "$input" != "n" ]; then
read -p "输入NEZHA_SERVER(哪吒v1填写形式:nz.abc.com:8008,哪吒v0填写形式:nz.abc.com):" nezha_server
if [ -z "$nezha_server" ]; then
echo "Error: nezha_server不能为空!"
exit 1
fi
read -p "输入NEZHA_PORT( v1面板此处按回车, v0的agent端口为{443,8443,2096,2087,2083,2053}其中之一时开启tls):" nezha_port
nezha_port=${nezha_port:-""}
read -p "输入NEZHA_KEY(v1的NZ_CLIENT_SECRET或v0的agent端口):" nezha_key
if [ -z "$nezha_key" ]; then
echo "Error: nezha_key不能为空!"
exit 1
fi
fi
echo "你输入的nezha_server: $nezha_server, nezha_port:$nezha_port, nezha_key:$nezha_key"
sed -i "s/NEZHA_SERVER || ''/NEZHA_SERVER || '$nezha_server'/g" "/home/$username/domains/$domain/public_html/index.js"
sed -i "s/NEZHA_PORT || ''/NEZHA_PORT || '$nezha_port'/g" "/home/$username/domains/$domain/public_html/index.js"
sed -i "s/NEZHA_KEY || ''/NEZHA_KEY || '$nezha_key'/g" "/home/$username/domains/$domain/public_html/index.js"
sed -i "s/1234.abc.com/$domain/g" "/home/$username/domains/$domain/public_html/index.js"
sed -i "s/3000;/$random_port;/g" "/home/$username/domains/$domain/public_html/index.js"
sed -i "s/de04add9-5c68-6bab-950c-08cd5320df33/$uuid/g" "/home/$username/domains/$domain/public_html/index.js"
if [ "$input" = "y" ]; then
sed -i "s/nezha_check=false/nezha_check=true/g" "/home/$username/cron.sh"
fi
cat > "/home/$username/domains/$domain/public_html/package.json" << EOF
{
"name": "node-ws",
"version": "1.0.0",
"description": "Node.js Server",
"main": "index.js",
"author": "eoovve",
"repository": "https://github.com/eoovve/node-ws",
"license": "MIT",
"private": false,
"scripts": {
"start": "node index.js"
},
"dependencies": {
"ws": "^8.14.2",
"axios": "^1.6.2"
},
"engines": {
"node": ">=14"
}
}
EOF
echo "*/1 * * * * cd /home/$username/public_html && /home/$username/cron.sh" > ./mycron
crontab ./mycron >/dev/null 2>&1
rm ./mycron
echo "安装完毕"