-
Notifications
You must be signed in to change notification settings - Fork 5
/
awning.sh
executable file
·887 lines (838 loc) · 29.1 KB
/
awning.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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
#!/bin/bash
RED='\033[0;31m'
ORANGE='\033[38;5;214m'
LIGHT_BLUE='\033[1;34m'
UNDERLINE='\033[4m'
GREEN='\033[0;32m'
MAGENTA="\e[36m"
NC='\033[0m' # No Color
BOLD='\e[1m'
NB='\e[0m'
# Function to get the latest versions of software excluding 'rc' tags from GitHub
get_latest_versions() {
local repo=$1
curl -s "https://api.github.com/repos/${repo}/tags" | grep -oP '"name": "\K(.*?)(?=")' | grep -v 'rc' | sed 's/\(beta\).*/\1/' | head -n 5
}
# Function to detect architecture
detect_architecture() {
local arch=$(uname -m)
if [[ "$arch" == "x86_64" ]]; then
echo "x86_64 amd64"
elif [[ "$arch" == "aarch64" ]]; then
echo "aarch64 arm64"
else
echo "Unsupported architecture: $arch" >&2
exit 1
fi
}
MYUID=$(id -u)
MYGID=$(id -g)
ARCH_INFO=($(detect_architecture))
BITCOIN_ARCH=${ARCH_INFO[0]}
LND_ARCH=${ARCH_INFO[1]}
# Print header
print_header() {
echo "-----------"
echo -e "${BOLD}${ORANGE}$1) $2${NC}${NB} "
# echo -e "${BOLD}$2${NB}"
echo "-----------"
# sleep 1
}
# Function to check if Bitcoin blockchain is downloaded
is_bitcoin_blockchain_downloaded() {
local blocks_folder="./data/bitcoin/blocks"
if [ -d "$blocks_folder" ] && [ "$(ls -A $blocks_folder)" ]; then
return 0
else
return 1
fi
}
# Function to check if LND is initialized
is_lnd_initialized() {
channel_backup_file="./data/lnd/data/chain/bitcoin/mainnet/channel.backup"
if [ -f "$channel_backup_file" ]; then
return 0
else
return 1
fi
}
# Function to generate a random password
generate_password() {
tr -dc A-Za-z0-9 </dev/urandom | head -c 16 ; echo ''
}
# Function to check if input is a valid SSH GitHub repository URL
is_ssh_github_repo() {
local input="$1"
local regex='^git@github\.com:[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+\.git$'
if [[ $input =~ $regex ]]; then
return 0
else
return 1
fi
}
is_disk_space_available() {
script_dir="$(dirname "$(readlink -f "$0")")"
partition=$(df -P "$script_dir" | tail -1 | awk '{print $6}')
free_space_kb=$(df -P "$partition" | tail -1 | awk '{print $4}')
data_dir="$script_dir/data"
data_size_kb=$(du -sk "$data_dir" | awk '{print $1}')
required_free_space_kb=$((900000000 - data_size_kb))
if (( free_space_kb >= required_free_space_kb )); then
return 0
else
return 1
fi
}
show_welcome() {
echo -e ""
echo -e "Welcome to the ${ORANGE}${BOLD}Awning${NB}${NC} setup tutorial!"
echo -e "This script will guide you through setting up a full dockerized Bitcoin/LND/BTCPay server on your PC."
echo -e ""
echo -e "${BOLD}************ DISCLAIMER ****************${NB}"
echo -e "${BOLD}This open-source project ('the Project') is provided 'as-is' without any warranty of any kind, either expressed or implied. The developers are not liable for any damages or losses arising out of the use of this software.${NB}"
echo -e "${BOLD}Please read the full disclaimer before using the Project here: ${UNDERLINE}https://github.com/giovantenne/awning/blob/master/DISCLAIMER.md${NC}${NB}"
echo -e "${BOLD}By using the Project, you acknowledge that you have read, understood, and agree to be bound by this disclaimer. If you do not agree to this disclaimer, you should not use the Project.${NB}"
echo -e "${BOLD}****************************************${NB}"
echo -e ""
if ! is_disk_space_available; then
echo -e "${RED}The disk where you are running Awning doesn't have enough free space and can not contain the Bitcoin blockchain.${NC}"
echo -e "${RED}Please exit this setup with CTRL+C use a different disk.${NC}"
echo -e "----------------"
fi
if ! is_bitcoin_blockchain_downloaded; then
echo -e "It seems that you need to download the entire ${ORANGE}Bitcoin${NC} blockchain. This will take some time..."
echo -e "If you already have the blockchain downloaded somewhere, please move it to ${UNDERLINE}./data/bitcoin/${NC} now."
echo -e "----------------"
fi
if ! is_lnd_initialized; then
touch ./data/lnd/password.txt
echo -e "It seems that you need to initialize your ${LIGHT_BLUE}LND${NC} wallet."
echo -e "If you already have your LND data somewhere, please move it to ${UNDERLINE}./data/lnd/${NC} now."
echo -e "----------------"
fi
echo -e ""
echo "Press any key to continue..."
read -n 1 -s -r
}
choose_alias() {
print_header $1 "LND node alias"
echo -e "Choose the alias your LND node will use, which can be up to 32 UTF-8 characters in length."
echo -e ""
echo -n "Insert alias (default is 'AwningNode'): "
read NODE_ALIAS
NODE_ALIAS=${NODE_ALIAS:-AwningNode}
}
insert_scb_repo() {
print_header $1 "LND channel backups"
echo -e "The Static Channels Backup (SCB) is a feature of ${LIGHT_BLUE}LND${NC} that allows for the on-chain recovery of lightning channel balances in the case of a bricked node. Despite its name, it does not allow the recovery of your LN channels but increases the chance that you'll recover all (or most) of your off-chain (local) balances."
echo -e ""
echo -e "${BOLD}Awning${NB} will automatically upload a copy of your ${UNDERLINE}channel.backup${NC} every time it changes on a Github repository you own, so you will need to create one and provide upload credential later."
echo -e ""
echo -e "${BOLD}Create a GitHub repository${NB}"
echo -e " - Go to GitHub (${UNDERLINE}https://github.com${NC}), sign up for a new user account, or log in with an existing one."
echo -e " - Create a new repository: ${UNDERLINE}https://github.com/new${NC}"
echo -e " - Choose a repository name (eg. ${BOLD}remote-lnd-backup${NB})"
echo -e " - Select 'Private' (rather than the default 'Public')"
echo -e " - Click on 'Create repository'"
echo -e " - Annotate your SSH repository address."
echo -e " It should be something like ${UNDERLINE}[email protected]:giovantenne/remote-lnd-backup.git${NC}"
echo -e ""
if [ -f .env ]; then
current_repo=$(grep -E '^\s*SCB_REPO\s*=' .env | sed -e 's/^\s*SCB_REPO\s*=\s*//' -e 's/\s*$//')
else
current_repo=""
fi
while true; do
if [ -z "$current_repo" ]; then
echo -en "Enter your SSH repository address: "
else
echo -e "Current value: ${UNDERLINE}$current_repo${NC}"
echo -en "Enter your SSH repository address (press ENTER to keep current): "
fi
read SCB_REPO
if [ -z "$SCB_REPO" ]; then
SCB_REPO=$current_repo
fi
if is_ssh_github_repo "$SCB_REPO"; then
break
else
echo -e "${RED}${BOLD}Invalid address${NB}${NC}"
fi
done
}
upload_scb_repo_deploy_key() {
print_header $1 "Authorize SCB to be uploaded on Github"
if [ ! -f ./data/scb/.ssh/id_rsa.pub ]; then
echo -e "Generating the SSH key. This could take a few minutes. Please wait..."
mkdir -p ./data/scb/.ssh
# Generating ssh key
$docker_command run --rm -e MYUID=$MYUID -e MYGID=$MYGID -v "$PWD/data/scb/.ssh:/keys" debian:bookworm-slim sh -c "
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends openssh-client && \
ssh-keygen -t rsa -b 2048 -f /keys/id_rsa -N '' && \
chown $MYUID:$MYGID /keys/*" >/dev/null 2>&1
# adding github public key fingerprints
else
echo -e "SSH key already present in ${UNDERLINE}./data/scb/.ssh/${NC}"
fi
if [ ! -f ./data/scb/.ssh/known_hosts ]; then
echo "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=" >> ./data/scb/.ssh/known_hosts
fi
echo -e "************************${GREEN}"
cat ./data/scb/.ssh/id_rsa.pub
echo -e "${NC}************************"
# Extract the username and repository name using parameter expansion
# The SSH URL is expected to be in the format: [email protected]:username/repository.git
local username=$(echo $SCB_REPO | cut -d':' -f2 | cut -d'/' -f1)
local repository=$(echo $SCB_REPO | cut -d'/' -f2 | sed 's/\.git$//')
echo -e ""
echo -e "- Go to the following address: ${UNDERLINE}https://github.com/$username/$repository/settings/keys/new${NC}"
echo -e "- Type a title (e.g., 'SCB')"
echo -e "- In the 'Key' box, copy/paste the SSH key generated above (e.g. ${UNDERLINE}ssh-rsa 56fgh... scb@5cf1058457${NC})"
echo -e "- Tick the box 'Allow write access' to enable this key to push changes to the repository"
echo -e "- Click 'Add key'"
echo -e ""
echo -e "Press ENTER to test your setup"
read -n 1 -s -r
rm -rf ./data/scb/test
cd ./data/scb
while true; do
echo -e "Performing test. Please wait..."
# Test read
if ! git config --global user.email &>/dev/null; then
git config --global user.email "[email protected]"
fi
if ! git config --global user.name &>/dev/null; then
git config --global user.name "Awning"
fi
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=.ssh/known_hosts -o IdentitiesOnly=yes -i .ssh/id_rsa" git clone $SCB_REPO test
if [ $? -ne 0 ]; then
echo -e "${RED}${BOLD}Read rest failed!${NB}${NC}"
echo -e "You do not have permission to read to ${UNDERLINE}$SCB_REPO${NC}"
echo -e "Please follow the above steps again and press ENTER to try again or CRTL-C to exit the setup."
read -n 1 -s -r
else
cd test
touch test >/dev/null 2>&1
git add test >/dev/null 2>&1
git commit -am "Test" >/dev/null 2>&1
git branch -M main
# Test write
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=../.ssh/known_hosts -o IdentitiesOnly=yes -i ../.ssh/id_rsa" git push $SCB_REPO main #>/dev/null 2>&1
if [ $? -ne 0 ]; then
cd ..
rm -rf test
echo -e "${RED}${BOLD}Write test failed!${NB}${NC}"
echo -e "You do not have permission to write to ${UNDERLINE}$SCB_REPO${NC}"
echo -e "Please follow the above steps again and press ENTER to try again or CRTL-C to exit the setup."
read -n 1 -s -r
else
# Cleanup
rm test
git commit -am "Test successful" >/dev/null 2>&1
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=../.ssh/known_hosts -o IdentitiesOnly=yes -i ../.ssh/id_rsa" git push $SCB_REPO main #>/dev/null 2>&1
cd ../../../
rm -rf ./data/scb/test
echo -e ""
echo -e "${GREEN}${BOLD}Test performed successfully${NB}${NC}"
echo "Press any key to continue..."
read -n 1 -s -r
break
fi
fi
done
}
choose_rtl_password() {
print_header $1 "${BOLD}'Ride The Lightning' password${NB}"
read -s -p "Please choose your password for the RTL web interface: " RTL_PASSWORD
echo -e ""
}
enable_btcpay() {
print_header $1 "${BOLD}BTCPay server${NB}"
while true; do
echo -n "Do you want to run BTCPay-server? (yes/no, default is no): "
read RUN_BTCPAY
RUN_BTCPAY=${RUN_BTCPAY:-no}
if [[ "$RUN_BTCPAY" =~ ^(yes|no)$ ]]; then
break
else
echo "Invalid choice. Please enter 'yes' or 'no'."
fi
done
}
function check_lnd(){
while [ "$($docker_command inspect -f '{{.State.Running}}' awning_lnd 2>/dev/null)" != "true" ]; do
echo -e "Waiting for LND container to start..."
sleep 10
echo "Timed out waiting for the container to start."
done
if is_lnd_initialized; then
if [ ! -s "./data/lnd/password.txt" ]; then
print_header $1 "${BOLD}Insert your LND wallet password${NB}"
echo -e "Please insert your password for automatically unlock your LND wallet. If you come from Umbrel please insert 'moneyprintergobrrr'"
read -s -p "Please insert your password: " LND_PASSWORD
echo -e ""
echo $LND_PASSWORD > ./data/lnd/password.txt
$compose_command restart lnd
fi
else
# Wait for the container to be running
local timeout=60
local wait_interval=2
elapsed=0
print_header $1 "${BOLD}Create your LND wallet password${NB}"
echo -e "Please choose your password for automatically unlock your LND wallet."
echo -e "You will need to re-enter the password 3 times on the next step."
echo -e ""
while true; do
read -s -p "Enter your wallet password (first time of three): " password
echo -e ""
if [ ! ${#password} -ge 8 ]; then
echo "password must have at least 8 characters"
echo -e ""
else
break
fi
done
echo $password > ./data/lnd/password.txt
$docker_command exec -it awning_lnd lncli create
echo -e ""
fi
}
function create_env_file() {
BITCOIN_VERSIONS=($(get_latest_versions "bitcoin/bitcoin"))
LND_VERSIONS=($(get_latest_versions "lightningnetwork/lnd"))
ELECTRS_VERSIONS=($(get_latest_versions "romanz/electrs"))
cat <<EOT > .env
UID=${MYUID}
GID=${MYGID}
NODE_ALIAS=${NODE_ALIAS}
BITCOIN_ARCH=${BITCOIN_ARCH}
LND_ARCH=${LND_ARCH}
RTL_PASSWORD=${RTL_PASSWORD}
SCB_REPO=${SCB_REPO}
BITCOIN_CORE_VERSION=$(echo ${BITCOIN_VERSIONS[0]} | sed 's/^v//')
LND_VERSION=$(echo ${LND_VERSIONS[0]} | sed 's/^v//')
ELECTRS_VERSION=$(echo ${ELECTRS_VERSIONS[0]} | sed 's/^v//')
EOT
}
function create_compose() {
cat <<EOT > docker-compose.yml
version: "3"
services:
EOT
cat ./fragments/tor.yml >> docker-compose.yml
cat ./fragments/bitcoin.yml >> docker-compose.yml
cat ./fragments/electrs.yml >> docker-compose.yml
cat ./fragments/lnd.yml >> docker-compose.yml
cat ./fragments/scb.yml >> docker-compose.yml
cat ./fragments/rtl.yml >> docker-compose.yml
cat ./fragments/nginx.yml >> docker-compose.yml
if [ "$RUN_BTCPAY" = "yes" ]; then
sed -i '/^ nginx:/,/depends_on:/s/^ *depends_on: \[rtl, electrs\]/ depends_on: [rtl, electrs, btcpay]/' docker-compose.yml
sed -i '/nginx:/,/restart: unless-stopped/{s/^ #\s*/ /}' docker-compose.yml
sed -i 's/nginx-reverse-proxy/nginx-reverse-proxy-btcpay/g' docker-compose.yml
cat ./fragments/btcpay.yml >> docker-compose.yml
fi
}
compose_build() {
print_header $1 "You are now ready to build your Docker images"
echo -e "The first time it will take some time to build all the images from scratch (especially compiling the Electrs binary can take up to one hour)."
echo -e ""
echo "Press any key to continue..."
read -n 1 -s -r
$compose_command build
echo -e "${GREEN}${BOLD}Build completed${NB}${NC}"
echo "Press any key to continue..."
read -n 1 -s -r
}
are_services_up() {
$compose_command ps | grep ' Up ' > /dev/null
echo $?
}
# Function to display menu
display_menu() {
while true; do
echo ""
echo "#############################################"
echo -e "# ${BOLD}${ORANGE}Awning${NC}${NB} #"
echo "#############################################"
echo "1) Start/Stop the node"
echo "2) Logs"
echo "3) Node info"
echo "4) Change node parameters"
echo "5) Connections URLs"
echo "6) Utilities"
echo -e "${BOLD}0) Exit${NB}"
echo "#############################################"
echo ""
echo -n "Choose an option: "
read option
case $option in
1)
echo "Loading..."
echo ""
if [ $(are_services_up) -ne 0 ]; then
read -p "Node is not running. Do you want to start the node? (y/n): " answer
if [[ $answer =~ ^[Yy]$ ]]; then
echo "Starting the node..."
$compose_command up -d
fi
else
read -p "Node is running. Do you want to stop the node? (y/n): " answer
if [[ $answer =~ ^[Yy]$ ]]; then
echo "Stopping the node..."
$compose_command down
fi
fi
;;
2)
if [ $(are_services_up) -ne 0 ]; then
echo -e "${RED}Node is not running!${NC}"
else
logs_submenu
fi
;;
3)
echo "Loading..."
if [ $(are_services_up) -ne 0 ]; then
echo -e "${RED}Node is not running!${NC}"
else
show_node_info
fi
;;
4)
node_params_submenu
;;
5)
connections_submenu
;;
6)
utils_submenu
;;
0)
echo "Exiting."
exit 0
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
;;
esac
done
}
show_node_info() {
bitcoin_version=$($docker_command exec awning_bitcoin bitcoin-cli --version | grep "Bitcoin Core RPC client version")
sync_percentage=$($docker_command exec awning_bitcoin /bin/bash -c 'echo "`bitcoin-cli getblockchaininfo | jq -r '.verificationprogress'` * 100" | bc')
blocks=$($docker_command exec awning_bitcoin /bin/bash -c "bitcoin-cli getblockchaininfo | jq -r '.blocks'")
headers=$($docker_command exec awning_bitcoin /bin/bash -c "bitcoin-cli getblockchaininfo | jq -r '.headers'")
initialblockdownload=$($docker_command exec awning_bitcoin /bin/bash -c "bitcoin-cli getblockchaininfo | jq -r '.initialblockdownload'")
lnd_version=$($docker_command exec awning_lnd /bin/bash -c "lncli getinfo | jq -r '.version'")
synced_to_chain=$($docker_command exec awning_lnd /bin/bash -c "lncli getinfo | jq -r '.synced_to_chain'")
synced_to_graph=$($docker_command exec awning_lnd /bin/bash -c "lncli getinfo | jq -r '.synced_to_graph'")
num_pending_channels=$($docker_command exec awning_lnd /bin/bash -c "lncli getinfo | jq -r '.num_pending_channels'")
num_active_channels=$($docker_command exec awning_lnd /bin/bash -c "lncli getinfo | jq -r '.num_active_channels'")
num_inactive_channels=$($docker_command exec awning_lnd /bin/bash -c "lncli getinfo | jq -r '.num_inactive_channels'")
num_peers=$($docker_command exec awning_lnd /bin/bash -c "lncli getinfo | jq -r '.num_peers'")
echo ""
echo -e "${ORANGE}BITCOIN${NC}"
echo -e $bitcoin_version
echo -e "Sync Progress: $sync_percentage%"
echo -e "Blocks: $blocks"
echo -e "Headers: $headers"
echo -e "Initial block download: $initialblockdownload"
echo ""
echo -e "${LIGHT_BLUE}LND${NC}"
echo -e "Version $lnd_version"
echo -e "Synced to Chain: $synced_to_chain"
echo -e "Synced to Graph: $synced_to_graph"
echo -e "Num. active channels: $num_active_channels"
echo -e "Num. pending channels: $num_pending_channels"
echo -e "Num. inactive channels: $num_inactive_channels"
echo -e "Num. peers: $num_peers"
echo ""
echo "Press any key to continue..."
read -n 1 -s -r
}
logs_submenu(){
while true; do
echo "#############################################"
echo -e "# Logs (CRTL+C to exit) #"
echo "#############################################"
echo "1) All the logs"
echo "2) Bitcoin logs"
echo "3) LND logs"
echo "4) Electrs logs"
echo "5) RTL logs"
echo "6) TOR logs"
echo "7) SCB logs"
echo ""
echo -e "${BOLD}0) <- Back to main menu${NB}"
echo "#############################################"
echo ""
echo -n "Choose an option: "
read option
case $option in
1)
$compose_command logs --tail 100 -f
;;
2)
$compose_command logs --tail 100 -f bitcoin
;;
3)
$compose_command logs --tail 100 -f lnd
;;
4)
$compose_command logs --tail 100 -f electrs
;;
5)
$compose_command logs --tail 100 -f rtl
;;
6)
$compose_command logs --tail 100 -f tor
;;
7)
$compose_command logs --tail 100 -f scb
;;
0)
display_menu
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
;;
esac
done
}
node_params_submenu() {
while true; do
echo "#############################################"
echo "# Change params #"
echo "#############################################"
echo "1) Change the RTL password"
echo "2) Change Bitcoin version"
echo "3) Change LND version"
echo ""
echo -e "${BOLD}0) <- Back to main menu${NB}"
echo "#############################################"
echo ""
echo -n "Choose an option: "
read option
case $option in
1)
if (change_rtl_password); then
if [ $(are_services_up) -ne 1 ]; then
$compose_command restart rtl
fi
fi
;;
2)
if (change_version "BITCOIN_CORE_VERSION" "bitcoin/bitcoin"); then
$compose_command build bitcoin
if [ $(are_services_up) -ne 1 ]; then
$compose_command down
$compose_command up -d
fi
fi
;;
3)
if (change_version "LND_VERSION" "lightningnetwork/lnd") ; then
$compose_command build lnd
if [ $(are_services_up) -ne 1 ]; then
$compose_command down
$compose_command up -d
fi
fi
;;
0)
display_menu
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
;;
esac
done
}
connections_submenu() {
while true; do
echo "#############################################"
echo "# Connections #"
echo "#############################################"
echo "1) Display web addresses"
echo "2) Display QR-code for Zeus Wallet"
echo ""
echo -e "${BOLD}0) <- Back to main menu${NB}"
echo "#############################################"
echo ""
echo -n "Choose an option: "
read option
case $option in
1)
local local_ip=$(hostname -I | awk '{print $1}')
echo -e "ELECTRS via TOR: ${GREEN}${UNDERLINE}`cat ./data/tor/hidden_service_electrs/hostname`:50001${NC}${NC}"
echo -e "Electrs (ssl): https://$local_ip:50002"
echo -e "LND Rest API (ssl): https://$local_ip:8080"
echo -e "RTL (ssl): https://$local_ip:8081"
echo -e "RTL (no ssl): http://$local_ip:8082"
if $docker_command ps --filter "name=awning_btcpay" --filter "status=running"|grep awning_btcpay > /dev/null; then
echo -e "BTCPay (ssl): https://$local_ip:8083"
echo -e "BTCPay (no ssl): http://$local_ip:8084"
fi
echo ""
echo "Press any key to continue..."
read -n 1 -s -r
;;
2)
if [ $(are_services_up) -ne 0 ]; then
echo -e "${RED}Node is not running!${NC}"
else
URI=`cat ./data/tor/hidden_service_lnd_rest/hostname` && $docker_command exec awning_lnd lndconnect --host $URI --port 8080
echo ""
echo "Press any key to get a code you can copy paste into the app."
read -n 1 -s -r
echo ""
URI=`cat ./data/tor/hidden_service_lnd_rest/hostname` && $docker_command exec awning_lnd lndconnect -j --host $URI --port 8080
fi
echo ""
echo "Press any key to continue..."
read -n 1 -s -r
;;
0)
display_menu
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
;;
esac
done
}
utils_submenu() {
while true; do
echo "#############################################"
echo "# Utilities #"
echo "#############################################"
echo "1) Enter the Bitcoin container (bitcoin-cli)"
echo "2) Enter the LND container (lncli)"
echo "3) Restart services"
echo "4) Rebuild docker images"
echo "5) Run the SETUP tutorial"
echo "6) Update Awning"
echo ""
echo -e "${BOLD}0) <- Back to main menu${NB}"
echo "#############################################"
echo ""
echo -n "Choose an option: "
read option
case $option in
1)
$docker_command exec -it awning_bitcoin bash
;;
2)
$docker_command exec -it awning_lnd bash
;;
3)
restart_submenu
;;
4)
rebuild_submenu
;;
5)
setup_tutorial
;;
6)
read -p "Do you want to proceed? (y/n): " answer
if [[ $answer =~ ^[Yy]$ ]]; then
git stash
git pull origin master
git stash apply
echo ""
echo "You may need to rebuild and/or restart the Awning services"
echo "Press any key to continue..."
exec ./awning.sh
exit
read -n 1 -s -r
elif [[ $answer =~ ^[Nn]$ ]]; then
display_menu
else
echo "Invalid input."
fi
;;
0)
display_menu
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
;;
esac
done
}
restart_submenu() {
while true; do
echo "#############################################"
echo "# Restart #"
echo "#############################################"
echo "1) Restart the Awning node"
echo "2) Restart Bitcoin"
echo "3) Restart LND"
echo ""
echo -e "${BOLD}0) <- Back to utils menu${NB}"
echo "#############################################"
echo ""
echo -n "Choose an option: "
read option
case $option in
1)
if [ $(are_services_up) -ne 0 ]; then
echo -e "${RED}Node is not running!${NC}"
else
$compose_command down
$compose_command up -d
fi
;;
2)
$compose_command restart bitcoin
;;
3)
$compose_command restart lnd
;;
0)
utils_submenu
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
;;
esac
done
}
rebuild_submenu() {
while true; do
echo "#############################################"
echo "# Rebuild #"
echo "#############################################"
echo "1) Rebuild the node images"
echo "2) Rebuild the node images without cache (can take up to one hour)"
echo ""
echo -e "${BOLD}0) <- Back to utils menu${NB}"
echo "#############################################"
echo ""
echo -n "Choose an option: "
read option
case $option in
1)
$compose_command build
if [ $(are_services_up) -ne 1 ]; then
$compose_command down
$compose_command up -d
fi
;;
2)
$compose_command build --no-cache
if [ $(are_services_up) -ne 1 ]; then
$compose_command down
$compose_command up -d
fi
;;
0)
utils_submenu
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
;;
esac
done
}
# Function to change RTL_PASSWORD
change_rtl_password() {
echo -n "Enter new RTL password (press ENTER to keep current): "
read new_rtl_password
if [ ! -z "$new_rtl_password" ]; then
sed -i "s/^RTL_PASSWORD=.*/RTL_PASSWORD=${new_rtl_password}/" .env
echo -e "${GREEN}RTL password updated.${NC}"
return 0
else
echo -e "${GREEN}RTL password unchanged.${NC}"
return 1
fi
}
# Function to change version
change_version() {
local versions=$2
versions=($(get_latest_versions $2))
echo "Select $version_name:"
for i in "${!versions[@]}"; do
echo "$((i+1))) ${versions[$i]}"
done
echo -n "Choose a version (press ENTER to keep current v`grep '^'$1 .env | cut -d '=' -f 2`): "
read version_index
if [ ! -z "$version_index" ] && [ "$version_index" -le "${#versions[@]}" ]; then
local new_version=$(echo ${versions[$((version_index-1))]} | sed 's/^v//')
sed -i "s/^$1=.*/$1=$new_version/" .env
echo -e "${GREEN}$version_name updated.${NC}"
return 0
else
echo -e "${GREEN}$version_name unchanged.${NC}"
return 1
fi
}
# Function to check if docker-compose is installed
check_docker_compose() {
if command -v docker-compose &> /dev/null; then
if check_root_needed; then
echo "sudo docker-compose"
else
echo "docker-compose"
fi
elif docker compose version &> /dev/null; then
if check_root_needed; then
echo "sudo docker compose"
else
echo "docker compose"
fi
else
echo "None"
fi
}
check_docker() {
if check_root_needed; then
echo "sudo docker"
else
echo "docker"
fi
}
# Function to check if root is needed to run docker-compose
check_root_needed() {
if docker ps &> /dev/null; then
return 1 # Root is not needed
else
return 0 # Root is needed
fi
}
setup_tutorial(){
show_welcome
choose_alias "1/7"
insert_scb_repo "2/7"
upload_scb_repo_deploy_key "3/7"
choose_rtl_password "4/7"
enable_btcpay "5/7"
create_env_file
create_compose
compose_build "6/7"
if [ $(are_services_up) -ne 0 ]; then
$compose_command down
fi
$compose_command up -d
check_lnd "6/7"
display_menu
}
# Check if docker-compose or docker compose is available
compose_command=$(check_docker_compose)
if [ "$compose_command" == "None" ]; then
echo "Neither docker-compose nor docker compose is installed. Please install one of them."
exit 1
fi
docker_command=$(check_docker)
if [ -f "docker-compose.yml" ] && [ -f ".env" ]; then
display_menu
else
setup_tutorial
fi