raspiblitz/home.admin/97addMobileWalletLNDconnect.sh

166 lines
5.1 KiB
Bash
Raw Normal View History

2018-08-31 19:22:41 +02:00
#!/bin/bash
2019-04-04 03:25:13 +01:00
# get service port from argument
servicePort="10009"
if [ $# -gt 0 ]; then
2019-04-04 03:32:44 +01:00
if [ "$1" == "RPC" ]; then
echo "running RPC mode"
servicePort="10009"
fi
if [ "$1" == "REST" ]; then
echo "running REST mode"
servicePort="8080"
fi
2019-04-04 03:25:13 +01:00
fi
2018-12-21 01:59:26 +01:00
# load raspiblitz config data
2019-02-02 23:49:04 +01:00
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
2018-08-31 19:22:41 +02:00
2019-01-17 22:40:26 +01:00
# export go vars (if needed)
if [ ${#GOROOT} -eq 0 ]; then
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
fi
if [ ${#GOPATH} -eq 0 ]; then
export GOPATH=/usr/local/gocode
export PATH=$PATH:$GOPATH/bin
fi
2019-01-17 18:26:57 +01:00
2019-01-17 22:58:15 +01:00
# make sure go is installed
2019-03-14 11:39:56 +01:00
goVersion="1.11"
echo "### Check Framework: GO ###"
2019-01-17 22:58:15 +01:00
goInstalled=$(go version 2>/dev/null | grep -c 'go')
if [ ${goInstalled} -eq 0 ];then
2019-06-18 22:32:17 +02:00
goVersion="1.12.6"
2019-05-12 10:19:24 +01:00
if [ ${isARM} -eq 1 ] ; then
2019-05-07 01:42:51 +01:00
goOSversion="armv6l"
fi
2019-05-12 10:19:24 +01:00
if [ ${isAARCH64} -eq 1 ] ; then
goOSversion="arm64"
fi
2019-05-07 01:42:51 +01:00
if [ ${isX86_64} -eq 1 ] ; then
goOSversion="amd64"
fi
2019-05-11 10:42:37 +01:00
if [ ${isX86_32} -eq 1 ] ; then
goOSversion="386"
fi
2019-05-07 01:42:51 +01:00
echo "*** Installing Go v${goVersion} for ${goOSversion} ***"
# wget https://storage.googleapis.com/golang/go${goVersion}.linux-${goOSversion}.tar.gz
wget https://dl.google.com/go/go${goVersion}.linux-${goOSversion}.tar.gz
if [ ! -f "./go${goVersion}.linux-${goOSversion}.tar.gz" ]
then
echo "!!! FAIL !!! Download not success."
exit 1
fi
sudo tar -C /usr/local -xzf go${goVersion}.linux-${goOSversion}.tar.gz
2019-01-17 18:24:14 +01:00
sudo rm *.gz
sudo mkdir /usr/local/gocode
sudo chmod 777 /usr/local/gocode
2019-05-07 01:42:51 +01:00
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/usr/local/gocode
export PATH=$PATH:$GOPATH/bin
2019-01-17 22:58:15 +01:00
goInstalled=$(go version 2>/dev/null | grep -c 'go')
2019-01-17 18:24:14 +01:00
fi
2019-01-17 22:58:15 +01:00
if [ ${goInstalled} -eq 0 ];then
2019-01-31 21:10:01 +01:00
echo "FAIL: Was not able to install GO (needed to run LndConnect)"
2019-03-14 11:39:56 +01:00
sleep 4
2019-01-17 18:24:14 +01:00
exit 1
fi
2019-04-04 03:43:54 +01:00
2019-03-14 11:39:56 +01:00
correctGoVersion=$(go version | grep -c "go${goVersion}")
if [ ${correctGoVersion} -eq 0 ]; then
echo "WARNING: You work with a untested version of GO - should be ${goVersion} .. trying to continue"
go version
sleep 6
echo ""
fi
2019-01-17 18:24:14 +01:00
2018-08-31 19:22:41 +02:00
# make sure qrcode-encoder in installed
echo "*** Setup ***"
echo ""
echo "Installing lndconnect. Please wait..."
2018-08-31 19:22:41 +02:00
echo ""
2019-03-17 18:59:57 +01:00
echo "Getting github.com/LN-Zap/lndconnect (please wait - can take several minutes) ..."
2019-01-31 21:10:01 +01:00
go get -d github.com/LN-Zap/lndconnect
cd $GOPATH/src/github.com/LN-Zap/lndconnect
2018-08-31 19:22:41 +02:00
echo ""
2019-01-31 21:10:01 +01:00
echo "Building github.com/LN-Zap/lndconnect ..."
2018-12-21 03:03:06 +01:00
make
cd
sleep 3
2018-08-31 19:22:41 +02:00
2019-04-04 03:25:13 +01:00
# default host to local IP and port
2019-04-04 01:04:10 +01:00
local=1
2019-04-04 04:20:11 +01:00
localIP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
host="${localIP}"
2019-04-04 03:25:13 +01:00
port="${servicePort}"
2019-04-04 01:04:10 +01:00
# change host to dynDNS if set
if [ ${#dynDomain} -gt 0 ]; then
local=0
host="${dynDomain}"
2019-04-04 03:25:13 +01:00
echo "port ${servicePort} forwarding from dynDomain ${host}"
2019-04-04 01:04:10 +01:00
fi
2019-04-04 03:25:13 +01:00
# check if local service port is forwarded
2019-04-04 01:04:10 +01:00
if [ ${#sshtunnel} -gt 0 ]; then
2019-04-04 03:25:13 +01:00
isForwarded=$(echo ${sshtunnel} | grep -c "${servicePort}<")
2019-04-04 01:04:10 +01:00
if [ ${isForwarded} -gt 0 ]; then
local=0
host=$(echo $sshtunnel | cut -d '@' -f2 | cut -d ' ' -f1)
2019-04-04 03:47:31 +01:00
if [ "${servicePort}" == "10009" ]; then
2019-04-04 03:32:44 +01:00
port=$(echo $sshtunnel | awk '{split($0,a,"10009<"); print a[2]}' | cut -d ' ' -f1 | sed 's/[^0-9]//g')
2019-04-04 03:47:31 +01:00
elif [ "${servicePort}" == "8080" ]; then
2019-04-04 03:32:44 +01:00
port=$(echo $sshtunnel | awk '{split($0,a,"8080<"); print a[2]}' | cut -d ' ' -f1 | sed 's/[^0-9]//g')
fi
2019-04-04 03:25:13 +01:00
echo "port ${servicePort} forwarding from port ${port} from server ${host}"
2019-04-04 01:04:10 +01:00
else
2019-04-04 03:25:13 +01:00
echo "port ${servicePort} is not part of the ssh forwarding - keep default port ${servicePort}"
2019-04-04 01:04:10 +01:00
fi
fi
2019-04-04 04:34:27 +01:00
# write qr code data to an image
2019-04-04 04:10:46 +01:00
lndconnect --host=${host} --port=${port} --image
2018-08-31 19:22:41 +02:00
2019-04-04 04:34:27 +01:00
# display qr code image on LCD
2019-04-04 04:10:46 +01:00
./XXdisplayLCD.sh lndconnect-qr.png
2018-08-31 19:22:41 +02:00
2019-04-04 04:34:27 +01:00
# show pairing info dialog
2019-04-04 04:08:05 +01:00
msg=""
if [ ${local} -eq 1 ]; then
2019-04-04 04:26:54 +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"
2019-04-04 04:08:05 +01:00
fi
2019-04-27 02:58:23 +02:00
msg="You should now see the pairing QR code on the RaspiBlitz LCD.\n\n${msg}When you start the App choose to connect to your own node.\n(DIY / Remote-Node / lndconnect)\n\nClick on the 'Scan QR' button. Scan the QR on the LCD and <continue> or <show QR code> to see it in this window."
2019-04-04 04:08:05 +01:00
whiptail --backtitle "Connecting Mobile Wallet" \
--title "Pairing by QR code" \
--yes-button "continue" \
--no-button "show QR code" \
2019-08-13 01:21:42 +02:00
--yesno "${msg}" 18 65
2019-04-04 04:08:05 +01:00
if [ $? -eq 1 ]; then
lndconnect --host=${host} --port=${port}
echo "(To shrink QR code: OSX->CMD- / LINUX-> CTRL-) Press ENTER when finished."
read key
fi
2018-08-31 19:22:41 +02:00
2019-04-04 04:08:05 +01:00
# clean up
./XXdisplayQRlcd_hide.sh
2019-04-04 04:10:46 +01:00
shred lndconnect-qr.png 2> /dev/null
rm -f lndconnect-qr.png 2> /dev/null
2019-04-04 04:08:05 +01:00
shred qr.txt 2> /dev/null
2019-04-04 04:20:11 +01:00
rm -f qr.txt 2> /dev/null
echo "------------------------------"
2019-04-04 04:27:33 +01:00
echo "If the connection was not working:"
2019-04-04 04:20:11 +01:00
if [ ${#dynDomain} -gt 0 ]; then
echo "- Make sure that your router is forwarding port ${port} to the Raspiblitz with IP ${localIP}"
fi
2019-04-04 04:26:54 +01:00
if [ ${local} -eq 1 ]; then
echo "- Check that your WIFI devices can talk to the LAN devices on your router (deactivate IP isolation or guest mode)."
fi
2019-04-04 04:20:11 +01:00
echo "- check issues: https://github.com/LN-Zap/lndconnect/issues"
echo "- check issues: https://github.com/rootzoll/raspiblitz/issues"
2019-04-04 04:26:54 +01:00
echo ""