-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlinux-sugarchain-miner-en.sh
423 lines (359 loc) · 15 KB
/
linux-sugarchain-miner-en.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/bin/bash
#color codes
RED='\033[1;31m'
YELLOW='\033[1;33m'
BLUE="\\033[38;5;27m"
SEA="\\033[38;5;49m"
GREEN='\033[1;32m'
CYAN='\033[1;36m'
NC='\033[0m'
dversion="v1.0"
CRTDIR=$(pwd)
function string_limit_check_mark(){
if [[ -z "$2" ]]; then
string="$1"
string=${string::100}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::100+string_diff}
fi
echo -e "${ARROW}${CYAN}$string[${CHECK_MARK}√${CYAN}]${NC}"
}
function string_limit_x_mark(){
if [[ -z "$2" ]]; then
string="$1"
string=${string::50}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::50+string_diff}
fi
echo -e "${ARROW}${CYAN}$string[${CHECK_MARK}${RED}×${CYAN}]${NC}"
}
function Modify_sugarchain_miner_conf(){
if [[ -f ${CRTDIR}/sugarchain_miner_conf.json ]]; then
read_config
fi
if [[ -f ${CRTDIR}/pool-list.json ]]; then
echo
else
curl -O https://raw.githubusercontent.com/bailaoshijiadao/multitool-sugarchain/master/pool-list.json
fi
if whiptail --yesno "Would you like use old sugar address?" 8 40; then
string_limit_check_mark "Sugar address $sugar_address................................." "Sugar address ${GREEN}$sugar_address${CYAN}................................."
sleep 2
else
while true
do
sugar_address=$(whiptail --inputbox "Please enter your sugar address" 8 40 3>&1 1>&2 2>&3)
if [[ "$sugar_address" == sugar* ]]; then
string_limit_check_mark "Sugar address $sugar_address format is valid................................." "Sugar address ${GREEN}$sugar_address${CYAN} format is valid................................."
sleep 1
break
else
string_limit_x_mark "Sugar address $sugar_address is not valid..............................."
sleep 5
fi
done
fi
pool=$(cat ${CRTDIR}/pool-list.json)
#pool=$(curl -O https://raw.githubusercontent.com/bailaoshijiadao/multitool-sugarchain/master/pool-list.json)
if whiptail --yesno "Would you like use old pool?" 8 40; then
string_limit_check_mark "Pool address $pool_address................................." "Pool address ${GREEN}$pool_address${CYAN}................................."
sleep 2
else
while true
do
pool_address=$(whiptail --inputbox "Please enter your Pool address or IP\nChoose from the following mining pools\n$pool" 16 40 39.98.39.1:6678 3>&1 1>&2 2>&3)
if [[ "$pool_address" == *.*.*:* || "$pool_address" == *.*.*.*:* ]]; then
string_limit_check_mark "Pool address $pool_address format is valid................................." "Pool address ${GREEN}$pool_address${CYAN} format is valid................................."
sleep 1
break
else
string_limit_x_mark "Pool address $pool_address1 is not valid..............................."
sleep 5
fi
done
fi
if whiptail --yesno "Would you like use old miner cores?" 8 40; then
string_limit_check_mark "Miner cores $miner_cores................................." "Miner cores ${GREEN}$miner_cores${CYAN}................................."
sleep 2
else
while true
do
miner_cores=$(whiptail --inputbox "Please enter your miner cores(optional), defaults to 100% CPU" 8 40 3>&1 1>&2 2>&3)
if [[ "$miner_cores" =~ ^[0-9]*$ || "$miner_cores" == "" ]]; then
string_limit_check_mark "Miner cores $miner_cores format is valid................................." "Miner cores ${GREEN}$miner_cores${CYAN} format is valid................................."
sleep 1
break
else
string_limit_x_mark "Miner cores $miner_cores is not valid..............................."
sleep 5
fi
done
fi
if whiptail --yesno "Would you like use old machinary code?" 8 40; then
string_limit_check_mark "Machinary code $machinary_code................................." "Machinary code ${GREEN}$machinary_code${CYAN}................................."
sleep 2
else
while true
do
machinary_code=$(whiptail --inputbox "Please enter your machinary code(optional)" 8 40 3>&1 1>&2 2>&3)
if [[ "$machinary_code" == "" || "$miner_cores" == * ]]; then
string_limit_check_mark "Machinary code $machinary_code format is valid................................." "Machinary code ${GREEN}$machinary_code${CYAN} format is valid................................."
sleep 1
break
fi
done
fi
cat << EOF > ${CRTDIR}/sugarchain_miner_conf.json
{
"sugar_address":"${sugar_address}",
"pool_address":"${pool_address}",
"miner_cores":"${miner_cores}",
"machinary_code":"${machinary_code}"
}
EOF
string_limit_check_mark "Modify mining configuration succeeded................................." "Modify mining configuration succeeded................................."
}
function creat_sugarchain_miner_conf(){
if [[ -f ${CRTDIR}/pool-list.json ]]; then
echo
else
curl -O https://raw.githubusercontent.com/bailaoshijiadao/multitool-sugarchain/master/pool-list.json
fi
while true
do
sugar_address=$(whiptail --inputbox "Please enter your sugar address" 8 40 3>&1 1>&2 2>&3)
if [[ "$sugar_address" == sugar* ]]; then
string_limit_check_mark "Sugar address $sugar_address format is valid................................." "Sugar address ${GREEN}$sugar_address${CYAN} format is valid................................."
sleep 1
break
else
string_limit_x_mark "Sugar address $sugar_address is not valid ..............................."
sleep 5
fi
done
pool=$(cat ${CRTDIR}/pool-list.json)
#pool=$(curl -O https://raw.githubusercontent.com/bailaoshijiadao/multitool-sugarchain/master/pool-list.json)
while true
do
pool_address=$(whiptail --inputbox "Please enter your Pool address or IP\nChoose from the following mining pools\n$pool" 16 40 3>&1 1>&2 2>&3)
if [[ "$pool_address" == *.*.*:* || "$pool_address" == *.*.*.*:* ]]; then
string_limit_check_mark "Pool address $pool_address format is valid................................." "Pool address ${GREEN}$pool_address${CYAN} format is valid................................."
sleep 1
break
else
string_limit_x_mark "Pool address $pool_address1 is not valid..............................."
sleep 5
fi
done
while true
do
miner_cores=$(whiptail --inputbox "Please enter your miner cores(optional), defaults to 100% CPU" 8 40 3>&1 1>&2 2>&3)
if [[ "$miner_cores" =~ ^[0-9]*$ || "$miner_cores" == "" ]]; then
string_limit_check_mark "Miner cores $miner_cores format is valid................................." "Miner cores ${GREEN}$miner_cores${CYAN} format is valid................................."
sleep 1
break
else
string_limit_x_mark "Miner cores $miner_cores is not valid..............................."
sleep 5
fi
done
while true
do
machinary_code=$(whiptail --inputbox "Please enter your machinary code(optional)" 8 40 3>&1 1>&2 2>&3)
if [[ "$machinary_code" == "" || "$miner_cores" == * ]]; then
string_limit_check_mark "Machinary code $machinary_code format is valid................................." "Machinary code ${GREEN}$machinary_code${CYAN} format is valid................................."
sleep 1
break
fi
done
cat << EOF > ${CRTDIR}/sugarchain_miner_conf.json
{
"sugar_address":"${sugar_address}",
"pool_address":"${pool_address}",
"miner_cores":"${miner_cores}",
"machinary_code":"${machinary_code}"
}
EOF
string_limit_check_mark "Creat mining configuration succeeded................................." "Creat mining configuration succeeded................................."
}
function read_config(){
sugar_address=$(cat ${CRTDIR}/sugarchain_miner_conf.json | jq -r '.sugar_address')
string_limit_check_mark "Sugar address $sugar_address ................................." "Sugar address ${GREEN}$sugar_address${CYAN} ................................."
pool_address=$(cat ${CRTDIR}/sugarchain_miner_conf.json | jq -r '.pool_address')
string_limit_check_mark "Pool address $pool_address ................................." "Pool address ${GREEN}$pool_address${CYAN} ................................."
miner_cores=$(cat ${CRTDIR}/sugarchain_miner_conf.json | jq -r '.miner_cores')
string_limit_check_mark "Miner cores $miner_cores ................................." "Miner cores ${GREEN}$miner_cores${CYAN} ................................."
machinary_code=$(cat ${CRTDIR}/sugarchain_miner_conf.json | jq -r '.machinary_code')
string_limit_check_mark "Machinary code $machinary_code ................................." "Machinary code ${GREEN}$machinary_code${CYAN} ................................."
}
function Start_sugar_miner(){
echo -e "${CYAN}Sugarchain cpuminer setup starting,you can press [CTRL+C] to cancel.${NC}"
sleep 5
cd ~/
if [[ -f ${CRTDIR}/sugarchain_miner_conf.json ]]; then
read_config
else
creat_sugarchain_miner_conf
fi
check_results=`uname -a`
if [[ $check_results =~ "Linux" ]]; then
echo -e "${YELLOW}$check_results${NC}"
if [[ $check_results =~ "x86_64" ]]; then
if [[ ! -f ${CRTDIR}/sugarmaker-linux64 ]]; then
curl -O https://raw.githubusercontent.com/bailaoshijiadao/sugarmaker/main/sugarmaker-linux64
fi
chmod 777 sugarmaker-linux64
check_results=`screen -ls`
if [[ $check_results =~ "sugarchain_screen" ]]; then
string_limit_check_mark "Detect the existing mining serial port and start to close the original window........." "Detect the existing mining serial port and start to close the original window${GREEN}${CYAN} ........."
Stop_sugar_miner
fi
string_limit_check_mark "Start creating a mining window............................." "Start creating a mining window${GREEN}${CYAN} ................................."
screen_name=$"sugarchain_screen"
screen -dmS $screen_name
if [[ "$miner_cores" == "" ]]; then
cmd=$"./sugarmaker-linux64 -a YespowerSugar -o stratum+tcp://$pool_address -u $sugar_address.$machinary_code"
else
cmd=$"./sugarmaker-linux64 -a YespowerSugar -o stratum+tcp://$pool_address -u $sugar_address.$machinary_code -t$miner_cores"
fi
screen -x -S $screen_name -p 0 -X stuff "$cmd"
screen -x -S $screen_name -p 0 -X stuff $'\n'
string_limit_check_mark "Sugar chain mining has been started, please press 4 after 10 seconds to enter the view mining window" "Sugar chain mining has been started, please press 4 after 10 seconds to enter the view mining window${GREEN}${CYAN}"
sleep 5
fi
if [[ $check_results =~ "i686" ]]; then
if [[ ! -f ${CRTDIR}/sugarmaker-linux32 ]]; then
curl -O https://raw.githubusercontent.com/bailaoshijiadao/sugarmaker/main/sugarmaker-linux32
fi
chmod 777 sugarmaker-linux32
check_results=`screen -ls`
if [[ $check_results =~ "sugarchain_screen" ]]; then
string_limit_check_mark "Detect the existing mining serial port and start to close the original window........." "Detect the existing mining serial port and start to close the original window${GREEN}${CYAN} ........."
Stop_sugar_miner
fi
string_limit_check_mark "Start creating a mining window............................." "Start creating a mining window${GREEN}${CYAN} ................................."
screen_name=$"sugarchain_screen"
screen -dmS $screen_name
if [[ "$miner_cores" == "" ]]; then
cmd=$"./sugarmaker-linux32 -a YespowerSugar -o stratum+tcp://$pool_address -u $sugar_address.$machinary_code"
else
cmd=$"./sugarmaker-linux32 -a YespowerSugar -o stratum+tcp://$pool_address -u $sugar_address.$machinary_code -t$miner_cores"
fi
screen -x -S $screen_name -p 0 -X stuff "$cmd"
screen -x -S $screen_name -p 0 -X stuff $'\n'
string_limit_check_mark "Sugar chain mining has been started, please press 4 after 10 seconds to enter the view mining window" "Sugar chain mining has been started, please press 4 after 10 seconds to enter the view mining window${GREEN}${CYAN}"
sleep 5
fi
fi
echo -e "${YELLOW}******sugarmaker 2.5.0-sugar4 by Kanon******${NC}"
echo -e "${YELLOW}Multi-threaded CPU miner for Sugarchain and other Yespower variants${NC}"
echo -e "${YELLOW}SUGAR donation: sugar1q8d79pk0jyhl92jrmfsrpvuwwg9ycsr20xz93rz(bailaoshi)${NC}"
}
function Stop_sugar_miner(){
check_results=`screen -ls`
if [[ $check_results =~ "sugarchain_screen" ]]
then
screen_name=$"sugarchain_screen"
cmd=$"\003";
screen -x -S $screen_name -p 0 -X stuff "$cmd"
screen -x -S $screen_name -p 0 -X stuff $'\n'
cmd=$"exit";
screen -x -S $screen_name -p 0 -X stuff "$cmd"
screen -x -S $screen_name -p 0 -X stuff $'\n'
string_limit_check_mark "Stop sugar miner succeeded....................................." "Stop sugar miner succeeded${GREEN}${CYAN} ....................................."
else
string_limit_x_mark "No mining window detected, stop mining failed................"
fi
screen -ls|awk 'NR>=2&&NR<=5{print $1}'|awk '{print "screen -S "$1" -X quit"}'|sh
}
function see_screen(){
if screen -ls > /dev/null 2>&1
then
screen -r
else
echo -e "${RED}Mining window is not detected, window opening failed.${NC}"
fi
sleep 5
}
function install_step(){
if ! figlet -v > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing figlet ....${NC}"
sudo $* install -y figlet
fi
if ! whiptail -v > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing whiptail ....${NC}"
sudo $* install -y whiptail > /dev/null 2>&1
fi
#install JQ
if ! jq --version > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing JQ ....${NC}"
sudo $* install -y jq > /dev/null 2>&1
fi
if ! screen -v > /dev/null 2>&1; then
sudo $* install -y screen > /dev/null 2>&1
fi
}
#Ubuntu
if [[ -f /etc/issue ]]; then
system_v=$(cat /etc/issue)
if [[ $system_v =~ "Ubuntu" ]]; then
install_step apt
fi
fi
#Centos
if [[ -f /etc/centos-release ]]; then
install_step yum
else
if [[ -f /etc/redhat-release ]]; then
install_step yum
fi
fi
while :
do
sleep 1
echo -e "${BLUE}"
figlet -f big "SugarChain"
echo -e "${YELLOW}===========================================================${NC}"
echo -e "${GREEN}Version: $dversion${NC}"
echo -e "${GREEN}OS: Linux Ubuntu Centos${NC}"
echo -e "${GREEN}Author: bailaoshi${NC}"
echo -e "${GREEN}Special thanks to Kanon${NC}"
echo -e "${YELLOW}===========================================================${NC}"
echo -e "${CYAN}1 - Start sugar miner[Background process]${NC}"
echo -e "${CYAN}2 - Stop sugar miner${NC}"
echo -e "${CYAN}3 - Modify mining configuration[Use only when modification is required]${NC}"
echo -e "${CYAN}4 - View the mining window, return to this window and use the key combination[CTRL+A+D]${NC}"
echo -e "${YELLOW}===========================================================${NC}"
echo -e "${YELLOW}******sugarmaker 2.5.0-sugar4 by Kanon******${NC}"
echo -e "${YELLOW}Multi-threaded CPU miner for Sugarchain and other Yespower variants${NC}"
echo -e "${YELLOW}SUGAR donation: sugar1q8d79pk0jyhl92jrmfsrpvuwwg9ycsr20xz93rz(bailaoshi)${NC}"
read -rp "Pick an option and hit ENTER: "
case "$REPLY" in
1)
sleep 2
Start_sugar_miner
;;
2)
sleep 2
Stop_sugar_miner
;;
3)
sleep 2
Modify_sugarchain_miner_conf
;;
4)
sleep 2
see_screen
;;
esac
done