forked from lephleg/nano-node-docker
/
banano.sh
executable file
·630 lines (540 loc) · 30 KB
/
banano.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
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
#!/bin/bash
#################################################
# Banano Node Docker #
# https://github.com/amamel/banano-node-docker #
#################################################
# Banano Node Docker Script Version
version='1.0'
# Output Variables
red=$(tput setaf 1) # Set the variable red to the ANSI escape code for red color
green=$(tput setaf 2) # Set the variable green to the ANSI escape code for green color
yellow=$(tput setaf 3) # Set the variable yellow to the ANSI escape code for yellow color
purple=$(tput setaf 5) # Set the variable purple to the ANSI escape code for purple color
bold=$(tput bold) # Set the variable bold to the ANSI escape code for bold text
reset=$(tput sgr0) # Set the variable reset to the ANSI escape code to reset text formatting
# Flags & Arguments
quiet=false # Flag: Quiet mode (default: false)
displaySeed=false # Flag: Display wallet seed (default: false)
fastSync=false # Flag: Enable fast sync (default: false)
domain='' # Argument: Domain name for SSL setup (default: empty)
email='' # Argument: Email for Let's Encrypt SSL setup (default: empty)
tag='' # Argument: Docker image tag (default: empty)
while getopts 'sqfd:e:t:' flag; do
case "$flag" in
s) displaySeed=true ;; # Set displaySeed flag to true if -s option is provided
d) domain="$OPTARG" ;; # Set domain to the value provided after -d option
e) email="$OPTARG" ;; # Set email to the value provided after -e option
q) quiet=true ;; # Set quiet flag to true if -q option is provided
f) fastSync=true ;; # Set fastSync flag to true if -f option is provided
t) tag="$OPTARG" ;; # Set tag to the value provided after -t option
*) exit 1 ;; # Invalid option, exit with error
esac
done
echo $@ >settings
# Function to check the operating system
check_os() {
local os=$(uname -s)
if [[ "$os" != "Linux" ]]; then
echo "[i] ${red}'$os' support is not yet offered by this script${reset}"
exit 1
fi
}
check_os
# Check root user
echo "[${green}✓${reset}] Root user check"
check_root_user() {
if [ "$EUID" -ne 0 ]; then
echo "This script must be run as root." >&2
return 1
fi
}
check_root_user
# Script Deets
echo -e "${green} ================================================================================${reset}"
echo -e "${green}${bold} Banano Node Docker ${version}${reset}"
echo -e "${yellow} https://github.com/amamel/banano-node-docker${reset}"
echo -e "${green} ================================================================================${reset}\n"
echo "${yellow}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&BG5J?7!~^^^::::::^^^~!7?J5GB&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&BPJ7!^^::::::::::^^^^^^^:::::::::^^!7YPB&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@&GY7~:::::::^^~!!7??JJJYYYYYJJ??7!!~^^^:::::^~7YG&@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@B57^:::::^^!7?Y5PPGGGGGGGGGGGGGBBBBBGGGP5YJ7!~^^::::^75B@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@BY!:::::^~7J5PGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBGG5J7~^^^::^!YB@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@&P!:::::^!?5PGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBGPJ!^^^^:^7P&@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@#J~::::^!J5GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBPY!^^^^:~Y#@@@@@@@@@@@@@@@@
@@@@@@@@@@@@#J^::::~?5GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBPJ~^^^:^J#@@@@@@@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BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB##BY!^^^^~5&@@@@@@@@@@
@@@@@@@@@@@@&Y~^^^^~JPBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB##BGJ~^^^^~Y&@@@@@@@@@@@@
@@@@@@@@@@@@@@&5!^^^^^7YGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB##BGY7^^^^^!5&@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@&G?~^^^^^~7YPGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB###BGPY?~^^^^~?G&@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@#57~^^^^^~!?J5PGBBB################BBBGP5J?!~^^^^^^!?P#@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@#P?~^^^^^^~7YPGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB#5^^^^~B@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@&B5?!^^^^^^^^~~!7??JYYYY55YYYYJ??7!~~^^^^^^^~!?5B&@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&#G5J7!~^^^^^^^^^^^^^^^^^^^^^^^^^^~!7J5G#&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&#GP5J?7!!~~~~~~~~~~!!7?J5PG#&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${reset}"
echo "[i] ${yellow}Checking for / installing Required dependencies for this install script... ${reset}"
verify_tools() {
# Define required tools
local requiredTools=("awk" "cmake" "cmake-format" "curl" "git" "g++" "jq" "make" "p7zip-full" "python-dev-is-python3" "ufw" "wget")
# Check if required tools are installed
local missingTools=()
for tool in "${requiredTools[@]}"; do
if ! command -v "$tool" &>/dev/null; then
missingTools+=("$tool")
fi
done
# Install missing tools if any
if [[ ${#missingTools[@]} -gt 0 ]]; then
echo "[i] ${red}The following tools are required but are not installed: ${missingTools[*]}.${reset}"
echo "[i] ${yellow}Installing missing dependencies...${reset}"
# Update package lists and upgrade existing packages
sudo apt-get update && sudo apt-get upgrade
# Install missing tools
sudo apt-get install -y "${missingTools[@]}"
# Install Python 3 pip
sudo apt install python3-pip
# Install cmake-format using pip
sudo pip install cmake-format
fi
}
verify_tools
echo "[i] ${yellow}Checking for Docker... ${reset}"
verify_docker() {
if ! command -v docker &>/dev/null; then
echo "[i] ${red}Docker not detected. Installing Docker...${reset}"
# Add Docker PGP key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Add Docker remote repository
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
# Update package information
sudo apt-get update
# Install Docker
if [[ $quiet = 'false' ]]; then
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
else
sudo apt-get install -y docker-ce docker-ce-cli containerd.io &>/dev/null
fi
# Check if the installation was successful
if [ $? -ne 0 ]; then
echo "[i] ${red}Failed to install Docker. Please install Docker manually and run the script again.${reset}"
exit 2
fi
else
echo "[i] ${green}$(echo -e '\u2713') Detected Docker.${reset}"
echo ""
fi
}
verify_docker
echo "[i] ${yellow}Checking for Docker Compose... ${reset}"
verify_docker_compose() {
if ! command -v docker-compose &>/dev/null; then
echo "[i] ${red}Docker Compose not detected. Installing Docker Compose...${reset}"
# Install Docker Compose
if [[ $quiet = 'false' ]]; then
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
else
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose &>/dev/null
chmod +x /usr/local/bin/docker-compose
fi
# Check if the installation was successful
if [ $? -ne 0 ]; then
echo "[i] ${red}Failed to install Docker Compose. Please install Docker Compose manually and run the script again.${reset}"
exit 2
fi
else
echo "[i] ${green}$(echo -e '\u2713') Detected Docker Compose.${reset}"
echo ""
fi
}
verify_docker_compose
# Fast Syncing
################################################################################
# Note - These links are community supported; however they may experience
# downtime.
################################################################################
# Define the fast-sync database download links
################################################################################
# LMDB Ledger Link
ledgerDownloadLink_LMDB='https://ledger.banano.trade/download/data.ldb'
# RocksDB Ledger Link
ledgerDownloadLink_RocksDB='https://ledgerfiles.moonano.net/files/latest.tar.gz'
################################################################################
fast_sync_lmdb() {
if [[ $quiet = 'false' ]]; then
printf "[i] ${yellow}Downloading the LMDB database for fast-syncing...${reset}\n"
wget -O data.ldb ${ledgerDownloadLink_LMDB} -q --show-progress
else
wget -O data.ldb ${ledgerDownloadLink_LMDB} -q
fi
printf "[i] ${yellow}Moving the database file...${reset} "
# Copy data.ldb to ./banano-node/BananoData/ and overwrite data.ldb while renaming it
mv -f data.ldb ./banano-node/BananoData/data.ldb 2>/dev/null || :
printf "[${green}✓${reset}] ${green}done.${reset}\n"
# Delete the leftover data.ldb file
rm -f data.ldb
echo ""
}
fast_sync_rocksdb() {
if [[ $quiet = 'false' ]]; then
printf "[i] ${yellow}Downloading the RocksDB database for fast-syncing...${reset}\n"
wget -O latest.tar.gz ${ledgerDownloadLink_RocksDB} -q --show-progress
printf "[i] ${yellow}Extracting and placing the database files...${reset} "
# Create the /rocksdb folder if it doesn't exist
mkdir -p ./banano-node/BananoData/rocksdb
tar -xf latest.tar.gz -C ./banano-node/BananoData/rocksdb --strip-components=1
rm latest.tar.gz
printf "[${green}✓${reset}] ${green}done.${reset}\n"
echo ""
else
wget -O latest.tar.gz ${ledgerDownloadLink_RocksDB} -q
docker-compose stop banano-node &>/dev/null
# Create the /rocksdb folder if it doesn't exist
mkdir -p ./banano-node/BananoData/rocksdb
tar -xf latest.tar.gz -C ./banano-node/BananoData/rocksdb --strip-components=1
rm latest.tar.gz
fi
}
fast_sync() {
# Define the menu options using variables
option1="LMDB"
option2="RocksDB"
option3="Exit"
PS3="[i] ${green}Please select the database you would like to use for fast-syncing: ${reset}"
options=("$option1" "$option2" "$option3")
# Prompt the user to choose the database option
select opt in "${options[@]}"; do
case $opt in
"$option1")
fast_sync_lmdb
break
;;
"$option2")
fast_sync_rocksdb
break
;;
"$option3")
echo "[i] ${red}Installer stopped by user. Fast-syncing aborted.${reset}"
echo ""
exit 1
;;
*) echo "[i] ${red}Invalid option. Please select a valid number.${reset}" ;;
esac
done
}
optional_fastSync() {
if [[ $fastSync = 'true' ]]; then
fast_sync
else
echo "[i] ${yellow}Skipping fast-sync. Quick-syncing is not enabled.${reset}"
echo ""
fi
}
optional_fastSync
# Determine if this is an initial install
if [[ $quiet = 'false' ]]; then
echo "[i] ${yellow}Checking initial status...${reset}"
echo ""
fi
# Check if node mounted directory exists
if [ -d "./banano-node" ]; then
# Check if mounted directory follows the new /root structure
if [ ! -d "./banano-node/BananoData" ]; then
if [ ! -d "./banano-node/Banano" ]; then
[[ $quiet = 'false' ]] && printf "[i] ${reset}Unsupported directory structure detected. Migrating files... "
# Check if Banano directory already exists
if [ ! -d "./banano-node/BananoData" ]; then
mkdir ./banano-node/BananoData
fi
# Move files only if the Banano directory is empty
if [ -z "$(ls -A ./banano-node/BananoData)" ]; then
# Move everything into subdirectory and suppress the error about itself
mv ./banano-node/* ./banano-node/BananoData/ &>/dev/null
[[ $quiet = 'false' ]] && printf "[${green}✓${reset}] ${green}done.\n${reset}"
[[ $quiet = 'false' ]] && echo "done"
[[ $quiet = 'false' ]] && echo ""
else
[[ $quiet = 'false' ]] && printf "[i] ${reset}The Banano directory is not empty. Skipping file migration.\n${reset}"
[[ $quiet = 'false' ]] && echo "done"
[[ $quiet = 'false' ]] && echo ""
fi
fi
fi
fi
# Spin up the appropriate stack
if [ "$quiet" = 'false' ]; then
echo "[i] ${yellow}Pulling images and spinning up containers...${reset}"
echo ""
fi
docker network create banano-node-network &>/dev/null
if [ -n "$domain" ]; then
if [ -n "$tag" ]; then
echo "[i] ${yellow}Selected tag:${reset} ${green}$tag${reset}"
echo ""
sed -i "s/image: bananocoin\/banano:.*/image: bananocoin\/banano:$tag/g" docker-compose.letsencrypt.yml
fi
sed -i "s/ - VIRTUAL_HOST=.*/ - VIRTUAL_HOST=$domain/g" docker-compose.letsencrypt.yml
sed -i "s/ - LETSENCRYPT_HOST=.*/ - LETSENCRYPT_HOST=$domain/g" docker-compose.letsencrypt.yml
sed -i "s/ - DEFAULT_HOST=.*/ - DEFAULT_HOST=$domain/g" docker-compose.letsencrypt.yml
if [ -n "$email" ]; then
sed -i "s/ - LETSENCRYPT_EMAIL=.*/ - LETSENCRYPT_EMAIL=$email/g" docker-compose.letsencrypt.yml
fi
if [ "$quiet" = 'false' ]; then
docker-compose -f docker-compose.letsencrypt.yml up -d
else
docker-compose -f docker-compose.letsencrypt.yml up -d &>/dev/null
fi
else
if [ -n "$tag" ]; then
echo "[i] ${yellow}Selected Dockerhub tag:${reset} ${green}$tag${reset}"
echo ""
sed -i "s/image: bananocoin\/banano:.*/image: bananocoin\/banano:$tag/g" docker-compose.yml
fi
if [ "$quiet" = 'false' ]; then
docker-compose up -d
else
docker-compose up -d &>/dev/null
fi
fi
if [ $? -ne 0 ]; then
echo "[i] ${red}Errors were encountered while spinning up the containers. Scroll up for more info on how to fix them.${reset}"
exit 2
fi
# Check Node Initialization
[[ $quiet = 'false' ]] && echo ""
[[ $quiet = 'false' ]] && printf "[i] ${yellow}Waiting for Banano node to fully initialize... "
isRpcLive="$(curl -s -d '{"action": "version"}' 127.0.0.1:7072 | grep "rpc_version")"
while [ ! -n "$isRpcLive" ]; do
sleep 1s
isRpcLive="$(curl -s -d '{"action": "version"}' 127.0.0.1:7072 | grep "rpc_version")"
done
[[ $quiet = 'false' ]] && printf "[${green}✓${reset}] ${green}done.${reset}\n\n"
# Determine Node Version
nodeExec="docker exec -it banano-node /usr/bin/bananode"
# Set Aliases for Banano Node CLI
# Function to append alias to shell configuration file if not already present
append_alias() {
local alias=$1
local file=$2
if [ ! -f "$file" ]; then
touch "$file"
fi
if ! grep -q "alias $alias" "$file"; then
echo "alias $alias" >>"$file"
fi
}
# Function to check if an alias exists in a file
alias_exists() {
local alias_name="$1"
local file_path="$2"
grep -qF "alias $alias_name" "$file_path"
}
# Banano Alias List
aliases=(
# Banano Node CLI
"benis='${nodeExec}'" # Shorthand access to Banano Node CLI
"banano-node='${nodeExec}'" # Alias for Banano Node CLI: Banano Node
"banano-rpc='banano-node --rpc'" # Alias for Banano Node CLI: Banano RPC
"banano-wallet='banano-node --wallet'" # Alias for Banano Node CLI: Banano Wallet
"banano-status='banano-node --status'" # Alias for Banano Node CLI: Banano Node Status
"banano-restart='banano-node --stop && banano-node --daemon'" # Alias for Banano Node CLI: Restart Banano Node
"banano-update='banano-node --update'" # Alias for Banano Node CLI: Update Banano Node
"banano-logs='tail -f /var/log/banano/banano_node.log'" # Alias for Banano Node CLI: View Banano Node Logs
# Banano Wallet and RPC Commands
"banano-account-create='banano-wallet --rpc --command account_create'" # Alias for Banano Wallet: Create a Banano account
"banano-account-list='banano-wallet --rpc --command account_list'" # Alias for Banano Wallet: List Banano accounts
"banano-account-remove='banano-wallet --rpc --command account_remove'" # Alias for Banano Wallet: Remove a Banano account
"banano-account-rename='banano-wallet --rpc --command account_rename'" # Alias for Banano Wallet: Rename a Banano account
"banano-account-history='banano-wallet --rpc --command account_history'" # Alias for Banano Wallet: Get account history
"banano-account-info='banano-wallet --rpc --command account_info'" # Alias for Banano Wallet: Get account information
"banano-account-move='banano-wallet --rpc --command account_move'" # Alias for Banano Wallet: Move an account
"banano-account-key='banano-wallet --rpc --command account_key'" # Alias for Banano Wallet: Get the account's public key
"banano-account-get='banano-wallet --rpc --command account_get'" # Alias for Banano Wallet: Get the account for a given public key
"banano-account-forks='banano-wallet --rpc --command account_forks'" # Alias for Banano Wallet: Get account forks
"banano-account-balance-total='banano-wallet --rpc --command account_balance_total'" # Alias for Banano Wallet: Get the total account balance
"banano-account-representative='banano-wallet --rpc --command account_representative'" # Alias for Banano Wallet: Get the account representative
"banano-account-weight='banano-wallet --rpc --command account_weight'" # Alias for Banano Wallet: Get the account weight
"banano-account-weights='banano-wallet --rpc --command account_weights'" # Alias for Banano Wallet: Get the account weights
"banano-account-confirmations='banano-wallet --rpc --command account_confirmations'" # Alias for Banano Wallet: Get the account confirmations
"banano-account-create-work='banano-wallet --rpc --command account_create_work'" # Alias for Banano Wallet: Create work for an account
"banano-balance='banano-wallet info --balance'" # Alias for Banano Wallet: Get the wallet balance
"banano-accounts='banano-wallet accounts'" # Alias for Banano Wallet: List wallet accounts
"banano-send='banano-wallet send'" # Alias for Banano Wallet: Send Banano from the wallet
"banano-import='banano-wallet import'" # Alias for Banano Wallet: Import a Banano wallet
"banano-export='banano-wallet export'" # Alias for Banano Wallet: Export a Banano wallet
"banano-history='banano-wallet history'" # Alias for Banano Wallet: Get wallet transaction history
"banano-receive='banano-wallet receive'" # Alias for Banano Wallet: Receive Banano in the wallet
"banano-representatives='banano-wallet representatives'" # Alias for Banano Wallet: List wallet representatives
"banano-delegators='banano-wallet delegators'" # Alias for Banano Wallet: List wallet delegators
"banano-account-info='banano-wallet account_info'" # Alias for Banano Wallet: Get account information from the wallet
"banano-block-info='banano-wallet block_info'" # Alias for Banano Wallet: Get block information from the wallet
"banano-block-count='banano-wallet block_count'" # Alias for Banano Wallet: Get the block count from the wallet
"banano-work-generate='banano-wallet work_generate'" # Alias for Banano Wallet: Generate work using the wallet
)
# Add aliases to the shell configuration file if they don't already exist
for alias in "${aliases[@]}"; do
alias_name=$(echo "$alias" | cut -d= -f1)
config_files=("$HOME/.bash_aliases" "$HOME/.zshrc")
alias_exists=false
for file_path in "${config_files[@]}"; do
if alias_exists "$alias_name" "$file_path"; then
alias_exists=true
break
fi
done
if ! $alias_exists; then
append_alias "$alias" "$HOME/.bash_aliases"
append_alias "$alias" "$HOME/.zshrc"
fi
done
# Create .bash_aliases if it doesn't exist
if [ ! -f "$HOME/.bash_aliases" ]; then
touch "$HOME/.bash_aliases"
fi
# Create .zshrc if it doesn't exist
if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi
# Reload the shell
echo -n "[i] ${yellow}Appending Banano node aliases to shell...${reset}"
source "$HOME/.bash_aliases"
source "$HOME/.zshrc"
# Print "done" message
[[ $quiet = 'false' ]] && printf " [${green}✓${reset}] ${green}done.\n${reset}"
# Wallet Setup
existingWallet="$(${nodeExec} --wallet_list | grep 'Wallet ID' | awk '{ print $NF}')"
if [[ ! $existingWallet ]]; then
[[ $quiet = 'false' ]] && printf "[i] ${yellow}No wallet detected. Generating a new one... ${reset}"
walletId=$(${nodeExec} --wallet_create | tr -d '\r')
address="$(${nodeExec} --account_create --wallet=$walletId | awk '{ print $NF}')"
[[ $quiet = 'false' ]] && printf "[${green}✓${reset}] ${green}done.${reset}\n\n"
else
[[ $quiet = 'false' ]] && echo "[i] ${yellow}Existing wallet detected.${reset}"
[[ $quiet = 'false' ]] && echo ''
address="$(${nodeExec} --wallet_list | grep 'ban_' | awk '{ print $NF}' | tr -d '\r')"
walletId=$(echo $existingWallet | tr -d '\r')
fi
if [[ $quiet = 'false' && $displaySeed = 'true' ]]; then
seed=$(${nodeExec} --wallet_decrypt_unsafe --wallet=$walletId | grep 'Seed' | awk '{ print $NF}' | tr -d '\r')
fi
# Update Node Monitor configuration
if [ ! -f ./banano-node-monitor/config.php ]; then
[[ $quiet = 'false' ]] && echo "[i] ${yellow}No existing Banano Node Monitor config file detected. Fetching a fresh copy...${reset}"
if [[ $quiet = 'false' ]]; then
docker-compose restart banano-node-monitor
else
docker-compose restart banano-node-monitor >/dev/null
fi
fi
[[ $quiet = 'false' ]] && printf "[i] ${yellow}Configuring Banano Node Monitor... ${reset}"
##############################################
# Banano Node Monitor Configuration Settings #
##############################################
if [ -f ./banano-node-monitor/config.sample.php ]; then
# Create the config.php file if it doesn't exist
cp -n ./banano-node-monitor/config.sample.php ./banano-node-monitor/config.php
fi
# Perform the necessary sed commands
sed -i -e "s/\/\/ \$blockExplorer.*;/\$blockExplorer = 'bananocreeper';/g" ./banano-node-monitor/config.php
sed -i -e "s/\/\/ \$currency.*;/\$currency = 'banano';/g" ./banano-node-monitor/config.php
sed -i -e "s/\/\/ \$nanoNodeAccount.*;/\$nanoNodeAccount/g" ./banano-node-monitor/config.php
sed -i -e "s/\$nanoNodeAccount.*/\$nanoNodeAccount = '$address';/g" ./banano-node-monitor/config.php
sed -i -e "s/\/\/ \$nanoNodeRPCIP.*;/\$nanoNodeRPCIP/g" ./banano-node-monitor/config.php
sed -i -e "s/\$nanoNodeRPCIP.*/\$nanoNodeRPCIP = 'banano-node';/g" ./banano-node-monitor/config.php
sed -i -e "s/\/\/ \$nanoNodeRPCPort.*;/\$nanoNodeRPCPort = '7072';/g" ./banano-node-monitor/config.php
sed -i -e "s/\/\/ \$nodeLocation.*;/\$nodeLocation = 'Jungle';/g" ./banano-node-monitor/config.php
sed -i -e "s/\/\/ \$themeChoice.*;/\$themeChoice = 'banano-dark';/g" ./banano-node-monitor/config.php
sed -i -e "s/\/\/ \$welcomeMsg.*;/\$welcomeMsg = 'Welcome! This node was set up using <a href=\"https:\/\/github.com\/amamel\/banano-node-docker\" target=\"_blank\">Banano Node Docker<\/a>!';/g" ./banano-node-monitor/config.php
sed -i -e "s/\/\/ \$widgetType.*;/\$widgetType = 'monkey';/g" ./banano-node-monitor/config.php
if [[ $domain ]]; then
sed -i -e "s/\/\/ \$nanoNodeName.*;/\$nanoNodeName = '$domain';/g" ./banano-node-monitor/config.php
else
ipAddress=$(hostname -I | awk '{print $1}')
if [[ -z $ipAddress ]]; then
ipAddress=$(ip addr show | awk '/inet6/{print $2}' | awk -F'/' '{print $1}')
fi
sed -i -e "s/\/\/ \$nanoNodeName.*;/\$nanoNodeName = '$ipAddress';/g" ./banano-node-monitor/config.php
fi
# Remove any carriage returns that may have been included by sed replacements
sed -i -e 's/\r//g' ./banano-node-monitor/config.php
[[ $quiet = 'false' ]] && echo "[${green}✓${reset}] ${green}done.${reset}"
if [[ $quiet = 'false' ]]; then
echo "${yellow} |================================================================================${reset}"
echo "${yellow} | ${green}${bold}Congratulations! Banano Node Docker has been setup successfully!${reset}"
echo "${yellow} |================================================================================${reset}"
echo "${yellow} | ${bold}Node address:${reset} ${green}$address ${reset}"
echo "${yellow} | ${bold}Wallet ID:${reset} ${green}${walletId} ${reset}"
echo "${yellow} | ${bold}Please ensure you save the wallet ID and seed. ${reset}"
echo "${yellow} | ${bold}To start managing the wallet, use the following command: ${reset}"
echo "${yellow} | ${green}benis --banano-wallet ${reset}"
echo "${yellow} |================================================================================${reset}"
if [[ $displaySeed = 'true' ]]; then
echo "${yellow} | ${bold}SEED:${reset} ${red}${seed} ${reset}"
echo "${yellow} | ${bold}IMPORTANT:${reset} ${red}Never share your seed. Keep it safe. ${reset}"
echo "${yellow} |============================================================================${reset}"
fi
if [[ $domain ]]; then
echo "${yellow} Open a browser and navigate to ${green}https://$domain${yellow} to check your monitor."
echo ""
else
echo "${yellow} Open a browser and navigate to ${green}http://$ipAddress${yellow} to check your monitor."
echo ""
fi
echo "${yellow} Configure the node monitor by editing the config file: ${reset}"
echo "${green} ./banano-node-monitor/config.php${reset}"
echo "${yellow} =================================================================================${reset}"
echo "${green} || A lot of care and effort has gone into refactoring Banano Node Docker, ||${reset}"
echo "${green} || to make the script easily configurable and accessible for all. ||${reset}"
echo "${green} || Your support is invaluable in sustaining this project. ||${reset}"
echo "${green} || Thank you for being a part of it! ||${reset}"
echo "${yellow} =================================================================================${reset}"
echo -e " \U0001F34C"
echo "${yellow}${bold} Support This Project: ${reset}"
echo "${green} ban_114i44aggu9a31gymt4pj1ztuk5prn76ejej1baw9ixr9j5z4djngmn4k6tm ${reset}"
echo "${yellow} =================================================================================${reset}"
echo ""
fi
end() {
#echo "Current Banano version is V25.1"
#echo "Current banano.sh version is V1.0"
#echo "Current Banano Node Monitor version is"
echo -e "\n${green}${bold}Banano Node Docker finished successfully. Press any key to close.${reset}"
read -n 1 -s -r -p "" # Wait for user input of any key
}
# ================================================================================
# Check if the script finished successfully and call the function
# ================================================================================
if [ $? -eq 0 ]; then
echo -e "\n\n\n"
end # Call the function to display message and wait for keypress
fi