-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path9c-swarm-miner.sh
More file actions
executable file
·293 lines (249 loc) · 5.42 KB
/
9c-swarm-miner.sh
File metadata and controls
executable file
·293 lines (249 loc) · 5.42 KB
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
#!/bin/bash
source bin/cklib.sh
# Check: ROOT
checkRoot
# Set permissions for this project
checkPermissions() {
# Set directory permissions
sudo find . -type d -exec chmod 755 {} \;
# Set file permissions
sudo find . -type f -exec chmod 644 {} \;
# Set scripts as executable
sudo find . -name "*.sh" -exec chmod +x {} \;
}
# Check: Run setup if first run
checkFirstRun() {
if [ ! -f "settings.conf" ] && [ ! -f "docker-compose.yml" ]; then
./bin/setup.sh
else
return
fi
exit 0
}
# Check: settings.conf
checkConfig() {
if [ -f "settings.conf" ]; then
sEntry "settings.conf"
source settings.conf
else
./bin/build-config.sh
fi
}
# Check: docker-compose.yml
checkCompose() {
if [ -f "docker-compose.yml" ]; then
rm -f docker-compose.yml
./bin/build-compose.sh
else
./bin/build-compose.sh
fi
}
# Check: Crontab
checkCronTab() {
if [[ "$NC_CRONJOB_AUTO_RESTART" == 0 ]]; then
./bin/crontab.sh --disable
else
./bin/crontab.sh --enable
fi
}
# Check: Snapshot
checkSnapshot() {
if [[ "$NC_REFRESH_SNAPSHOT" == 1 ]]; then
./bin/manage-snapshot.sh
else
sL
sTitle "Snapshot Management:$C Disabled"
fi
}
# Precheck
preCheck() {
sTitle "Loading Prerequisites"
checkConfig
checkCompose
}
# Cleanup
clean() {
if [[ "$1" == "1" ]]; then
sudo rm -f docker-compose.yml
sudo rm -rf latest-snapshot
sudo rm -f 9c-main-snapshot.zip
sudo rm -rf logs
sudo rm -rf vault
elif [[ "$1" == "2" ]]; then
sudo rm -f docker-compose.yml
sudo rm -f settings.conf
sudo rm -rf latest-snapshot
sudo rm -f 9c-main-snapshot.zip
sudo rm -rf vault
sudo rm -rf logs
else
errCode "Not a valid cleaning option."
fi
}
# Autostart: Logging Docker Containers
autoLog() {
sLL
sTitle "These logging filters will display below: Mined a block | reorged | mining | Append failed"
export GREP_COLORS='ms=1;92'
docker-compose logs --tail=1000 -f | grep --color -i -E 'Mined a block|reorged|mining|Append failed'
}
# Display Log Commands
displayLogCmds() {
sLL
sTitle "Windows Monitor (Full Log):"
sAction "Open Docker and you can access logging for each individual container"
sTitle "Windows Monitor (Mined Blocks Only):"
sAction "Search for 'Mined a block'"
sTitle "Linux Monitor (Full Log):"
sAction "docker-compose logs --tail=100 -f"
sTitle "Linux Monitor (Mined Blocks Only):"
sAction "docker-compose logs --tail=100 -f | grep -A 10 --color -i 'Mined a block'"
sTitle "Linux Monitor (Mined/Reorg/Append failed events):"
sAction "docker-compose logs --tail=100 -f | grep --color -i -E 'Mined a block|reorged|mining|Append failed'"
}
# Asks if user wants to start logging
runLogging() {
sSpacer
sTitle "Miner is started! (May take up to 10+ mins for miner(s) to be fully operational)"
sSpacer
read -r -p "$(echo -e "$S""> Would you like to run auto-logging ['Mined a block|reorged|Append failed'] (Y/n)?: ""$RS")" optionLog
if [[ $optionLog == [yY] || $optionLog == [yY][eE][sS] ]]; then
autoLog
else
exit 0
fi
}
# Update
updateMain() {
sIntro
sTitle "Checking for updates"
startSpinner "Shutting down docker containers:"
docker-compose down -v &> /dev/null
stopSpinner $?
startSpinner "Cleaning old files:"
clean "1"
stopSpinner $?
startSpinner "Pulling from Github:"
{
git pull
} &> /dev/null
stopSpinner $?
./bin/build-config.sh --update
./bin/setup.sh --update
}
# Start Docker Containers
startDocker() {
sL
sTitle "Docker"
startSpinner "Initiating containers:"
{
docker-compose up -d
} &> /dev/null
stopSpinner $?
}
# Check: Docker Logs
checkDockerLog() {
if [[ "$NC_EMAIL" == 0 ]]; then
./bin/email.sh --disable
else
./bin/email.sh --enable
fi
}
###############################
Main() {
sIntro
checkPermissions
checkFirstRun
preCheck
checkCronTab
#checkDockerLog
checkSnapshot
startDocker
displayLogCmds
optionDonate
runLogging
}
###############################
case $1 in
--start)
docker-compose up -d
exit 0
;;
--stop)
docker-compose stop
exit 0
;;
--update)
updateMain
exit 0
;;
--setup)
./bin/setup.sh
exit 0
;;
--settings)
nano ./settings.conf
exit 0
;;
--refresh)
./bin/manage-snapshot.sh
exit 0
;;
--force-refresh)
./bin/manage-snapshot.sh --force
exit 0
;;
--clean)
clean "1"
exit 0
;;
--clean-all)
clean "2"
exit 0
;;
--check-vol)
./bin/manage-snapshot.sh --volume
exit 0
;;
--check-permissions)
checkPermissions
exit 0
;;
--logging)
displayLogCmds
exit 0
;;
--crontab)
docker-compose stop
docker-compose up -d
exit 0
;;
--send-logs)
./bin/email.sh --send
exit 0
;;
--check-gold)
./bin/graphql-query.sh --check-gold
exit 0
;;
--help)
#TODO Add help text to explain each command and usage
exit 0
;;
--private-key)
./bin/key.sh --private
exit 0
;;
--public-key)
./bin/key.sh --public
exit 0
;;
--keys)
./bin/key.sh --all
exit 0
;;
*)
Main
exit 0
;;
esac