-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshaipot_cn.sh
341 lines (287 loc) · 11.6 KB
/
shaipot_cn.sh
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/bash
while true; do
# 显示选项菜单
echo -e "\n请选择一个操作:"
echo -e "\n1) 安装软件"
echo "2) 查看日志"
echo "3) 重启服务"
echo "4) 停止服务"
echo "5) 查看钱包地址"
echo "6) 修改钱包地址"
echo -e "\n7) 查看矿池地址"
echo "8) 修改矿池地址"
echo "9) 可用矿池列表"
echo "10) 修改CPU占用"
echo "11) 设置开机自启动"
echo "12) 移除开机自启动"
echo -e "\n13) 退出脚本"
read -rp "请输入选项编号 (1-13): " option
# 检查是否要退出脚本
if [[ "$option" == "13" ]]; then
echo "退出脚本..."
break
fi
case $option in
1)
# 安装环境并配置挖矿软件
echo "更新并安装必要的包..."
apt update -y && apt upgrade -y && apt install -y \
build-essential libtool autotools-dev automake pkg-config \
bsdmainutils python3 libevent-dev libboost-dev libsqlite3-dev \
libssl-dev curl wget htop git net-tools cmake autoconf \
libuv1-dev libhwloc-dev
echo "正在安装 Rust 和 Cargo..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
if [ $? -ne 0 ]; then
echo "Rust 安装失败。请检查网络连接或安装脚本的输出。"
continue
fi
echo "更新环境变量..."
source "$HOME/.cargo/env"
if ! command -v cargo &> /dev/null; then
echo "Cargo 未找到,请手动将 Rust 安装路径添加到 PATH 中。"
echo '可以通过在 ~/.bashrc 或 ~/.zshrc 中添加以下行来解决:'
echo 'export PATH="$HOME/.cargo/bin:$PATH"'
continue
fi
echo "验证 Rust 和 Cargo 安装..."
rustc --version
cargo --version
echo "Rust 和 Cargo 已成功安装!"
# 输入钱包地址并进行验证
while true; do
read -rp "请输入您的 Shaicoin 钱包地址: " wallet_address
if [[ ${#wallet_address} -eq 42 ]]; then
echo "输入的钱包地址: $wallet_address"
break
else
echo "错误:钱包地址不正确。请确保地址为42位。"
fi
done
# 如果 /root/shaipot 目录存在,则删除
if [ -d "/root/shaipot" ]; then
echo "/root/shaipot 目录已存在,正在删除..."
rm -rf /root/shaipot
fi
# 克隆最新的 shaipot 仓库
echo "正在克隆 shaipot 仓库..."
git clone https://github.com/shaicoin/shaipot.git /root/shaipot
# 进入项目目录
cd /root/shaipot
echo "当前目录: $(pwd)"
echo "正在编译 shaipot 挖矿程序..."
cargo rustc --release -- -C opt-level=3 -C target-cpu=native -C codegen-units=1 -C debuginfo=0
if [ $? -ne 0 ]; then
echo "编译失败。请检查错误信息。"
continue
fi
# 返回到 /root 目录
cd /root
echo "正在创建 systemd 服务文件..."
bash -c 'cat > /etc/systemd/system/shai.service <<EOF
[Unit]
Description=Shaicoin Mining Service
After=network.target
[Service]
ExecStart=/root/shaipot/target/release/shaipot --address '"$wallet_address"' --pool wss://pool.shaicoin.org --threads $(nproc) --vdftime 1.5
WorkingDirectory=/root/shaipot
StandardOutput=journal
StandardError=journal
Restart=always
RestartSec=10
Environment=RUST_BACKTRACE=1
[Install]
WantedBy=multi-user.target
EOF'
echo "刷新 systemd 配置并启动服务..."
systemctl daemon-reload
systemctl start shai
systemctl enable shai
echo "Shaipot 挖矿程序已作为服务启动并启用。"
;;
2)
# 查看挖矿程序日志
echo "显示 Shaicoin 挖矿服务日志..."
journalctl -u shai -f
;;
3)
# 重启服务
echo "正在重启 Shaicoin 挖矿服务..."
systemctl restart shai
echo "Shaicoin 挖矿服务已成功重启。"
;;
4)
# 停止服务
echo "正在停止 Shaicoin 挖矿服务..."
systemctl stop shai
echo "Shaicoin 挖矿服务已成功停止。"
;;
5)
# 查看当前钱包地址
wallet_address=$(grep -oP '(?<=--address )\S+' /etc/systemd/system/shai.service)
if [[ -n "$wallet_address" ]]; then
echo "当前钱包地址为: $wallet_address"
else
echo "无法从服务文件中提取钱包地址。"
fi
;;
6)
# 修改钱包地址,先提取矿池地址和线程数
pool_address=$(grep -oP '(?<=--pool )\S+' /etc/systemd/system/shai.service)
thread_count=$(grep -oP '(?<=--threads )\S+' /etc/systemd/system/shai.service)
if [[ -z "$pool_address" ]]; then
echo "无法从服务文件中提取矿池地址。"
continue
fi
if [[ -z "$thread_count" ]]; then
echo "无法从服务文件中提取线程数,默认为$(nproc)核。"
thread_count=$(nproc)
fi
while true; do
read -rp "请输入新的 Shaicoin 钱包地址: " wallet_address
if [[ ${#wallet_address} -eq 42 ]]; then
echo "新的钱包地址: $wallet_address"
echo "正在创建新的 systemd 服务文件..."
bash -c 'cat > /etc/systemd/system/shai.service <<EOF
[Unit]
Description=Shaicoin Mining Service
After=network.target
[Service]
ExecStart=/root/shaipot/target/release/shaipot --address '"$wallet_address"' --pool '"$pool_address"' --threads '"$thread_count"' --vdftime 1.5
WorkingDirectory=/root/shaipot
StandardOutput=journal
StandardError=journal
Restart=always
RestartSec=10
Environment=RUST_BACKTRACE=1
[Install]
WantedBy=multi-user.target
EOF'
echo "刷新 systemd 配置并重启服务..."
systemctl daemon-reload
systemctl restart shai
echo "钱包地址已更新,服务已重新启动。"
break
else
echo "错误:钱包地址不正确。请确保地址为42位。"
fi
done
;;
7)
# 查看当前矿池地址
pool_address=$(grep -oP '(?<=--pool )\S+' /etc/systemd/system/shai.service)
if [[ -n "$pool_address" ]]; then
echo "当前矿池地址为: $pool_address"
else
echo "无法从服务文件中提取矿池地址。"
fi
;;
8)
# 修改矿池地址,先提取钱包地址和CPU占用
wallet_address=$(grep -oP '(?<=--address )\S+' /etc/systemd/system/shai.service)
thread_count=$(grep -oP '(?<=--threads )\S+' /etc/systemd/system/shai.service)
if [[ -z "$wallet_address" ]]; then
echo "无法从服务文件中提取钱包地址。"
continue
fi
if [[ -z "$thread_count" ]]; then
echo "无法从服务文件中提取线程数,默认为$(nproc)核。"
thread_count=$(nproc)
fi
while true; do
read -rp "请输入新的 Shaicoin 矿池地址: " pool_address
if [[ -n "$pool_address" ]]; then
echo "新的矿池地址: $pool_address"
echo "正在创建新的 systemd 服务文件..."
bash -c 'cat > /etc/systemd/system/shai.service <<EOF
[Unit]
Description=Shaicoin Mining Service
After=network.target
[Service]
ExecStart=/root/shaipot/target/release/shaipot --address '"$wallet_address"' --pool '"$pool_address"' --threads '"$thread_count"' --vdftime 1.5
WorkingDirectory=/root/shaipot
StandardOutput=journal
StandardError=journal
Restart=always
RestartSec=10
Environment=RUST_BACKTRACE=1
[Install]
WantedBy=multi-user.target
EOF'
echo "刷新 systemd 配置并重启服务..."
systemctl daemon-reload
systemctl restart shai
echo "矿池地址已更新,服务已重新启动。"
break
else
echo "错误:矿池地址不能为空。"
fi
done
;;
9)
# 可用矿池列表
echo "可用矿池列表:"
echo -e "\n矿池地址:wss://pool.shaicoin.org\n网站地址:https://pool.shaicoin.org\n"
echo -e "矿池地址:wss://shaipool.moncici.xyz/ws/\n网站地址:https://shaipool.moncici.xyz\n"
echo -e "矿池地址:ws://162.220.160.74:3333\n网站地址:https://shaipool.z4ch.xyz\n"
echo -e "矿池地址:wss://pool.shaicoin.fun\n网站地址:https://www.shaicoin.fun\n"
;;
10)
# 修改CPU占用,先提取矿池和钱包地址
wallet_address=$(grep -oP '(?<=--address )\S+' /etc/systemd/system/shai.service)
pool_address=$(grep -oP '(?<=--pool )\S+' /etc/systemd/system/shai.service)
if [[ -z "$wallet_address" ]]; then
echo "无法从服务文件中提取钱包地址。"
continue
fi
if [[ -z "$pool_address" ]]; then
echo "无法从服务文件中提取矿池地址。"
continue
fi
while true; do
read -rp "请输入要使用的核心数: " thread_count
if [[ "$thread_count" =~ ^[0-9]+$ ]] && [[ "$thread_count" -gt 0 ]]; then
echo "设置核心数为: $thread_count"
bash -c 'cat > /etc/systemd/system/shai.service <<EOF
[Unit]
Description=Shaicoin Mining Service
After=network.target
[Service]
ExecStart=/root/shaipot/target/release/shaipot --address '"$wallet_address"' --pool '"$pool_address"' --threads '"$thread_count"' --vdftime 1.5
WorkingDirectory=/root/shaipot
StandardOutput=journal
StandardError=journal
Restart=always
RestartSec=10
Environment=RUST_BACKTRACE=1
[Install]
WantedBy=multi-user.target
EOF'
echo "刷新 systemd 配置并重启服务..."
systemctl daemon-reload
systemctl restart shai
echo "核心数已更新,服务已重新启动。"
break
else
echo "错误:请输入一个大于0的数字。"
fi
done
;;
11)
# 设置服务为开机自启动
echo "设置 Shaicoin 挖矿服务为开机自启动..."
systemctl enable shai
echo "Shaicoin 挖矿服务已设置为开机自启动。"
;;
12)
# 移除服务的开机自启动
echo "移除 Shaicoin 挖矿服务的开机自启动..."
systemctl disable shai
echo "Shaicoin 挖矿服务的开机自启动已移除。"
;;
*)
echo "无效选项,请输入 1 到 13 之间的数字。"
;;
esac
echo -e "\n"
done