2019-12-04 12:05:27 +00:00
#!/bin/bash
2020-01-23 18:59:53 +01:00
# 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"
2022-06-01 23:07:38 +02:00
echo "# bonus.lndconnect.sh [zap-ios|zap-android|zeus-ios|zeus-android|shango-ios|shango-android|sendmany-android|fullynoded-lnd] [?ip|tor] [?key-value]"
2020-01-23 18:59:53 +01:00
exit 1
fi
2022-05-11 22:31:55 +02:00
# check if lnd is on
source <( /home/admin/_cache.sh get lnd)
if [ " ${ lnd } " != on ] ; then
echo "error='lnd not active'"
exit 1
fi
2021-03-24 00:20:05 +01:00
# make sure commandline tool is available
sudo apt-get install -y qrencode 1>/dev/null 2>/dev/null
2020-01-23 18:59:53 +01:00
# load raspiblitz config data
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
#### PARAMETER
2020-01-25 16:29:02 +01:00
# 1. TARGET WALLET
2020-01-27 16:59:26 +01:00
targetWallet = $1
2020-01-23 18:59:53 +01:00
2020-01-27 16:59:26 +01:00
# 1. TOR or IP (optional - default IP)
forceTOR = 0
if [ " $2 " = = "tor" ] ; then
forceTOR = 1
2020-01-23 18:59:53 +01:00
fi
2020-05-27 01:00:26 +02:00
#### 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
2022-02-17 11:52:37 +01:00
echo " # using ip2torREST: IP( ${ ip } ) PORT( ${ port } ) "
2020-05-27 01:00:26 +02:00
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
2022-02-17 11:52:37 +01:00
echo " # using ip2torGRPC: IP( ${ ip } ) PORT( ${ port } ) "
2020-05-27 01:00:26 +02:00
ip2torGRPC_IP = " ${ ip } "
ip2torGRPC_PORT = " ${ port } "
fi
2022-05-17 14:31:17 -06:00
#### ADAPT PARAMETERS BASED TARGETWALLET
2020-01-23 18:59:53 +01:00
2020-01-25 16:29:02 +01:00
# defaults
host = ""
port = ""
2021-03-24 00:20:05 +01:00
addcert = 1
2020-01-25 16:29:02 +01:00
supportsTOR = 0
2020-05-27 01:55:03 +02:00
usingIP2TOR = ""
2021-04-20 00:26:49 +02:00
connectInfo = "When you start the App choose to connect to your own node.\n(DIY / Remote-Node / lndconnect)\nClick on the 'Scan QR' button."
2020-01-23 18:59:53 +01:00
2020-01-25 16:29:02 +01:00
if [ " ${ targetWallet } " = "zap-ios" ] ; then
2020-01-27 16:59:26 +01:00
if [ ${ forceTOR } -eq 1 ] ; then
2020-01-25 16:29:02 +01:00
# when ZAP runs on TOR it uses REST
port = "8080"
2021-03-24 00:20:05 +01:00
addcert = 0
2020-01-25 16:29:02 +01:00
else
2022-02-17 12:28:47 +01:00
# ZAP uses gRPC ports
2020-01-25 16:29:02 +01:00
port = "10009"
fi
2020-05-27 01:55:03 +02:00
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 } "
2022-05-17 14:31:17 -06:00
fi
2020-01-25 16:29:02 +01:00
elif [ " ${ targetWallet } " = "zap-android" ] ; then
2021-04-20 00:26:49 +02:00
connectInfo = "- start the Zap Wallet --> SETUP WALLET\n or choose new Wallet in app menu\n- scan the QR code \n- confirm host address"
2022-02-17 12:28:47 +01:00
# ZAP uses gRPC ports
port = "10009"
2020-05-27 01:18:55 +02:00
if [ ${# ip2torGRPC_IP } -gt 0 ] ; then
# when IP2TOR bridge is available - force using that
2020-05-27 01:55:03 +02:00
usingIP2TOR = "LND-GRPC-API"
2021-03-24 00:20:05 +01:00
forceTOR = 1
2020-05-27 01:18:55 +02:00
host = " ${ ip2torGRPC_IP } "
port = " ${ ip2torGRPC_PORT } "
2022-05-17 14:31:17 -06:00
fi
2020-01-25 16:29:02 +01:00
elif [ " ${ targetWallet } " = "zeus-ios" ] ; then
2021-03-24 00:20:05 +01:00
port = "8080"
2020-05-27 01:55:03 +02:00
usingIP2TOR = "LND-REST-API"
2021-03-24 00:20:05 +01:00
forceTOR = 1
host = $( sudo cat /mnt/hdd/tor/lndrest8080/hostname)
2021-04-20 00:26:49 +02:00
connectInfo = "- start the Zeus Wallet --> lndconnect\n- scan the QR code \n- activate 'Tor' option \n- activate 'Certification Verification' option\n- save Node Config"
2020-01-25 16:29:02 +01:00
elif [ " ${ targetWallet } " = "zeus-android" ] ; then
2021-03-24 00:20:05 +01:00
port = "8080"
2020-05-27 01:55:03 +02:00
usingIP2TOR = "LND-REST-API"
2021-03-24 00:20:05 +01:00
forceTOR = 1
host = $( sudo cat /mnt/hdd/tor/lndrest8080/hostname)
2021-04-20 00:26:49 +02:00
connectInfo = "- start the Zeus Wallet --> lndconnect\n- scan the QR code \n- activate 'Tor' option \n- activate 'Certification Verification' option\n- save Node Config"
2020-01-25 16:29:02 +01:00
2020-04-05 10:19:44 +02:00
elif [ " ${ targetWallet } " = "sendmany-android" ] ; then
connector = "lndconnect"
if [ ${ forceTOR } -eq 1 ] ; then
2020-05-08 12:52:55 +02:00
# echo "error='no tor support'"
# exit 1
2021-03-24 00:20:05 +01:00
# port="8080"
# addcert=0
2020-05-08 12:52:55 +02:00
# 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
2020-04-05 10:19:44 +02:00
fi
2020-04-05 13:53:45 +02:00
port = "10009"
2020-05-27 01:55:03 +02:00
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 } "
2022-05-17 14:31:17 -06:00
fi
2020-01-25 16:29:02 +01:00
2021-10-08 16:12:43 +01:00
elif [ " ${ targetWallet } " = "fullynoded-lnd" ] ; then
port = "8080"
usingIP2TOR = "LND-REST-API"
forceTOR = 1
host = $( sudo cat /mnt/hdd/tor/lndrest8080/hostname)
connectInfo = "- start Fully Noded and go to:\n Settings' -> 'Node Manger' -> 'scan QR'"
2020-01-25 16:29:02 +01:00
else
echo "error='unknown target wallet'"
exit 1
fi
#### ADAPT PARAMETERS BASED RASPIBLITZ CONFIG
# get the local IP as default host
2020-05-27 01:18:55 +02:00
if [ ${# host } -eq 0 ] ; then
2021-08-04 00:18:30 +02:00
host = $( hostname -I | awk '{print $1}' )
2020-05-27 01:18:55 +02:00
fi
2020-01-25 16:29:02 +01:00
# change host to dynDNS if set
if [ ${# dynDomain } -gt 0 ] ; then
host = " ${ dynDomain } "
2020-01-23 18:59:53 +01:00
fi
2020-01-25 16:29:02 +01:00
# tunnel thru TOR if running and supported by the wallet
2020-01-27 16:59:26 +01:00
if [ ${ forceTOR } -eq 1 ] ; then
2020-01-23 18:59:53 +01:00
# depending on RPC or REST use different TOR address
2020-01-25 16:29:02 +01:00
if [ " ${ port } " = = "10009" ] ; then
2022-02-17 12:22:39 +01:00
echo "# TOR LND RPC"
host = $( sudo cat /mnt/hdd/tor/lndrpc/hostname)
if [ " ${ host } " = = "" ] ; then
echo "# setting up onion service ..."
/home/admin/config.scripts/tor.onion-service.sh lndrpc 10009 10009
host = $( sudo cat /mnt/hdd/tor/lndrpc/hostname)
fi
2020-01-25 16:29:02 +01:00
elif [ " ${ port } " = = "8080" ] ; then
2022-02-17 12:22:39 +01:00
echo "# TOR LND REST"
host = $( sudo cat /mnt/hdd/tor/lndrest/hostname)
if [ " ${ host } " = = "" ] ; then
echo "# setting up onion service ..."
/home/admin/config.scripts/tor.onion-service.sh lndrest 8080 8080
host = $( sudo cat /mnt/hdd/tor/lndrest/hostname)
fi
2020-01-25 16:29:02 +01:00
fi
2022-02-17 12:22:39 +01:00
echo " # TOR --> host ${ host } port ${ port } "
2020-01-25 16:29:02 +01:00
fi
2022-05-17 14:31:17 -06:00
2020-01-25 16:29:02 +01:00
# 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
2020-01-23 18:59:53 +01:00
fi
fi
2020-01-27 16:59:26 +01:00
2020-01-23 18:59:53 +01:00
#### RUN LNDCONNECT
2021-03-24 00:20:05 +01:00
# generate data parts
2021-08-18 17:49:05 +01:00
macaroon = $( sudo base64 /home/bitcoin/.lnd/data/chain/${ network } /${ chain } net/admin.macaroon | tr -d '=' | tr '/+' '_-' | tr -d '\n' )
2021-03-24 00:20:05 +01:00
cert = $( sudo grep -v 'CERTIFICATE' /mnt/hdd/lnd/tls.cert | tr -d '=' | tr '/+' '_-' | tr -d '\n' )
2020-01-23 18:59:53 +01:00
2021-03-24 00:20:05 +01:00
# generate URI parameters
macaroonParameter = " ?macaroon= ${ macaroon } "
certParameter = " &cert= ${ cert } "
2020-01-23 18:59:53 +01:00
2021-03-24 00:20:05 +01:00
# mute cert parameter (optional)
if [ ${ addcert } -eq 0 ] ; then
certParameter = ""
fi
2020-01-24 17:31:59 +01:00
2021-03-24 00:20:05 +01:00
# build lndconnect
# see spec here: https://github.com/LN-Zap/lndconnect/blob/master/lnd_connect_uri.md
lndconnect = " lndconnect:// ${ host } : ${ port } ${ macaroonParameter } ${ certParameter } "
2020-01-24 17:31:59 +01:00
2022-05-11 22:31:55 +02:00
if [ " $3 " = = "key-value" ] ; then
echo " lndconnect=' ${ lndconnect } ' "
exit 0
fi
2021-03-24 00:20:05 +01:00
# display qr code image on LCD
2022-02-13 12:23:34 +00:00
sudo /home/admin/config.scripts/blitz.display.sh qr " ${ lndconnect } "
2020-01-23 18:59:53 +01:00
# show pairing info dialog
msg = ""
2020-01-25 16:29:02 +01:00
if [ $( echo " ${ host } " | grep -c '192.168' ) -gt 0 ] ; then
2020-01-23 18:59:53 +01:00
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
2021-03-24 00:20:05 +01:00
if [ ${# usingIP2TOR } -gt 0 ] && [ ${ forceTOR } -eq 0 ] ; then
2020-05-27 01:55:03 +02:00
msg = " Your IP2TOR bridge ' ${ usingIP2TOR } ' is used for this connection.\n\n "
2020-05-27 01:28:33 +02:00
fi
2021-04-20 00:26:49 +02:00
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> "
2020-01-23 18:59:53 +01:00
whiptail --backtitle "Connecting Mobile Wallet" \
--title "Pairing by QR code" \
2020-09-14 23:39:06 +02:00
--yes-button "Continue" \
--no-button "Console QRcode" \
2020-01-23 18:59:53 +01:00
--yesno " ${ msg } " 18 65
if [ $? -eq 1 ] ; then
2020-01-27 16:59:26 +01:00
# backup - show QR code on screen (not LCD)
2021-03-24 00:20:05 +01:00
echo "##############"
echo "qrencode -o - -t ANSIUTF8 -m2 " ${ lndconnect } ""
echo "##############"
qrencode -o - -t ANSIUTF8 -m2 " ${ lndconnect } "
echo "Press ENTER when finished."
read key
2020-01-23 18:59:53 +01:00
fi
# clean up
2022-02-13 12:23:34 +00:00
sudo /home/admin/config.scripts/blitz.display.sh hide
2020-01-23 18:59:53 +01:00
echo "------------------------------"
echo "If the connection was not working:"
if [ ${# dynDomain } -gt 0 ] ; then
2020-01-25 16:29:02 +01:00
echo " - Make sure that your router is forwarding port ${ port } to the Raspiblitz "
2020-01-23 18:59:53 +01:00
fi
2020-01-25 16:29:02 +01:00
if [ $( echo " ${ host } " | grep -c '192.168' ) -gt 0 ] ; then
2020-01-23 18:59:53 +01:00
echo "- Check that your WIFI devices can talk to the LAN devices on your router (deactivate IP isolation or guest mode)."
2019-12-17 13:44:10 +00:00
fi
2020-01-23 18:59:53 +01:00
echo "- try to refresh the TLS & macaroons: Main Menu 'EXPORT > 'RESET'"
echo "- check issues: https://github.com/rootzoll/raspiblitz/issues"
2020-10-13 20:03:27 +02:00
echo ""