-
Notifications
You must be signed in to change notification settings - Fork 528
/
Copy pathbonus.lndconnect.sh
executable file
·236 lines (203 loc) · 7.49 KB
/
bonus.lndconnect.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
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# config script to connect mobile apps with lnd connect"
echo "# will autodetect dyndns, sshtunnel or TOR"
echo "# bonus.lndconnect.sh [zap-ios|zap-android|zeus-ios|zeus-android|shango-ios|shango-android|sendmany-android] [?ip|tor]"
exit 1
fi
# make sure commandline tool is available
sudo apt-get install -y qrencode 1>/dev/null 2>/dev/null
# load raspiblitz config data
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
#### PARAMETER
# 1. TARGET WALLET
targetWallet=$1
# 1. TOR or IP (optional - default IP)
forceTOR=0
if [ "$2" == "tor" ]; then
forceTOR=1
fi
#### CHECK IF IP2TOR BRIDGES ARE AVAILABLE
ip2torREST_IP=""
ip2torREST_PORT=""
error=""
source <(/home/admin/config.scripts/blitz.subscriptions.ip2tor.py subscription-by-service LND-REST-API)
if [ ${#error} -eq 0 ]; then
ip2torREST_IP="${ip}"
ip2torREST_PORT="${port}"
fi
ip2torGRPC_IP=""
ip2torGRPC_PORT=""
error=""
source <(/home/admin/config.scripts/blitz.subscriptions.ip2tor.py subscription-by-service LND-GRPC-API)
if [ ${#error} -eq 0 ]; then
ip2torGRPC_IP="${ip}"
ip2torGRPC_PORT="${port}"
fi
#### ADAPT PARAMETERS BASED TARGETWALLET
# defaults
host=""
port=""
addcert=1
supportsTOR=0
usingIP2TOR=""
connectInfo="When you start the App choose to connect to your own node.\n(DIY / Remote-Node / lndconnect)\nClick on the 'Scan QR' button."
if [ "${targetWallet}" = "zap-ios" ]; then
if [ ${forceTOR} -eq 1 ]; then
# when ZAP runs on TOR it uses REST
port="8080"
addcert=0
else
# normal ZAP uses gRPC ports
port="10009"
fi
if [ ${#ip2torGRPC_IP} -gt 0 ]; then
# when IP2TOR bridge is available - force using that
usingIP2TOR="LND-GRPC-API"
forceTOR=0
host="${ip2torGRPC_IP}"
port="${ip2torGRPC_PORT}"
fi
elif [ "${targetWallet}" = "zap-android" ]; then
connectInfo="- start the Zap Wallet --> SETUP WALLET\n or choose new Wallet in app menu\n- scan the QR code \n- confirm host address"
if [ ${forceTOR} -eq 1 ]; then
# when ZAP runs on TOR it uses gRPC
port="10009"
connectInfo="${connectInfo}\n- install & connect Orbot App (VPN mode)"
else
# normal ZAP uses gRPC ports
port="10009"
fi
if [ ${#ip2torGRPC_IP} -gt 0 ]; then
# when IP2TOR bridge is available - force using that
usingIP2TOR="LND-GRPC-API"
forceTOR=1
host="${ip2torGRPC_IP}"
port="${ip2torGRPC_PORT}"
fi
elif [ "${targetWallet}" = "zeus-ios" ]; then
port="8080"
usingIP2TOR="LND-REST-API"
forceTOR=1
host=$(sudo cat /mnt/hdd/tor/lndrest8080/hostname)
connectInfo="- start the Zeus Wallet --> lndconnect\n- scan the QR code \n- activate 'Tor' option \n- activate 'Certification Verification' option\n- save Node Config"
elif [ "${targetWallet}" = "zeus-android" ]; then
port="8080"
usingIP2TOR="LND-REST-API"
forceTOR=1
host=$(sudo cat /mnt/hdd/tor/lndrest8080/hostname)
connectInfo="- start the Zeus Wallet --> lndconnect\n- scan the QR code \n- activate 'Tor' option \n- activate 'Certification Verification' option\n- save Node Config"
elif [ "${targetWallet}" = "sendmany-android" ]; then
connector="lndconnect"
if [ ${forceTOR} -eq 1 ]; then
# echo "error='no tor support'"
# exit 1
# port="8080"
# addcert=0
# deactivate TOR for now, because address is too long QR code is too big to be scanned by
# app and so just make it possible to use local.
forceTOR=0
fi
port="10009"
if [ ${#ip2torGRPC_IP} -gt 0 ]; then
# when IP2TOR bridge is available - force using that
usingIP2TOR="LND-GRPC-API"
forceTOR=0
host="${ip2torGRPC_IP}"
port="${ip2torGRPC_PORT}"
fi
else
echo "error='unknown target wallet'"
exit 1
fi
#### ADAPT PARAMETERS BASED RASPIBLITZ CONFIG
# get the local IP as default host
if [ ${#host} -eq 0 ]; then
host=$(ip addr | grep 'state UP' -A2 | egrep -v 'docker0|veth' | grep 'eth0\|wlan0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
fi
# change host to dynDNS if set
if [ ${#dynDomain} -gt 0 ]; then
host="${dynDomain}"
fi
# tunnel thru TOR if running and supported by the wallet
if [ ${forceTOR} -eq 1 ]; then
# depending on RPC or REST use different TOR address
if [ "${port}" == "10009" ]; then
host=$(sudo cat /mnt/hdd/tor/lndrpc10009/hostname)
port="10009"
echo "# using TOR --> host ${host} port ${port}"
elif [ "${port}" == "8080" ]; then
host=$(sudo cat /mnt/hdd/tor/lndrest8080/hostname)
port="8080"
echo "# using TOR --> host ${host} port ${port}"
fi
fi
# tunnel thru SSH-Reverse-Tunnel if activated for that port
if [ ${#sshtunnel} -gt 0 ]; then
isForwarded=$(echo ${sshtunnel} | grep -c "${port}<")
if [ ${isForwarded} -gt 0 ]; then
if [ "${port}" == "10009" ]; then
host=$(echo $sshtunnel | cut -d '@' -f2 | cut -d ' ' -f1 | cut -d ':' -f1)
port=$(echo $sshtunnel | awk '{split($0,a,"10009<"); print a[2]}' | cut -d ' ' -f1 | sed 's/[^0-9]//g')
echo "# using ssh-tunnel --> host ${host} port ${port}"
elif [ "${port}" == "8080" ]; then
host=$(echo $sshtunnel | cut -d '@' -f2 | cut -d ' ' -f1 | cut -d ':' -f1)
port=$(echo $sshtunnel | awk '{split($0,a,"8080<"); print a[2]}' | cut -d ' ' -f1 | sed 's/[^0-9]//g')
echo "# using ssh-tunnel --> host ${host} port ${port}"
fi
fi
fi
#### RUN LNDCONNECT
# generate data parts
macaroon=$(sudo base64 /mnt/hdd/app-data/lnd/data/chain/${network}/${chain}net/admin.macaroon | tr -d '=' | tr '/+' '_-' | tr -d '\n')
cert=$(sudo grep -v 'CERTIFICATE' /mnt/hdd/lnd/tls.cert | tr -d '=' | tr '/+' '_-' | tr -d '\n')
# generate URI parameters
macaroonParameter="?macaroon=${macaroon}"
certParameter="&cert=${cert}"
# mute cert parameter (optional)
if [ ${addcert} -eq 0 ]; then
certParameter=""
fi
# build lndconnect
# see spec here: https://github.com/LN-Zap/lndconnect/blob/master/lnd_connect_uri.md
lndconnect="lndconnect://${host}:${port}${macaroonParameter}${certParameter}"
# display qr code image on LCD
/home/admin/config.scripts/blitz.display.sh qr "${lndconnect}"
# show pairing info dialog
msg=""
if [ $(echo "${host}" | grep -c '192.168') -gt 0 ]; then
msg="Make sure you are on the same local network.\n(WLAN same as LAN - use WIFI not cell network on phone).\n\n"
fi
if [ ${#usingIP2TOR} -gt 0 ] && [ ${forceTOR} -eq 0 ]; then
msg="Your IP2TOR bridge '${usingIP2TOR}' is used for this connection.\n\n"
fi
msg="You should now see the pairing QR code on the RaspiBlitz LCD.\n\n${msg}${connectInfo}\n\nIf your RaspiBlitz has no LCD use <Console QRcode>"
whiptail --backtitle "Connecting Mobile Wallet" \
--title "Pairing by QR code" \
--yes-button "Continue" \
--no-button "Console QRcode" \
--yesno "${msg}" 18 65
if [ $? -eq 1 ]; then
# backup - show QR code on screen (not LCD)
echo "##############"
echo "qrencode -o - -t ANSIUTF8 -m2 "${lndconnect}""
echo "##############"
qrencode -o - -t ANSIUTF8 -m2 "${lndconnect}"
echo "Press ENTER when finished."
read key
fi
# clean up
/home/admin/config.scripts/blitz.display.sh hide
echo "------------------------------"
echo "If the connection was not working:"
if [ ${#dynDomain} -gt 0 ]; then
echo "- Make sure that your router is forwarding port ${port} to the Raspiblitz"
fi
if [ $(echo "${host}" | grep -c '192.168') -gt 0 ]; then
echo "- Check that your WIFI devices can talk to the LAN devices on your router (deactivate IP isolation or guest mode)."
fi
echo "- try to refresh the TLS & macaroons: Main Menu 'EXPORT > 'RESET'"
echo "- check issues: https://github.com/rootzoll/raspiblitz/issues"
echo ""