-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmine.sh
455 lines (428 loc) · 13.4 KB
/
mine.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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#!/bin/bash
units_available()
{
if punits=$(nproc) ; then
echo $punits
else
echo ""
fi
}
add_pool()
{
if [[ "$1" -gt "1" ]]; then
echo
echo "$(tput setaf 3)●$(tput sgr 0) Please, select the additional mining pool."
PS3="➤ Additional Pool: "
else
echo "$(tput setaf 3)●$(tput sgr 0) Please, select the mining pool."
PS3="$(tput setaf 3)➤$(tput sgr 0) Pool: "
fi
units=`units_available`
options=("CTR EU" "CTR EU Backup" "CTR AS" "CTR AS Backup" "CTR US" "CTR US Backup" "Other" "Exit")
select opt in "${options[@]}"
do
case "$REPLY" in
1)
pool_heading $opt
server[$1]="eu.catchthatrabbit.com"
port[$1]=8008
if [[ "$1" -lt "2" ]]; then
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter wallet address: " wallet
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter worker name: " worker
printf "$(tput setaf 3)●$(tput sgr 0) Available processing units: %s\n" $units
read -p "$(tput setaf 3)➤$(tput sgr 0) How many units to use? [Enter for all] " threads
fi
break
;;
2)
pool_heading $opt
server[$1]="eu1.catchthatrabbit.com"
port[$1]=8008
if [[ "$1" -lt "2" ]]; then
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter wallet address: " wallet
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter worker name: " worker
printf "$(tput setaf 3)●$(tput sgr 0) Available processing units: %s\n" $units
read -p "$(tput setaf 3)➤$(tput sgr 0) How many units to use? [Enter for all] " threads
fi
break
;;
3)
pool_heading $opt
server[$1]="as.catchthatrabbit.com"
port[$1]=8008
if [[ "$1" -lt "2" ]]; then
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter wallet address: " wallet
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter worker name: " worker
printf "$(tput setaf 3)●$(tput sgr 0) Available processing units: %s\n" $units
read -p "$(tput setaf 3)➤$(tput sgr 0) How many units to use? [Enter for all] " threads
fi
break
;;
4)
pool_heading $opt
server[$1]="as1.catchthatrabbit.com"
port[$1]=8008
if [[ "$1" -lt "2" ]]; then
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter wallet address: " wallet
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter worker name: " worker
printf "$(tput setaf 3)●$(tput sgr 0) Available processing units: %s\n" $units
read -p "$(tput setaf 3)➤$(tput sgr 0) How many units to use? [Enter for all] " threads
fi
break
;;
5)
pool_heading $opt
server[$1]="us.catchthatrabbit.com"
port[$1]=8008
if [[ "$1" -lt "2" ]]; then
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter wallet address: " wallet
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter worker name: " worker
printf "$(tput setaf 3)●$(tput sgr 0) Available processing units: %s\n" $units
read -p "$(tput setaf 3)➤$(tput sgr 0) How many units to use? [Enter for all] " threads
fi
break
;;
6)
pool_heading $opt
server[$1]="us1.catchthatrabbit.com"
port[$1]=8008
if [[ "$1" -lt "2" ]]; then
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter wallet address: " wallet
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter worker name: " worker
printf "$(tput setaf 3)●$(tput sgr 0) Available processing units: %s\n" $units
read -p "$(tput setaf 3)➤$(tput sgr 0) How many units to use? [Enter for all] " threads
fi
break
;;
7)
pool_heading $opt
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter server address: " server[$1]
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter server port: " port[$1]
if [[ "$1" -lt "2" ]]; then
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter wallet address: " wallet
read -p "$(tput setaf 3)➤$(tput sgr 0) Enter worker name: " worker
printf "$(tput setaf 3)●$(tput sgr 0) Available processing units: %s\n" $units
read -p "$(tput setaf 3)➤$(tput sgr 0) How many units to use? [Enter for all] " threads
fi
break
;;
8) clear; exit 0;;
*) echo "$(tput setaf 1)●$(tput sgr 0) Invalid option."; continue;;
esac
done
}
pool_heading()
{
echo
echo "╒════════════════════════════════════"
echo "│ Pool $1"
echo "╘════════════════════════════════════"
}
start_mining()
{
SECURE_JIT=""
cOS=$(uname -a | awk '{print $(1)}')
cPLT=$(uname -m)
if [ "$cOS" == "Darwin" ] && [ "$cPLT" == "arm64" ]; then
SECURE_JIT="--jit-secure"
fi
LARGE_PAGES=""
if [ -f /proc/sys/vm/nr_hugepages ]; then
if [ $(cat /proc/sys/vm/nr_hugepages) -gt 0 ]; then
LARGE_PAGES="--large-pages"
fi
fi
HARD_AES=""
if [ $(grep aes /proc/cpuinfo 2>&1 | wc -c) -ne 0 ]; then
HARD_AES="--hard-aes"
fi
POOLS=""
for pool in "${@:2}"
do
POOLS+="-P ${pool} "
done
THREAD=""
if [[ "$1" -gt "0" ]]; then
THREAD="-t ${1}"
fi
if [ ! -f "coreminer" ]; then
echo "$(tput setaf 1)●$(tput sgr 0) Miner not found!"
exit 2
fi
if [[ -x "coreminer" ]]; then
./coreminer --noeval $LARGE_PAGES $HARD_AES $SECURE_JIT $POOLS $THREAD
else
chmod +x coreminer
./coreminer --noeval $LARGE_PAGES $HARD_AES $SECURE_JIT $POOLS $THREAD
fi
}
validate_wallet()
{
BC=$(which bc)
if [[ -x "$BC" ]]; then
ord() {
LC_CTYPE=C printf '%d' "'$1"
}
alphabet_pos() {
if [ -n "$1" ] && [ "$1" -eq "$1" ] 2>/dev/null; then
echo $1
else
UPPER=$(echo "$1" | tr '[:lower:]' '[:upper:]')
echo $((`ord $UPPER` - 55))
fi
}
ICAN=$1
COUNTRY=${ICAN:0:2}
CHECKSUM=${ICAN:2:2}
BCAN=${ICAN:4}
BCCO=`echo $BCAN``echo $COUNTRY`
SUM=""
for ((i=0; i<${#BCCO}; i++)); do
SUM+=`alphabet_pos ${BCCO:$i:1}`
done
OPERAND=`echo $SUM``echo $CHECKSUM`
if [[ `echo "$OPERAND % 97" | $BC` -ne 1 ]]; then
echo "$(tput setaf 1)●$(tput sgr 0) Invalid wallet!"
exit 1
fi
else
echo "$(tput setaf 3)●$(tput sgr 0) Not able to validate wallet! (Install 'bc' if needed.)"
fi
}
compose_stratum()
{
# scheme://wallet[.workername][:password]@hostname:port[/...]
if [[ -z "$4" ]]; then
echo "stratum1+tcp://$1@$2:$3"
else
echo "stratum1+tcp://$1.$4@$2:$3"
fi
}
export_config()
{
> $1
for setting in "${@:2}"
do
echo $setting >> $1
done
}
import_config()
{
. $1
}
update_app()
{
if [ -f "./mine.updated.sh" ]; then
mv -f mine.updated.sh mine.sh
fi
JSONDATA=$(curl -X GET --header "Accept: application/json" "https://api.github.com/repos/catchthatrabbit/coreminer/releases/latest")
TAG=$(echo "${JSONDATA}" | awk 'BEGIN{RS=","} /tag_name/{gsub(/.*: "/,"",$0); gsub(/"/,"",$0); print $0}')
LATESTVER=$(echo ${TAG} | sed -r 's/^v//')
ARCH=$(uname -m)
if [ "$ARCH" == "aarch64" ]; then ARCH="arm64"; fi
PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
LATESTDOWN="https://github.com/catchthatrabbit/coreminer/releases/download/${TAG}/coreminer-${PLATFORM}-${ARCH}.tar.gz"
if [ -f "./coreminer" ]; then
VER=$(./coreminer -V | sed -n '2p' | sed 's/+commit\.\?[a-f0-9]*//')
printf -v versions '%s\n%s' "$VER" "$LATESTVER"
if [[ $versions = "$(sort -V <<< "$versions")" ]]; then
if curl --output /dev/null --silent --head --fail "$LATESTDOWN"; then
echo "$(tput setaf 2)●$(tput sgr 0) Downloading the update."
curl -OL "$LATESTDOWN"
tar -xzvf ./"coreminer-${PLATFORM}-${ARCH}.tar.gz"
rm -f ./"coreminer-${PLATFORM}-${ARCH}.tar.gz"
cd coreapp && mv -f coreminer ../coreminer && mv -f mine.sh ../mine.updated.sh
cd .. && rm -rf coreapp
echo "$(tput setaf 2)●$(tput sgr 0) Restarting the program."
exec ./mine.sh
else
echo "$(tput setaf 3)●$(tput sgr 0) Update not found for your system!"
fi
else
echo "$(tput setaf 2)●$(tput sgr 0) You have the latest version already."
fi
else
echo "$(tput setaf 2)●$(tput sgr 0) Software is not installed in this folder. Downloading the latest version."
curl -OL "$LATESTDOWN"
FILENAME="coreminer-${PLATFORM}-${ARCH}.tar.gz"
GZIP_MAGIC_NUMBER=$(head -c 2 "${FILENAME}" | od -N 2 -t x1 | awk 'NR==1 { printf("%s%s\n", $2, $3) }')
if [ "${GZIP_MAGIC_NUMBER}" == "1f8b" ]; then
tar -xzvf ./"coreminer-${PLATFORM}-${ARCH}.tar.gz"
rm -f ./"coreminer-${PLATFORM}-${ARCH}.tar.gz"
cd coreapp && mv -f coreminer ../coreminer && mv -f mine.sh ../mine.updated.sh
cd .. && rm -rf coreapp
echo "$(tput setaf 2)●$(tput sgr 0) Restarting the program."
exec ./mine.updated.sh
else
echo "$(tput setaf 1)●$(tput sgr 0) Downloaded file is not in gzip format. Update failed."
echo "$(tput setaf 1)●$(tput sgr 0) Please, download the latest version manually."
rm -f ./"coreminer-${PLATFORM}-${ARCH}.tar.gz"
exit 3
fi
fi
}
autostart_service()
{
if [ -f "/etc/systemd/system/coreminer.service" ]; then
echo "$(tput setaf 2)●$(tput sgr 0) Autostart service already exists."
return
fi
echo "$(tput setaf 2)●$(tput sgr 0) Creating autostart service."
> /etc/systemd/system/coreminer.service
echo "[Unit]" >> /etc/systemd/system/coreminer.service
echo "Description=CoreVerificator" >> /etc/systemd/system/coreminer.service
echo "After=network.target" >> /etc/systemd/system/coreminer.service
echo "StartLimitIntervalSec=0" >> /etc/systemd/system/coreminer.service
echo "" >> /etc/systemd/system/coreminer.service
echo "[Service]" >> /etc/systemd/system/coreminer.service
echo "Type=simple" >> /etc/systemd/system/coreminer.service
echo "WorkingDirectory=$(pwd)" >> /etc/systemd/system/coreminer.service
echo "ExecStart=/bin/bash $(pwd)/mine.sh" >> /etc/systemd/system/coreminer.service
echo "Restart=always" >> /etc/systemd/system/coreminer.service
echo "RestartSec=3" >> /etc/systemd/system/coreminer.service
echo "TimeoutStartSec=0" >> /etc/systemd/system/coreminer.service
echo "" >> /etc/systemd/system/coreminer.service
echo "[Install]" >> /etc/systemd/system/coreminer.service
echo "WantedBy=multi-user.target" >> /etc/systemd/system/coreminer.service
systemctl daemon-reload
systemctl enable coreminer.service
echo "$(tput setaf 2)●$(tput sgr 0) Autostart service created."
echo "$(tput setaf 2)●$(tput sgr 0) Vacuuming journal."
journalctl --rotate && journalctl --vacuum-time=1d
echo "$(tput setaf 2)●$(tput sgr 0) Starting autostart service and script."
systemctl start coreminer.service
}
extdrive_check()
{
EXTCONF=$(lsblk -nlo mountpoint | awk '$0 ~ /^\/media\/[^/]+\/coredrive/ {print}')
if [ -z "$EXTCONF" ]; then
echo "pool.cfg"
else
echo "${EXTCONF}/pool.cfg"
fi
}
while :
do
clear
echo " ▄▀▀ ▄▀▄ █▀▄ ██▀ ██▄ ▄▀▀ █▄█ █▄ █"
echo " ▀▄▄ ▀▄▀ █▀▄ █▄▄ █▄█ ▀▄▄ █ █ █ ▀█"
echo
CONFIG=`extdrive_check`
if [ -f "$CONFIG" ]; then
echo "$(tput setaf 2)●$(tput sgr 0) Mine settings file '$CONFIG' exists."
echo "$(tput setaf 2)●$(tput sgr 0) Importing settings."
import_config $CONFIG
if [ "$update" = true ]; then
update_app
fi
ICANWALLET=${wallet//[[:blank:]]/}
validate_wallet $ICANWALLET
echo "$(tput setaf 2)●$(tput sgr 0) Wallet validated."
STRATUM=""
echo "$(tput setaf 2)●$(tput sgr 0) Configuring stratum server."
for i in "${!server[@]}"
do
STRATUM+=`compose_stratum "$ICANWALLET" "${server[$i]}" "${port[$i]}" "$worker"`
STRATUM+=" "
done
echo "$(tput setaf 2)●$(tput sgr 0) Starting mining command."
start_mining "$threads" $STRATUM
else
echo "$(tput setaf 3)●$(tput sgr 0) Mine settings file '$CONFIG' doesn't exist."
echo "$(tput setaf 2)●$(tput sgr 0) Proceeding with setup."
echo
while true
do
read -r -p "$(tput setaf 3)➤$(tput sgr 0) Check for the update? [yes/no] " upd
case $upd in
[yY][eE][sS]|[yY])
update_app
break
;;
[nN][oO]|[nN])
echo "$(tput setaf 2)●$(tput sgr 0) Update skipped."
break
;;
*)
echo "$(tput setaf 1)➤$(tput sgr 0) Invalid input. [yes,no]"
;;
esac
done
LOOP=1
add_pool $LOOP
ICANWALLET=${wallet//[[:blank:]]/}
validate_wallet $ICANWALLET
echo "$(tput setaf 2)●$(tput sgr 0) Wallet validated."
echo
(( LOOP++ ))
while true
do
read -r -p "$(tput setaf 3)➤$(tput sgr 0) Do you wish to add additional pool? [yes/no] " back
case $back in
[yY][eE][sS]|[yY])
add_pool $LOOP
(( LOOP++ ))
;;
[nN][oO]|[nN])
break
;;
*)
echo "$(tput setaf 1)➤$(tput sgr 0) Invalid input. [yes,no]"
;;
esac
done
echo
echo "$(tput setaf 2)●$(tput sgr 0) Saving the settings."
EXPORTDATA=""
if [[ "$threads" -gt "0" ]]; then
EXPORTDATA+="$CONFIG wallet=${ICANWALLET} worker=${worker} threads=${threads}"
else
EXPORTDATA+="$CONFIG wallet=${ICANWALLET} worker=${worker}"
fi
for ((i = 1; i < $LOOP; i++)); do
EXPORTDATA+=" server[$i]=${server[$i]} port[$i]=${port[$i]}"
done
export_config $EXPORTDATA
echo
while true
do
read -r -p "$(tput setaf 3)➤$(tput sgr 0) Add the autostart service? [yes/no] " autostart
case $autostart in
[yY][eE][sS]|[yY])
autostart_service
exit 0
break
;;
[nN][oO]|[nN])
break
;;
*)
echo "$(tput setaf 1)➤$(tput sgr 0) Invalid input. [yes,no]"
;;
esac
done
echo
while true
do
read -r -p "$(tput setaf 3)➤$(tput sgr 0) Start mining now? [yes/no] " mine
case $mine in
[yY][eE][sS]|[yY])
STRATUM=""
for ((i = 1; i < $LOOP; i++)); do
STRATUM+=`compose_stratum "$ICANWALLET" "${server[$i]}" "${port[$i]}" "$worker"`
STRATUM+=" "
done
start_mining "$threads" $STRATUM
break
;;
[nN][oO]|[nN])
exit 0
;;
*)
echo "$(tput setaf 1)➤$(tput sgr 0) Invalid input. [yes,no]"
;;
esac
done
fi
sleep 60
done