-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_macOS.sh
232 lines (198 loc) · 8.34 KB
/
test_macOS.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
#!/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 "13) 启动挖矿"
echo -e "\n14) 退出脚本"
read -rp "请输入选项编号 (1-14): " option
if [[ "$option" == "14" ]]; then
echo "退出脚本..."
break
fi
case $option in
1)
if [[ "$OSTYPE" == "darwin"* ]]; then
if ! command -v brew &> /dev/null; then
echo "Homebrew 未安装,您想安装哪个版本?"
echo "1) 原版 Homebrew"
echo "2) 国内加速版 Homebrew"
read -rp "请输入选项编号 (1-2): " brew_option
case $brew_option in
1)
echo "正在安装原版 Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
;;
2)
echo "正在安装国内加速版 Homebrew..."
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
;;
*)
echo "无效选项,取消 Homebrew 安装。"
continue
;;
esac
fi
echo "更新并安装必要的包..."
brew update && brew install \
automake libtool pkg-config cmake git rust
else
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 已成功安装!"
fi
while true; do
read -rp "请输入您的 Shaicoin 钱包地址: " wallet_address
if [[ ${#wallet_address} -eq 42 ]]; then
echo "输入的钱包地址: $wallet_address"
break
else
echo "错误:钱包地址不正确。请确保地址为42位。"
fi
done
if [ -d "$HOME/shaipot" ]; then
echo "$HOME/shaipot 目录已存在,正在删除..."
rm -rf "$HOME/shaipot"
fi
echo "正在克隆 shaipot 仓库..."
git clone https://github.com/shaicoin/shaipot.git "$HOME/shaipot"
cd "$HOME/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
cd "$HOME"
echo "正在创建启动脚本..."
if [[ "$OSTYPE" == "darwin"* ]]; then
cat > "$HOME/start_shai_mining.sh" <<EOF
#!/bin/bash
$HOME/shaipot/target/release/shaipot --address "$wallet_address" --pool wss://pool.shaicoin.org --threads $(sysctl -n hw.ncpu) --vdftime 1.5
EOF
chmod +x "$HOME/start_shai_mining.sh"
echo "可以通过运行 $HOME/start_shai_mining.sh 来启动 Shaicoin 挖矿程序。"
else
cat > /etc/systemd/system/shai.service <<EOF
[Unit]
Description=Shaicoin Mining Service
After=network.target
[Service]
ExecStart=$HOME/shaipot/target/release/shaipot --address "$wallet_address" --pool wss://pool.shaicoin.org --threads $(nproc) --vdftime 1.5
WorkingDirectory=$HOME/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 挖矿程序已作为服务启动并启用。"
fi
;;
2)
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macOS 上暂不支持使用 systemd 查看日志,请手动检查日志文件。"
else
echo "显示 Shaicoin 挖矿服务日志..."
journalctl -u shai -f
fi
;;
3)
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macOS 上无法重启 systemd 服务,请手动重启程序。"
else
echo "正在重启 Shaicoin 挖矿服务..."
systemctl restart shai
echo "Shaicoin 挖矿服务已成功重启。"
fi
;;
4)
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macOS 上无法停止 systemd 服务,请手动停止程序。"
else
echo "正在停止 Shaicoin 挖矿服务..."
systemctl stop shai
echo "Shaicoin 挖矿服务已成功停止。"
fi
;;
5)
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macOS 上请手动检查启动脚本中的钱包地址。"
else
wallet_address=$(grep -oP '(?<=--address )\S+' /etc/systemd/system/shai.service)
if [[ -n "$wallet_address" ]]; then
echo "当前钱包地址为: $wallet_address"
else
echo "无法从服务文件中提取钱包地址。"
fi
fi
;;
7)
pool_address=$(grep -oP '(?<=--pool )\S+' /etc/systemd/system/shai.service)
if [[ -n "$pool_address" ]]; then
echo "当前矿池地址为: $pool_address"
else
echo "无法从服务文件中提取矿池地址。"
fi
;;
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"
;;
13)
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "启动 Shaicoin 挖矿程序..."
"$HOME/start_shai_mining.sh" &
else
echo "启动 Shaicoin 挖矿服务..."
systemctl start shai
echo "Shaicoin 挖矿服务已启动。"
fi
;;
*)
echo "无效选项,请输入 1 到 14 之间的数字。"
;;
esac
echo -e "\n"
done