This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stereum-control-center-cli.sh
executable file
·418 lines (337 loc) · 12.9 KB
/
stereum-control-center-cli.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
#!/bin/bash
# check for sudo/root first, make sure to have privileges to install stuff and configure
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root or with sudo."
exit 1
fi
dialog_title="Stereum Control Center"
stereum_config_file_path=/etc/stereum/ethereum2.yaml
function dialog_import_wallet() {
if [ "$(setup)" == "multiclient" ]; then
choice_validator_number=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the number of the validator_keys:" 9 60 "" \
3>&1 1>&2 2>&3)
choice_validator_mnemonic=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the mnemonic of the validator_keys:" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "Importing keys..." 3 19
ansible-playbook \
-e validator_number="$choice_validator_number" \
-e validator_mnemonic="$choice_validator_mnemonic" \
-v \
"$(e2a_install_path)/import-validator-accounts.yaml" \
> /dev/null 2>&1
else
choice_launchpad_wallet_path=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the directory of the validator_keys\n(e. g. /tmp/validator_keys):" 9 60 "" \
3>&1 1>&2 2>&3)
choice_launchpad_wallet_password=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the password of the validator_keys:" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "Importing keys..." 3 19
ansible-playbook \
-e validator_keys_path="$choice_launchpad_wallet_path" \
-e validator_password="$choice_launchpad_wallet_password" \
-v \
"$(e2a_install_path)/import-validator-accounts.yaml" \
> /dev/null 2>&1
fi
dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--msgbox "Import done, please see /var/log/anisble.log or grafana for details!" 6 50
dialog --clear
dialog_main
}
function dialog_update() {
choice_update_version_tag=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "What version do you want to use?" 9 60 "$(update_available)" \
3>&1 1>&2 2>&3)
(
echo "XXX"; echo "Downloading new version..."; echo "XXX"
echo "10"; ansible-playbook -e stereum_version_tag_override="$choice_update_version_tag" -v "$(e2a_install_path)/stop-and-update.yaml" > /dev/null 2>&1
echo "XXX"; echo "Configuring..."; echo "XXX"
echo "60"; ansible-playbook -v --inventory="stereumnodes," --connection=local "$(e2a_install_path)/finish-update.yaml" > /dev/null 2>&1
echo "XXX"; echo "Done!"; echo "XXX"
echo "100"; sleep 1
) |
dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--gauge "Starting update..." \
8 40
dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--msgbox "Update done, services restarted!" 5 50
dialog --clear
dialog_main
}
function dialog_unattended_update() {
dialog --backtitle "$dialog_backtitle" \
--title "Unattended Automized Updates" \
--yesno "Do you want to install updates automatically?" \
0 0
choice=$?
if [ $choice == 0 ]; then
auto_update_check_updates="true"
auto_update_install_updates="true"
auto_update_lane=$(dialog --backtitle "$dialog_backtitle" \
--title "Unattended Automized Updates" \
--menu "Please choose the lane you want to receive updates of:" 0 0 0 \
"stable" "Install only stable updates (highly recommended!)" \
"rc" "Install release candidates (this can break your setup!)" \
3>&1 1>&2 2>&3)
else
auto_update_check_updates="false"
auto_update_install_updates="false"
auto_update_lane="stable"
fi
ansible-playbook \
-e "{ \"update\": { \"lane\": \"$auto_update_lane\", \"unattended\": { \"check\": $auto_update_check_updates, \"install\": $auto_update_install_updates } } }" \
-v \
"$(e2a_install_path)/configure-autoupdate.yaml" \
> /dev/null 2>&1
dialog_main
}
function dialog_graffiti() {
choice_graffiti=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter new graffiti:" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "Setting graffiti..." 0 0
ansible-playbook \
-e e2dc_graffiti_updated="$choice_graffiti" \
-v \
"$(e2a_install_path)/set-graffiti.yaml" \
> /dev/null 2>&1
dialog_main
}
function dialog_api_bind_addr() {
choice_api_bind_addr=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter new IP to bind api listening:" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "Setting api bind address..." 0 0
ansible-playbook \
-e e2dc_api_bind_address_updated="$choice_api_bind_addr" \
-v \
"$(e2a_install_path)/set-api-bind-address.yaml" \
> /dev/null 2>&1
dialog_main
}
function dialog_restart_host() {
dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--yesno "Are you sure to restart the host?" \
0 0
choice=$?
if [ $choice != 0 ]; then
dialog --clear
dialog_main
else
clear
reboot
fi
}
function dialog_restart_services() {
(
echo "XXX"; echo "Restarting services..."; echo "XXX"
echo "10"; ansible-playbook -v "$(e2a_install_path)/restart-services.yaml" > /dev/null 2>&1
echo "XXX"; echo "Done!"; echo "XXX"
echo "100"; sleep 1
) |
dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--gauge "Restarting services..." \
8 40
dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--msgbox "Restarting done, services restarted." 5 50
dialog --clear
dialog_main
}
function dialog_geth_prune() {
dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--yesno "While geth is in the process of pruning there is no way your validators can create blocks. The process might take several hours depending on your hardware.\n\nDo you want to continue?" \
0 0
choice=$?
if [ $choice != 0 ]; then
dialog --clear
dialog_main
else
ansible-playbook -v "$(e2a_install_path)/geth-prune.yaml" > /dev/null 2>&1 &
dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--msgbox "Geth stoppend and pruning started.\n\nGeth will start automatically after pruning is done!" 0 0
dialog --clear
dialog_main
fi
}
function dialog_port_list() {
dialog --backtitle "$dialog_backtitle" \
--infobox "Reading services and ports..." 3 34
ansible-playbook -v "$(e2a_install_path)/list-ports.yaml" > /dev/null 2>&1
dialog --backtitle "$dialog_backtitle" \
--textbox "$(e2dc_install_path)/open-ports-list.txt" 0 0
dialog --clear
dialog_main
}
function dialog_exit_validator() {
if [[ "$(setup)" == "lodestar" || "$(setup)" == "prysm" || "$(setup)" == "nimbus" ]]; then
choice_validator_pubkey=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter validator's pubkey ( e. g: 0x1234abcd..... ):" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "exiting validator account..." 0 0
ansible-playbook \
-e validator_pubkey="$choice_validator_pubkey" \
-v \
"$(e2a_install_path)/exit-validator-accounts.yaml" \
> /dev/null 2>&1
elif [ "$(setup)" == "teku" ]; then
choice_validator_keystore_file=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the name of keystore file without '.json' extension (e.g: keystore-m_12345_1234_0_0_0-1234567890 ) :" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "exiting validator account..." 0 0
ansible-playbook \
-e validator_keystore="$choice_validator_keystore_file" \
-v \
"$(e2a_install_path)/exit-validator-accounts.yaml" \
> /dev/null 2>&1
elif [ "$(setup)" == "lighthouse" ]; then
choice_validator_keystore_file=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the name of keystore file (e.g: keystore-m_12345_1234_0_0_0-1234567890.json ) :" 9 60 "" \
3>&1 1>&2 2>&3)
choice_validator_password=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter account password:" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "exiting validator account..." 0 0
ansible-playbook \
-e validator_keystore="$choice_validator_keystore_file" \
-e validator_password="$choice_validator_password" \
-v \
"$(e2a_install_path)/exit-validator-accounts.yaml" \
> /dev/null 2>&1
fi
dialog_main
}
function dialog_delete_validator() {
if [[ "$(setup)" == "lodestar" || "$(setup)" == "prysm" || "$(setup)" == "nimbus" || "$(setup)" == "lighthouse" ]]; then
choice_validator_pubkey=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the public key of validator account( e. g: 0x1234abcd..... ):" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "deleting validator account..." 0 0
ansible-playbook \
-e validator_pubkey="$choice_validator_pubkey" \
-v \
"$(e2a_install_path)/delete-validator-accounts.yaml" \
> /dev/null 2>&1
elif [ "$(setup)" == "teku" ]; then
choice_validator_keystore_file=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the name of keystore file without '.json' extension (e.g: keystore-m_12345_1234_0_0_0-1234567890 ) :" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "deleting validator account..." 0 0
ansible-playbook \
-e validator_keystore="$choice_validator_keystore_file" \
-v \
"$(e2a_install_path)/delete-validator-accounts.yaml" \
> /dev/null 2>&1
fi
dialog_main
}
function dialog_export_config() {
choice_config_password=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title" \
--inputbox "Please enter the password for exporting configuration file:" 9 60 "" \
3>&1 1>&2 2>&3)
dialog --backtitle "$dialog_backtitle" \
--infobox "importing configuration..." 0 0
ansible-playbook \
-e export_config_password="$choice_config_password" \
-v \
"$(e2a_install_path)/export-config.yaml" \
> /dev/null 2>&1
dialog_main
}
function dialog_main() {
choice_main=$(dialog --backtitle "$dialog_backtitle" \
--title "$dialog_title - Main Menu" \
--menu "" 0 0 0 \
"import-wallet" "Import a wallet of launchpad.ethereum.org" \
"update" "Update your Stereum Node Setup" \
"unattended-update" "Configure unattended automized updates" \
"graffiti" "Set graffiti for staking" \
"api-bind-addr" "Bind address for apis (default: 127.0.0.1)" \
"restart-host" "Restart the server" \
"restart-services" "Restart certain services" \
"geth-prune" "Prune geth to reallocate disk space" \
"port-list" "List used ports" \
"exit-account" "Voluntary exit of validator" \
"delete-account" "Safely remove a validator account" \
"export-config" "Export currently running configuration" \
"quit" "Quit the Stereum Control Center" \
3>&1 1>&2 2>&3)
dialog --clear
if [ "$choice_main" == "import-wallet" ]; then
dialog_import_wallet
elif [ "$choice_main" == "update" ]; then
dialog_update
elif [ "$choice_main" == "unattended-update" ]; then
dialog_unattended_update
elif [ "$choice_main" == "graffiti" ]; then
dialog_graffiti
elif [ "$choice_main" == "api-bind-addr" ]; then
dialog_api_bind_addr
elif [ "$choice_main" == "restart-host" ]; then
dialog_restart_host
elif [ "$choice_main" == "restart-services" ]; then
dialog_restart_services
elif [ "$choice_main" == "geth-prune" ]; then
dialog_geth_prune
elif [ "$choice_main" == "port-list" ]; then
dialog_port_list
elif [ "$choice_main" == "exit-account" ]; then
dialog_exit_validator
elif [ "$choice_main" == "delete-account" ]; then
dialog_delete_validator
elif [ "$choice_main" == "export-config" ]; then
dialog_export_config
elif [ "$choice_main" == "quit" ]; then
clear
exit 0
fi
}
function check_config() {
if [[ -f "$(stereum_config_file_path)" ]]; then
echo "Found config $(stereum_config_file_path)"
script_relative_path="$(dirname "$(readlink -f "$0")")"
source "${script_relative_path}/helper/yaml.sh"
create_variables "$stereum_config_file_path"
stereum_version_tag=$(git -C "$(e2ccc_install_path)" describe --tags)
dialog_backtitle="Stereum Node Control Center - $stereum_version_tag"
else
echo "No config found at $stereum_config_file_path"
exit 1
fi
}
check_config
dialog_main
#EOF