This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
monero-bash
executable file
·511 lines (491 loc) · 15 KB
/
monero-bash
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
#!/usr/bin/env bash
#
# monero-bash - a wrapper for Monero written in Bash
#
# Copyright (c) 2022 hinto.janaiyo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Parts of this project are originally:
# Copyright (c) 2019-2022, jtgrassie
# Copyright (c) 2014-2022, The Monero Project
# Copyright (c) 2011-2022, Dominic Tarr
#
# Parts of this project are licensed under GPLv2:
# Copyright (c) ????-2022, Tamas Szerb <toma@rulez.org>
# Copyright (c) 2008-2022, Robert Hogan <robert@roberthogan.net>
# Copyright (c) 2008-2022, David Goulet <dgoulet@ev0ke.net>
# Copyright (c) 2008-2022, Alex Xu (Hello71) <alex_y_xu@yahoo.ca>
# This is the [main] script for [monero-bash].
# It REQUIRES and takes a lot of safety precautions
# to make sure everything found in `src` exists.
# | File/Folder | Purpose |
# |----------------|-----------------------------------------------|
# | api/ | internal file-based api used by [monero-bash] |
# | func/ | all the functions [monero-bash] uses |
# | txt/ | text files to store long-term on disk |
# | debug.sh | debugging functions |
# | libtorsocks.so | builtin torsocks library |
# | source.sh | master source file that sources vars/funcs |
# | var.sh | frequently used GLOBAL variables |
#
# [monero-bash] order of operations
# 1. User inputs [monero-bash <something>]
# 2. [monero-bash] sources -> [source.sh]
# 3. [source.sh] sources -> functions, state, variables
# 4. `parse_Config()` parses user configs safely
# 5. A whole bunch of safety checks
# 6. Parse & execute user input (update, wallet, etc)
# 2022-08-14 [v1.8.0]
# -------------------
# There's a lot of baggage and bad code/design
# in [monero-bash] for backwards compatibility.
# You can still install [monero-bash v1.0.0] and
# upgrade directly to the latest version...!
#
# But it's also because I didn't think ahead.
# Stuff like:
# - confusing paths
# - bad function names
# - bad variable names
# - over-complicated functions
# - files being un-upgradable (state/configs)
#
# Since [v2.0.0] is planned to be a hard-fork
# and incompatible with [v1.x.x] versions, I'll
# just continue to maintain and expand on the
# bad [v1.x.x] code instead of rebuilding it all.
# That's what [v2.0.0] will be for :)
#-------------------------------------------------------------------------------------------- BEGIN MAIN
# installDirectory = whereever /monero-bash/ is
scriptPath="$(realpath $0)"
installDirectory="$(dirname "$scriptPath")"
# Check if script is in [monero-bash] folder
if [[ $installDirectory != *"/monero-bash" ]]; then
printf "\033[1;31mExecuting monero-bash while it isn't in the /monero-bash/ folder is DANGEROUS\n"
printf "\033[0;31mExiting for safety...\n"
exit 1
fi
# Make the root reference folder [/usr/local/share/monero-bash]
cd "$installDirectory" || exit 99
# Source files, exit on failure
if ! source "$installDirectory/src/source.sh"; then
printf "\e[1;31m%s\n" "[MONERO BASH FATAL ERROR] SOURCING FAIL"
exit 1
fi
# Exit on any source failure
case true in
$varMissing) printf "\033[1;31mMONERO BASH: Variables not sourced\n"; exit 1;;
$funcMissing) printf "\033[1;31mMONERO BASH: Functions not sourced\n"; exit 1;;
$stateMissing) printf "\033[1;31mMONERO BASH: state file missing\n"; exit 1;;
$debugMissing) printf "\033[1;31mMONERO BASH: debug file missing\n"; exit 1;;
$hashlistMissing) printf "\033[1;31mMONERO BASH: hashlist file missing\n"; exit 1;;
esac
# DEBUG COMMAND - read /src/debug for more info
if [[ $1 = "DEBUG_04e3be9" ]]; then
case $2 in
"") DEBUG_04e3be9 ;;
*) "$2" ;;
esac
exit
fi
# Safety checks
safety_Root
safety::gnu_linux
safety::bash
# Warn against stdin
if [[ -p /dev/stdin ]]; then
print_Warn "monero-bash does not actively support stdin!"
print_Warn "Be careful, things will probably break."
fi
# Installation
if [[ $FIRST_TIME = "true" ]]; then
monerobash_Install
exit
fi
# Parse/source config files
parse_Config || { printf "\e[1;31m%s\n" "[MONERO BASH FATAL ERROR] Config source failure"; panic; }
safety::env
safety_User
safety_DotMoneroBash
missing_Wallets
missing_config_Folder
missing_config_All
missing_systemd_All
# Interactive/option check
[[ $1 ]] && options=true || interactive=true
# Interactive Wallet Selection
if [[ $interactive = "true" ]]; then
print_MoneroBashTitle
if [[ $AUTO_UPDATE = "true" ]]; then
update_All
echo
fi
# SHOW WALLETS, SELECT
wallet_Count; wallet_List
while true; do
printf "${BYELLOW}%s${OFF}%s${BPURPLE}%s${OFF}%s${BRED}%s${OFF}" \
"[Select wallet]" " or " "[new]" " or " "[exit] "
read -r walletSelection
for i in ${walletList[*]}; do
# IF WALLET NAME COLLIDES WITH OPTION, ASK FOR CLARIFICATION
if [[ $walletSelection = $i && $walletSelection = "new" ]]; then
echo "Wallet name is similar to option..."
while :; do
printf "${BYELLOW}%s${OFF}%s${BPURPLE}%s${OFF}" "SELECT " "or " "NEW? "
read selectNew
case $selectNew in
select|Select|SELECT)
printf "${BYELLOW}%s${BWHITE}%s${OFF}\n" "Selecting " "[$walletSelection]"
printf "%s" "Password: "
read -s -r walletPassword
printf "\n\n"
printf "${BYELLOW}%s${BWHITE}%s${OFF}\n" "Starting wallet " "[$walletSelection]"
wallet_Start
;;
new|New|NEW)
printf "\n${OFF}%s\n" "Creating new wallet..."
wallet::create
;;
*) print_Error "Invalid option" ;;
esac
done
# START WALLET IF MATCH
elif [[ $walletSelection = $i ]]; then
printf "%s" "Password: "
read -s -r walletPassword
printf "\n\n"
printf "${BYELLOW}%s${BWHITE}%s${OFF}\n" "Starting wallet " "[$walletSelection]"
wallet_Start
fi
done
# OR CATCH WALLET CREATION & ERROR INPUT
case $walletSelection in
new|New|NEW) wallet::create; break;;
'exit'|'Exit'|'EXIT') exit 0;;
'exit()') printf "%s\n" "This isn't Python but ok >_>"; exit 0;;
'exit(0);') printf "%s\n" "This isn't C but ok >_>"; exit 0;;
"") print_Error "Empty input" ;;
*) IRED; print_Error "Wallet <${walletSelection}> not found" ;;
esac
done
exit
fi
# Option Flags
if [[ $options = true ]]; then
case $1 in
backup) backup_Wallets ;;
decrypt) backup_Decrypt ;;
uninstall) monerobash_Uninstall ;;
update) update_All ;;
version) print_Version ;;
list) print_MoneroBashTitle && wallet_Count && wallet_List ;;
size) print_Size ;;
price) price_Check ;;
status)
case $2 in
*"daemon"*|*"monero"*) status_Monero && journalctl --no-pager -n 5 -u monero-bash-monerod --output cat;;
*"xmr"*) prompt_Sudo;error_Sudo; status_XMRig && sudo journalctl --no-pager -n 5 -u monero-bash-xmrig --output cat;;
*"p2p"*) status_P2Pool && journalctl --no-pager -n 5 -u monero-bash-p2pool --output cat;;
*) status_All;;
esac
;;
integrity) CHECK_HASH_LIST ;;
help) print_Usage ;;
config) mine_Config ;;
tor)
USE_TOR=true TEST_TOR=true TOR_QUIET=false
[[ $TOR_PROXY ]] || { print_Warn "[TOR_PROXY] not found in [monero-bash], falling back to [localhost:9050]"; TOR_IP=localhost TOR_PORT=9050; }
[[ $FAKE_HTTP_HEADERS = true ]] && header_Random
torsocks_init
exit
;;
rpc)
if [[ -z $2 || $2 = help ]]; then
print_rpc_Usage | less -R
else
shift
rpc_Daemon "$@"
fi
;;
seed)
if [[ $2 ]]; then
seedOptions="true"
seedLanguage="$2"
fi
seed_Create
;;
edit)
case $2 in
*bash*) define_MoneroBash;;
*"wallet"*) define_Monero;EDIT_CONFIG=wallet;;
*"monerod"*) define_Monero;EDIT_CONFIG=daemon;;
*"daemon"*|*"monero"*) define_Monero;;
*"xmr"*) define_XMRig;;
*"p2p"*) define_P2Pool;;
*) print_Error_Exit "Pick: <bash/monero/p2pool/xmrig>" ;;
esac
[[ $NAME_VER ]] || print_Error_Exit "$NAME_PRETTY isn't installed"
if [[ $2 = *bash* && -z $3 ]]; then
edit_Config
else
case $3 in
conf*|config) edit_Config;;
sys*|systemd|service)
if [[ $2 = *bash* ]]; then
print_Error_Exit "monero-bash does not have a systemd file"
else
edit_Systemd
fi
;;
*) print_Error_Exit "Pick a file to edit: <config/systemd>"
esac
fi
;;
reset)
case $2 in
*"bash"*) define_MoneroBash;;
*"daemon"*|*"monero"*) define_Monero;;
*"xmr"*) define_XMRig;;
*"p2p"*) define_P2Pool;;
*) print_Error_Exit "Pick: <bash/monero/p2pool/xmrig>" ;;
esac
[[ $NAME_VER ]] || print_Error_Exit "$NAME_PRETTY isn't installed"
if [[ $2 = *bash* && -z $3 ]]; then
reset_Config
else
case $3 in
conf*|config) reset_Config;;
sys*|systemd|service)
if [[ $2 = *bash* ]]; then
print_Error_Exit "monero-bash does not have a systemd file"
else
reset_Systemd
fi
;;
*) print_Error_Exit "Pick a file to edit: <config/systemd>"
esac
fi
;;
start)
shift
case "$*" in
*"daemon"*|*"monero"*) define_Monero;;
*"xmr"*) define_XMRig;;
*"p2p"*) define_P2Pool;;
all) mine_Start; exit;;
*) print_Error_Exit "Pick: <all/monero/p2pool/xmrig>" ;;
esac
process_Start
;;
stop)
case $2 in
*"daemon"*|*"monero"*) define_Monero;;
*"xmr"*) define_XMRig;;
*"p2p"*) define_P2Pool;;
all) mine_Stop; exit;;
*) print_Error_Exit "Pick: <all/monero/p2pool/xmrig>" ;;
esac
process_Stop
;;
restart)
case $2 in
*"daemon"*|*"monero"*) define_Monero;;
*"xmr"*) define_XMRig;;
*"p2p"*) define_P2Pool;;
all) mine_Restart; exit ;;
*) print_Error_Exit "Pick: <all/monero/p2pool/xmrig>" ;;
esac
process_Restart
;;
full)
case $2 in
*"daemon"*|*"monero"*) define_Monero;;
*"xmr"*) define_XMRig;;
*"p2p"*) define_P2Pool;;
*) print_Error_Exit "Pick: <monero/xmrig/p2pool>" ;;
esac
process_Full
;;
watch)
declare -g FIRST_WATCH=true
shopt -s checkwinsize
case $2 in
*"daemon"*|*"monero"*) watch_Monero ;;
*"xmr"*) watch_XMRig ;;
*"p2p"*) watch_P2Pool ;;
*) watch_Status;;
esac
;;
enable)
case $2 in
*"daemon"*|*"monero"*) define_Monero;;
*"xmr"*) define_XMRig;;
*"p2p"*) define_P2Pool;;
all) define_Monero;process_Enable;define_XMRig;process_Enable;define_P2Pool;process_Enable;exit;;
*) print_Error_Exit "Pick: <all/monero/xmrig/p2pool>" ;;
esac
process_Enable
;;
disable)
case $2 in
*"daemon"*|*"monero"*) define_Monero ;;
*"xmr"*) define_XMRig ;;
*"p2p"*) define_P2Pool ;;
all) define_Monero;process_Disable;define_XMRig;process_Disable;define_P2Pool;process_Disable;exit;;
*) print_Error_Exit "Pick: <all/monero/xmrig/p2pool>" ;;
esac
process_Disable
;;
upgrade)
[[ $* = *"verbose"* ]]&& VERBOSE="true" &&IBLUE&& echo "Verbosely upgrading...!" ;OFF
[[ $* = *"force"* ]]&& FORCE_UPGRADE="true" &&IRED&& echo "Forcefully upgrading...!" ;OFF
UPGRADE_LIST=${2//verbose}
UPGRADE_LIST=${UPGRADE_LIST//force}
case $UPGRADE_LIST in
*"bash"*)
BWHITE; echo -n "Upgrade [monero-bash]? (Y/n) " ;OFF
Yes(){ upgrade_MoneroBash ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
*"daemon"*|*"monero"*|*"Monero"*)
BWHITE; echo -n "Upgrade [Monero]? (Y/n) " ;OFF
Yes(){ upgrade_Monero ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
*"xmr"*|*"Xmr"*|*"XMR"*)
BWHITE; echo -n "Upgrade [XMRig]? (Y/n) " ;OFF
Yes(){ upgrade_XMRig ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
*"p2p"*|*"P2P"*|*"P2p"*)
BWHITE; echo -n "Upgrade [P2Pool]? (Y/n) " ;OFF
Yes(){ upgrade_P2Pool ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
""|all|All|ALL)
if [[ $FORCE_UPGRADE = "true" ]]; then
upgrade_Force
else
print_Upgrade
BWHITE; echo -n "Upgrade? (Y/n) " ;OFF
Yes(){ upgrade_All ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
fi
;;
*)
print_Error "Pick a package or <all>"
print_Version
exit 1
;;
esac
;;
install)
[[ $* = *"verbose"* ]]&& VERBOSE="true" &&IBLUE&& echo "Verbosely installing...!" ;OFF
case $2 in
*"bash"*|*"Bash"*|*"BASH"*)
BWHITE; echo -n "Install [monero-bash]? (Y/n) " ;OFF
Yes(){ install_MoneroBash ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
monero|Monero|MONERO)
BWHITE; echo -n "Install [Monero]? (Y/n) " ;OFF
Yes(){ install_Monero ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
xmrig|XMRig|XMRIG|Xmrig|xmr|Xmr)
BWHITE; echo -n "Install [XMRig]? (Y/n) " ;OFF
Yes(){ install_XMRig ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
*"p2p"*|*"P2P"*|*"P2p"*)
BWHITE; echo -n "Install [P2Pool]? (Y/n) " ;OFF
Yes(){ install_P2Pool ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
all|All|ALL)
print_Install
BWHITE; echo -n "Install? (Y/n) " ;OFF
Yes(){ install_All ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
*)
print_Error "Pick a package or <all>"
print_Version
exit 1
;;
esac
;;
remove)
case $2 in
*"bash"*|*"Bash"*|*"BASH"*)
BWHITE; echo -n "Remove [monero-bash]? (Y/n) " ;OFF
Yes(){ remove_MoneroBash ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
monero|Monero|MONERO)
BWHITE; echo -n "Remove [Monero]? (Y/n) " ;OFF
Yes(){ remove_Monero ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
xmrig|XMRig|XMRIG|Xmrig|xmr|Xmr)
BWHITE; echo -n "Remove [XMRig]? (Y/n) " ;OFF
Yes(){ remove_XMRig ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
*"p2p"*|*"P2P"*|*"P2p"*)
BWHITE; echo -n "Remove [P2Pool]? (Y/n) " ;OFF
Yes(){ remove_P2Pool ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
all|All|ALL)
print_Remove
BWHITE; echo -n "Remove? (Y/n) " ;OFF
Yes(){ remove_All ;}
No(){ echo "Exiting..." ;exit 1;}
prompt_YESno
;;
*)
print_Error "Pick a package or <all>"
print_Version
exit 1
;;
esac
;;
*)
print_Error "Invalid option!"
printf "${OFF}%s${BYELLOW}%s${OFF}\n" "For help, type: " "[monero-bash help]"
exit 1
esac
exit
fi