-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwizard
344 lines (306 loc) · 10.4 KB
/
wizard
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
#!/bin/bash
# Contact: <info@minerstat.com>
# Mail: Sepapaja tn 6, Lasnamäe district, Tallinn city, Harju county, 15551, Estonia
# © minerstat OÜ in 2019
echo "================ minerstat OÜ © 2019 ================"
echo "ASIC Hub (Non-SSH) Installation Wizard"
echo "For live chat join us on Discord: https://minerstat.com/discord"
TOKEN=$1
GROUP=$2
MAX_REQUEST_AT_A_TIME=$3
current_date () {
DATE=`date '+%H:%M:%S'`
}
if [ -z "$MAX_REQUEST_AT_A_TIME" ]; then
MAX_REQUEST_AT_A_TIME=60
fi
echo
echo "Preparing.."
sleep 2
# System check
if [ "$(uname)" == "Darwin" ]; then
SYSTEM="MAC";
else
SYSTEM="LINUX";
fi
PIFETCH=$(cat /proc/device-tree/model 2> /dev/null)
if [[ $PIFETCH == *"Raspberry"* ]]; then
SYSTEM="RASPBERRY"
fi
ARCHFETCH=$(cat /etc/issue 2> /dev/null)
if [[ $ARCHFETCH == *"Arch"* ]]; then
echo "ARCH LINUX NOT SUPPORTED"
echo "PLEASE, USE UBUNTU (PC) // RASPBIAN BUSTER (PI)"
exit 0
fi
CRONTAB=$(crontab -l | xargs -0)
if [ "$SYSTEM" = "MAC" ]; then
EXECNAME="hub-mac"
LOCATION="/usr/local/bin"
elif [ "$SYSTEM" = "LINUX" ]; then
EXECNAME="hub-linux"
LOCATION="/usr/bin"
else
EXECNAME="hub-pi"
LOCATION="/usr/bin"
fi
echo
echo "-------------------"
# Echo temporary data about software type and system
echo "= System : $SYSTEM"
echo "= Exec : $EXECNAME"
# Dependencies Check
which curl 2>&1 >/dev/null && curlPresent=true
which jq 2>&1 >/dev/null && jqPresent=true
which dialog 2>&1 >/dev/null && dialogPresent=true
which screen 2>&1 >/dev/null && screenPresent=true
which tac 2>&1 >/dev/null && tacPresent=true
if [ -z "${curlPresent:-}" ] || [ -z "${jqPresent:-}" ] || [ -z "${dialogPresent:-}" ] || [ -z "${tacPresent:-}" ] || [ -z "${screenPresent:-}" ]; then
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
echo "= INSTALLING DEPENDENCIES"
echo ""
sleep 2
if [ $SYSTEM = "MAC" ]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install wget curl jq dialog screen gnu-sed coreutils
else
FILE="/media/storage/config.js"
#if [[ -f "$FILE" ]]; then
sudo apt --yes --force-yes --fix-broken install
#fi
sudo apt-get --yes --force-yes install wget curl jq dialog screen
if [[ -f "$FILE" ]]; then
NVIDIA="$(nvidia-smi -L)"
if echo "$NVIDIA" | grep -iq "^GPU 0:" ;then
CHECKAPTXN=$(dpkg -l | grep "libegl1-amdgpu-pro" | wc -l)
if [ "$CHECKAPTXN" -gt "0" ]; then
sudo dpkg --remove --force-all libegl1-amdgpu-pro:i386 libegl1-amdgpu-pro:amd64
fi
fi
fi
fi
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
sleep 3
fi
unset curlPresent
unset jqPresent
unset dialogPresent
unset tacPresent
# COLOR
rm ~/.dialogrc 2> /dev/null
dialog --create-rc ~/.dialogrc
echo 'aspect = 0separate_widget = ""
tab_len = 0
visit_items = ON
use_shadow = OFF
use_colors = ON
screen_color = (WHITE,BLACK,OFF)
shadow_color = (BLACK,BLACK,OFF)
dialog_color = (WHITE,BLACK,OFF)
title_color = (CYAN,BLACK,OFF)
border_color = (CYAN,BLACK,OFF)
button_active_color = (CYAN,BLACK,ON)
button_inactive_color = dialog_color
button_key_active_color = button_active_color
button_key_inactive_color = (WHITE,BLACK,OFF)
button_label_active_color = (CYAN,BLACK,ON)
button_label_inactive_color = (WHITE,BLACK,ON)
inputbox_color = dialog_color
inputbox_border_color = border_color
searchbox_color = dialog_color
searchbox_title_color = title_color
searchbox_border_color = border_color
position_indicator_color = title_color
menubox_color = dialog_color
menubox_border_color = border_color
item_color = dialog_color
item_selected_color = button_active_color
tag_color = title_color
tag_selected_color = button_label_active_color
tag_key_color = button_key_inactive_color
tag_key_selected_color = (CYAN,BLACK,ON)
check_color = dialog_color
check_selected_color = button_active_color
uarrow_color = (CYAN,WHITE,ON)
darrow_color = uarrow_color
itemhelp_color = (WHITE,BLACK,OFF)
form_active_text_color = button_active_color
form_text_color = (CYAN,RED,ON)
form_item_readonly_color = (CYAN,WHITE,ON)
gauge_color = title_color
border2_color = border_color
inputbox_border2_color = border_color
searchbox_border2_color = border_color
menubox_border2_color = border_color' > ~/.dialogrc
dialog --backtitle "minerstat ASIC Hub (Non-SSH) Wizard" --title " ASIC Hub (Non-SSH) " --msgbox "Before you start make sure you are registered on my.minerstat.com and you have added at least one ASIC to your minerstat dashboard." 12 42
# Ask Info if Args empty & No defined
if [ -z "$TOKEN" -a "$TOKEN" != " " ]; then
echo '= Enter your minerstat ACCESS KEY'
TOKEN=$(dialog --backtitle "minerstat ASIC Hub (Non-SSH) Wizard" --title " Enter your access key " --inputbox "You can find your access key by hovering mouse over your avatar in the top right corner on my.minerstat.com or in the e-mail we have sent you. Access key is case-sensitive." 12 42 2>&1 1>/dev/tty)
fi
if [ -z "$GROUP" -a "$GROUP" != " " ]; then
echo '= Enter group/location [Default: asic] [Enter to skip]'
GROUP=$(dialog --backtitle "minerstat ASIC Hub (Non-SSH) Wizard" --title " Enter group for monitoring " --inputbox "Enter the group name of the workers you want to monitor. Default group is asic." 12 42 2>&1 1>/dev/tty)
fi
if [ -z "$TOKEN" ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!! ERROR: Missing Access Key"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 0
fi
if [ -z "$GROUP" ]; then
echo
echo '!! WARNING: No group/location provided.'
echo '!! WARNING: Monitoring all worker(s) on the account'
GROUP="asic"
fi
# Check it is installed
FILE="$LOCATION/$EXECNAME"
if [[ -f "$FILE" ]]; then
INSTALLED="YES"
else
INSTALLED="NO"
fi
echo "= ACCESS KEY : $TOKEN"
echo "= GROUP : $GROUP"
echo "= Installed? : $INSTALLED"
echo "-------------------"
echo
# ULIMIT CHECK
MAX_REQUEST_SYSTEM=$(ulimit -n | xargs -0)
MAX_REQUEST_AT_ALL_TIME=$(($MAX_REQUEST_AT_A_TIME*3))
if [ "$MAX_REQUEST_AT_A_TIME" = "60" ]; then
MAX_REQUEST_AT_PER_TIME=$(($MAX_REQUEST_SYSTEM/3))
else
MAX_REQUEST_AT_PER_TIME=$(($MAX_REQUEST_AT_A_TIME/3))
fi
# Ulimit Protection
if [ $MAX_REQUEST_SYSTEM -lt $MAX_REQUEST_AT_ALL_TIME ]; then
echo ""
echo "-----------------------"
echo "= CRITICAL ERROR!"
echo "-----------------------"
echo ""
echo "= MESSAGE: YOUR SYSTEM DEFINED MAXIMAL ALLOWED REQUEST IS $MAX_REQUEST_SYSTEM"
echo "= YOU HAVE SET $MAX_REQUEST_AT_A_TIME*3 [$MAX_REQUEST_AT_ALL_TIME]"
echo "= ENTER THIS COMMAND BEFORE RUNNING SOFTWARE AGAIN:"
echo ""
echo "ulimit -n $MAX_REQUEST_AT_ALL_TIME"
echo ""
echo "-----------------------"
echo "Press ENTER to exit"
echo "-----------------------"
read -p "[PRESS ENTER]"
exit 0
fi
echo "Validating account ..."
echo "-----------------------"
echo "= ULIMIT : $MAX_REQUEST_AT_ALL_TIME / $MAX_REQUEST_SYSTEM"
API=$(curl -s https://api.minerstat.com/v2/stats/$TOKEN/asicgroups/$GROUP)
API_MAX=$(echo $API | grep "," | wc -w | xargs)
echo "= WORKERS TO MONITOR: $API_MAX"
if [ "$API_MAX" = "0" ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!! ERROR: No workers found on Access Key: $TOKEN, Group: $GROUP"
echo "!! Recheck provided account info and try again. "
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo
exit 0
fi
echo "-----------------------"
# install
if [ "$SYSTEM" = "MAC" ]; then
EXECNAME="hub-mac"
LOCATION="/usr/local/bin"
elif [ "$SYSTEM" = "LINUX" ]; then
EXECNAME="hub-linux"
LOCATION="/usr/bin"
else
EXECNAME="hub-pi"
LOCATION="/usr/bin"
fi
rm $EXECNAME 2> /dev/null
sudo rm -rf $EXECNAME*
wget https://github.com/minerstat/minerstat-asic-hub-non-ssh/releases/download/latest/$EXECNAME
chmod 777 $EXECNAME
echo
echo "-----------------------"
echo "Provide your SYSTEM (USER/ROOT) password below, if the system requires it"
echo "on Linux / macOS this is your user password"
echo "-----------------------"
echo
sudo rm $LOCATION/$EXECNAME
sudo cp -rf $EXECNAME $LOCATION
sudo $LOCATION/$EXECNAME --version
FIRMWARE=""
# firmware questions
if [[ $API == *"antminer"* ]]; then
echo
echo "-----------------------"
echo "ANTMINER machine detected on your account"
echo
sleep 1
FIRMWARE=$(dialog --backtitle "minerstat ASIC Hub (Non-SSH) Wizard" --title " Select firmware " --radiolist "Select with [SPACE] then press [ENTER] to confirm the selection. All ASICs in the group will be monitored with the selected option." 12 42 20 "Factory Firmware" "ORIGINAL" "" "Braiins Firmware" "BRAIINS" "BRAIINS" 2>&1 1>/dev/tty)
#read FIRMWARE
echo "-----------------------"
echo
fi
#if [ ! -z $FIRMWARE ]; then
if [[ $FIRMWARE == *"Braiins"* ]]; then
EXTRA="--firmware braiins"
fi
#fi
echo
echo "Checking for Crontabs ..."
echo "-----------------------"
if [ "$SYSTEM" = "MAC" ]; then
if [[ $CRONTAB == *"local"* ]]; then
echo "= MAC PATH INSTALLED FOR CRON"
else
echo "= INSALLING MAC PATH FOR CRON"
echo "= “Terminal” would like to administer your computer. Administration can include modifying passwords, networking and system settings."
echo "= CLICK on [OK]"
echo "PATH=/usr/local/bin:/usr/bin:/bin" > cron
crontab -l >> cron
crontab cron
rm cron
fi
fi
if [[ $CRONTAB == *"update"* ]]; then
echo "= AUTO UPDATE ALREADY SET"
else
echo "= INSALLING MAC PATH FOR CRON"
echo "= “Terminal” would like to administer your computer. Administration can include modifying passwords, networking and system settings."
echo "= CLICK on [OK]"
crontab -l > cron
echo "0 10 * * * $LOCATION/$EXECNAME --update" >> cron
crontab cron
rm cron
fi
#if [[ $CRONTAB == *"$EXECNAME"* ]]; then
if [[ $CRONTAB == *"--token $TOKEN"* ]] && [[ $CRONTAB == *"--group $GROUP"* ]] && [[ $CRONTAB == *"$EXTRA"* ]]; then
echo "= Installation already found for this access key and group"
INSTALL=""
else
echo "= No installation found for this access key and group"
crontab -l > cron
RN=$((1 + RANDOM % 9999))
echo "* * * * * screen -A -m -d -S mshub$RN $LOCATION/$EXECNAME --token $TOKEN --group $GROUP --limit $MAX_REQUEST_AT_PER_TIME --debug 0 $EXTRA" >> cron
cat cron
crontab cron
rm cron
echo
fi
#fi
dialog --backtitle "minerstat ASIC Hub (Non-SSH) Wizard" --title " Installation finished " --msgbox "If you want to manually edit your cron tabs enter:\n\nexport EDITOR=nano && crontab -e\n\nWhen you finish press [CTRL + O] to save and [CTRL + C] to close the cron tab file." 12 42
clear
echo
echo "Need assistance? "
echo "You can find us on https://minerstat.com/discord (contact person: coinscrow#0001)."
echo