2019-01-15 20:19:36 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# command info
|
2019-01-15 22:48:55 +01:00
|
|
|
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
2019-01-15 20:19:36 +01:00
|
|
|
echo "tool to export macaroons & tls.cert"
|
2020-09-17 16:32:36 +02:00
|
|
|
echo "lnd.export.sh [hexstring|scp|http|btcpay]"
|
2019-01-15 20:19:36 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 1. parameter -> the type of export
|
|
|
|
exportType=$1
|
|
|
|
|
2019-01-15 22:42:41 +01:00
|
|
|
# interactive choose type of export if not set
|
|
|
|
if [ "$1" = "" ] || [ $# -eq 0 ]; then
|
|
|
|
OPTIONS=()
|
|
|
|
OPTIONS+=(SCP "SSH Download (Commands)")
|
2019-01-21 20:45:00 +01:00
|
|
|
OPTIONS+=(HTTP "Browserdownload (bit risky)")
|
2020-09-17 16:32:36 +02:00
|
|
|
OPTIONS+=(HEX "Hex-String (Copy+Paste)")
|
|
|
|
OPTIONS+=(STR "BTCPay Connection String")
|
2019-01-15 22:42:41 +01:00
|
|
|
CHOICE=$(dialog --clear \
|
|
|
|
--backtitle "RaspiBlitz" \
|
|
|
|
--title "Export Macaroons & TLS.cert" \
|
|
|
|
--menu "How do you want to export?" \
|
2019-01-21 20:45:00 +01:00
|
|
|
11 50 7 \
|
2019-01-15 22:42:41 +01:00
|
|
|
"${OPTIONS[@]}" \
|
|
|
|
2>&1 >/dev/tty)
|
|
|
|
clear
|
|
|
|
case $CHOICE in
|
|
|
|
HEX)
|
|
|
|
exportType='hexstring';
|
|
|
|
;;
|
2020-09-17 16:32:36 +02:00
|
|
|
STR)
|
|
|
|
exportType='btcpay';
|
|
|
|
;;
|
2019-01-15 22:42:41 +01:00
|
|
|
SCP)
|
|
|
|
exportType='scp';
|
|
|
|
;;
|
|
|
|
HTTP)
|
|
|
|
exportType='http';
|
|
|
|
;;
|
|
|
|
esac
|
2020-09-17 16:32:36 +02:00
|
|
|
|
2019-01-15 22:42:41 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# load data from config
|
2019-02-02 23:49:04 +01:00
|
|
|
source /home/admin/raspiblitz.info
|
|
|
|
source /mnt/hdd/raspiblitz.conf
|
2019-01-15 22:42:41 +01:00
|
|
|
|
2019-01-21 20:45:00 +01:00
|
|
|
########################
|
|
|
|
# CANCEL
|
|
|
|
########################
|
|
|
|
if [ ${#exportType} -eq 0 ]; then
|
|
|
|
|
|
|
|
echo "CANCEL"
|
|
|
|
exit 0
|
|
|
|
|
2019-01-15 20:19:36 +01:00
|
|
|
########################
|
|
|
|
# HEXSTRING
|
|
|
|
########################
|
2019-01-21 20:45:00 +01:00
|
|
|
elif [ "${exportType}" = "hexstring" ]; then
|
2019-01-15 20:19:36 +01:00
|
|
|
|
|
|
|
clear
|
|
|
|
echo "###### HEXSTRING EXPORT ######"
|
|
|
|
echo ""
|
|
|
|
echo "admin.macaroon:"
|
|
|
|
sudo xxd -ps -u -c 1000 /mnt/hdd/lnd/data/chain/${network}/${chain}net/admin.macaroon
|
|
|
|
echo ""
|
2019-01-21 21:08:13 +01:00
|
|
|
echo "invoice.macaroon:"
|
|
|
|
sudo xxd -ps -u -c 1000 /mnt/hdd/lnd/data/chain/${network}/${chain}net/invoice.macaroon
|
|
|
|
echo ""
|
2019-01-15 20:19:36 +01:00
|
|
|
echo "readonly.macaroon:"
|
|
|
|
sudo xxd -ps -u -c 1000 /mnt/hdd/lnd/data/chain/${network}/${chain}net/readonly.macaroon
|
|
|
|
echo ""
|
|
|
|
echo "tls.cert:"
|
|
|
|
sudo xxd -ps -u -c 1000 /mnt/hdd/lnd/tls.cert
|
|
|
|
echo ""
|
|
|
|
|
2020-09-17 16:32:36 +02:00
|
|
|
########################
|
|
|
|
# BTCPAY Connection String
|
|
|
|
########################
|
|
|
|
elif [ "${exportType}" = "btcpay" ]; then
|
|
|
|
|
|
|
|
# take public IP as default
|
|
|
|
# TODO: IP2TOR --> check if there is a forwarding for LND REST oe ask user to set one up
|
|
|
|
#ip="${publicIP}"
|
|
|
|
ip="127.0.0.1"
|
|
|
|
port="8080"
|
|
|
|
|
|
|
|
# will overwrite ip & port if IP2TOR tunnel is available
|
|
|
|
source <(sudo /home/admin/config.scripts/blitz.subscriptions.ip2tor.py subscription-by-service LND-REST-API)
|
|
|
|
|
2020-12-24 21:27:37 +01:00
|
|
|
# bake macaroon that just can create invoices and monitor them
|
|
|
|
macaroon=$(sudo -u admin lncli bakemacaroon address:read address:write info:read invoices:read invoices:write onchain:read)
|
2020-09-17 16:32:36 +02:00
|
|
|
|
2020-12-24 21:27:37 +01:00
|
|
|
# old: admin macaroon (remove after v1.6.3 release)
|
|
|
|
#macaroon=$(sudo xxd -ps -u -c 1000 /mnt/hdd/lnd/data/chain/${network}/${chain}net/admin.macaroon)
|
2020-09-17 16:32:36 +02:00
|
|
|
|
|
|
|
# get certificate thumb
|
|
|
|
certthumb=$(sudo openssl x509 -noout -fingerprint -sha256 -inform pem -in /mnt/hdd/lnd/tls.cert | cut -d "=" -f 2)
|
|
|
|
|
|
|
|
# construct connection string
|
|
|
|
connectionString="type=lnd-rest;server=https://${ip}:${port}/;macaroon=${macaroon};certthumbprint=${certthumb}"
|
|
|
|
|
|
|
|
clear
|
|
|
|
echo "###### BTCPAY CONNECTION STRING ######"
|
|
|
|
echo ""
|
|
|
|
echo "${connectionString}"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
# add info about outside reachability (type would have a value if IP2TOR tunnel was found)
|
|
|
|
if [ ${#type} -gt 0 ]; then
|
|
|
|
echo "NOTE: You have a IP2TOR connection for LND REST API .. so you can use this connection string also with a external BTCPay server."
|
|
|
|
else
|
|
|
|
echo "IMPORTANT: You can only use this connection string for a BTCPay server running on this RaspiBlitz."
|
|
|
|
echo "If you want to connect from a external BTCPay server activate a IP2TOR tunnel for LND-REST first:"
|
|
|
|
echo "MAIN MENU > SUBSCRIBE > IP2TOR > LND REST API"
|
|
|
|
echo "Then come back and get a new connection string."
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
|
2019-01-15 20:19:36 +01:00
|
|
|
###########################
|
|
|
|
# SHH / SCP File Download
|
|
|
|
###########################
|
2019-01-21 20:45:00 +01:00
|
|
|
elif [ "${exportType}" = "scp" ]; then
|
2019-01-15 20:19:36 +01:00
|
|
|
|
2021-06-25 23:48:33 +01:00
|
|
|
local_ip=$(ip addr | grep 'state UP' -A2 | grep -E -v 'docker0|veth' | grep 'eth0\|wlan0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
|
2019-01-15 20:19:36 +01:00
|
|
|
clear
|
|
|
|
echo "###### DOWNLOAD BY SCP ######"
|
2019-01-15 22:53:42 +01:00
|
|
|
echo "Copy, paste and execute these commands in your client terminal to download the files."
|
2019-01-15 20:19:36 +01:00
|
|
|
echo "The password needed during download is your Password A."
|
|
|
|
echo ""
|
2020-08-02 22:52:05 +02:00
|
|
|
echo "Macaroons:"
|
|
|
|
echo "scp bitcoin@${local_ip}:/home/bitcoin/.lnd/data/chain/${network}/${chain}net/\*.macaroon ./"
|
2019-01-21 21:08:13 +01:00
|
|
|
echo ""
|
2020-08-02 22:52:05 +02:00
|
|
|
echo "TLS Certificate:"
|
2019-01-15 20:22:50 +01:00
|
|
|
echo "scp bitcoin@${local_ip}:/home/bitcoin/.lnd/tls.cert ./"
|
2019-01-15 20:19:36 +01:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# HTTP File Download
|
|
|
|
###########################
|
2019-01-21 20:45:00 +01:00
|
|
|
elif [ "${exportType}" = "http" ]; then
|
2019-01-15 20:19:36 +01:00
|
|
|
|
2021-06-25 23:48:33 +01:00
|
|
|
local_ip=$(ip addr | grep 'state UP' -A2 | grep -E -v 'docker0|veth' | grep 'eth0\|wlan0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
|
2019-01-15 20:34:58 +01:00
|
|
|
randomPortNumber=$(shuf -i 20000-39999 -n 1)
|
2019-01-15 22:56:20 +01:00
|
|
|
sudo ufw allow from 192.168.0.0/16 to any port ${randomPortNumber} comment 'temp http server'
|
2019-01-15 20:19:36 +01:00
|
|
|
clear
|
|
|
|
echo "###### DOWNLOAD BY HTTP ######"
|
|
|
|
echo ""
|
2019-01-15 20:34:58 +01:00
|
|
|
echo "Open in your browser --> http://${local_ip}:${randomPortNumber}"
|
2019-01-16 00:01:59 +01:00
|
|
|
echo ""
|
2019-01-15 20:34:58 +01:00
|
|
|
echo "You need to be on the same local network - not reachable from outside."
|
2019-01-15 20:19:36 +01:00
|
|
|
echo "In browser click on files or use 'save as' from context menu to download."
|
|
|
|
echo ""
|
|
|
|
echo "Temp HTTP Server is running - use CTRL+C to stop when you are done"
|
2019-01-16 00:01:59 +01:00
|
|
|
echo ""
|
2019-01-15 20:19:36 +01:00
|
|
|
cd
|
2019-01-15 20:34:58 +01:00
|
|
|
randomFolderName=$(shuf -i 100000000-900000000 -n 1)
|
|
|
|
mkdir ${randomFolderName}
|
|
|
|
sudo cp /home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon ./${randomFolderName}/admin.macaroon
|
|
|
|
sudo cp /home/bitcoin/.lnd/data/chain/${network}/${chain}net/readonly.macaroon ./${randomFolderName}/readonly.macaroon
|
2019-01-21 21:08:13 +01:00
|
|
|
sudo cp /home/bitcoin/.lnd/data/chain/${network}/${chain}net/invoice.macaroon ./${randomFolderName}/invoice.macaroon
|
2019-01-15 20:34:58 +01:00
|
|
|
sudo cp /home/bitcoin/.lnd/tls.cert ./${randomFolderName}/tls.cert
|
|
|
|
cd ${randomFolderName}
|
2019-01-15 20:50:40 +01:00
|
|
|
sudo chmod 444 *.*
|
2020-02-17 15:01:45 +01:00
|
|
|
python3 -m http.server ${randomPortNumber} 2>/dev/null
|
2019-01-15 20:45:13 +01:00
|
|
|
sudo ufw delete allow from 192.168.0.0/16 to any port ${randomPortNumber} comment 'temp http server'
|
2019-01-15 20:19:36 +01:00
|
|
|
cd ..
|
2019-01-15 20:34:58 +01:00
|
|
|
sudo rm -r ${randomFolderName}
|
2019-01-15 20:19:36 +01:00
|
|
|
echo "OK - temp HTTP server is stopped."
|
|
|
|
|
|
|
|
else
|
2020-05-01 11:17:07 +02:00
|
|
|
echo "FAIL: unknown '${exportType}' - run with -h for help"
|
2020-02-17 14:52:45 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "" ] || [ $# -eq 0 ]; then
|
|
|
|
echo "Press ENTER to return to main menu."
|
|
|
|
read key
|
2020-04-30 22:07:27 +02:00
|
|
|
fi
|