-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.sh
executable file
·162 lines (150 loc) · 4.01 KB
/
config.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
#!/bin/bash
read -p 'Ring name: ' ring
name=$(echo "$ring" | sed 's/["\n]//g')
ring=$(echo "$ring" | sed 's/[^a-zA-Z0-9]//g')
echo "$ring"
config_file="rings/$ring.json"
if [ -f "$config_file" ]; then
read -p "$config_file already exists, overwrite [Y/N]? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
return
fi
fi
read -p 'Username: ' user
read -s -p 'Password: ' password
read -p 'Server url: ' url
PS3='Lightning Implementation (type the corresponding number):'
options=("LND" "c-lightning" "umbrel")
select opt in "${options[@]}"
do
case $opt in
"LND")
implementation="lnd"
break
;;
"c-lightning")
implementation="c-lightning"
break
;;
"umbrel")
implementation="umbrel"
cli="docker exec lnd lncli"
break
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
done
if [[ "$implementation" == 'lnd' ]]; then
PS3='cli or REST API? (type the corresponding number):'
options=("cli" "REST")
select opt in "${options[@]}"
do
case $opt in
"cli")
method="cli"
PS3='lncli, btcpayserver or shell script? (type the corresponding number):'
options=("lncli" "btcpayserver (docker)" "specify path to script")
select opt in "${options[@]}"
do
case $opt in
"lncli")
cli="lncli"
break
;;
"btcpayserver (docker)")
cli="docker exec btcpayserver_lnd_bitcoin lncli --macaroonpath /root/.lnd/admin.macaroon"
break
;;
"specify path to script")
read -p 'Path to script: ' cli
if [[ "$cli" == *".sh"* ]]; then
cli=". $cli"
fi
break
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
done
break
;;
"REST")
method="rest"
break
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
done
elif [[ "$implementation" == 'c-lightning' ]]; then
PS3='c-lightning btcpayserver or shell script? (type the corresponding number):'
options=("c-lightning" "btcpayserver (docker)" "specify path to script")
select opt in "${options[@]}"
do
case $opt in
"c-lightning")
cli="c-lightning"
break
;;
"btcpayserver (docker)")
cli="docker exec btcpayserver_clightning_bitcoin lightning-cli --rpc-file /root/.lightning/lightning-rpc"
break
;;
"specify path to script")
read -p 'Path to script: ' cli
if [[ "$cli" == *".sh"* ]]; then
cli=". $cli"
fi
break
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
done
fi
if [[ "$method" == 'rest' ]]
then
read -p 'rest url (default: https://127.0.0.1:8080): ' rest_url
if [ -n "$rest_url" ]; then
rest_url="https://127.0.0.1:8080"
fi
read -p 'path to macaroon (default: ./readonly.macaroon): ' macaroon
if [ -n "$rest_url" ]; then
rest_url="./readonly.macaroon"
fi
read -p 'path to tls.cert (default ./tls.cert): ' tlscert
if [ -n "$tlscert" ]; then
tlscert="./tls.cert"
fi
fi
peers=()
peer=true
while [ -n "$peer" ]; do
read -p 'Public key of peer you have a channel with (leave empty when done): ' peer
if [ -n "$peer" ]; then
peers+=( "\"$peer\"" )
fi
done
config=$(echo "${peers[@]}" | jq -s \
--arg name "$name" \
--arg user "$user" \
--arg password "$password" \
--arg url "$url" \
--arg implementation "$implementation" \
--arg cli "$cli" \
--arg method "$method" \
--arg rest_url "$rest_url" \
--arg macaroon "$macaroon" \
--arg tlscert "$tlscert" \
'{ name: $name, peers: ., auth: { user: $user, password: $password }, url: $url, implementation: $implementation, cli: $cli, method: $method, rest_url: $rest_url, macaroon: $macaroon, tlscert: $tlscert }' )
echo "$config" | tee "$config_file" >/dev/null