raspiblitz/home.admin/config.scripts/lnd.export.sh

155 lines
5.1 KiB
Bash
Raw Normal View History

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"
2019-01-21 20:45:00 +01:00
echo "lnd.export.sh [hexstring|scp|http|reset]"
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+=(HEX "Hex-String (Copy+Paste)")
OPTIONS+=(SCP "SSH Download (Commands)")
2019-01-21 20:45:00 +01:00
OPTIONS+=(HTTP "Browserdownload (bit risky)")
OPTIONS+=(RESET "RENEW MACAROONS & TLS")
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';
;;
SCP)
exportType='scp';
;;
HTTP)
exportType='http';
;;
2019-01-21 20:45:00 +01:00
RESET)
exportType='reset';
;;
2019-01-15 22:42:41 +01:00
esac
fi
# load data from config
source /mnt/hdd/raspiblitz.conf 2>/dev/null
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 ""
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 ""
###########################
# SHH / SCP File Download
###########################
2019-01-21 20:45:00 +01:00
elif [ "${exportType}" = "scp" ]; then
2019-01-15 20:19:36 +01:00
local_ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
clear
echo "###### DOWNLOAD BY SCP ######"
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 ""
echo "admin.macaroon:"
2019-01-15 20:22:50 +01:00
echo "scp bitcoin@${local_ip}:/home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon ./"
2019-01-15 20:19:36 +01:00
echo ""
echo "readonly.macaroon:"
2019-01-15 20:22:50 +01:00
echo "scp bitcoin@${local_ip}:/home/bitcoin/.lnd/data/chain/${network}/${chain}net/readonly.macaroon ./"
2019-01-15 20:19:36 +01:00
echo ""
echo "tls.cert:"
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
local_ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
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 ""
echo "Open in your browser --> http://${local_ip}:${randomPortNumber}"
2019-01-16 00:01:59 +01:00
echo ""
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
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
sudo cp /home/bitcoin/.lnd/tls.cert ./${randomFolderName}/tls.cert
cd ${randomFolderName}
2019-01-15 20:50:40 +01:00
sudo chmod 444 *.*
2019-01-15 22:56:20 +01:00
python -m SimpleHTTPServer ${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 ..
sudo rm -r ${randomFolderName}
2019-01-15 20:19:36 +01:00
echo "OK - temp HTTP server is stopped."
2019-01-21 20:45:00 +01:00
###########################
# RESET Macaroons and TLS
###########################
elif [ "${exportType}" = "reset" ]; then
clear
echo "###### RESET MACAROONS AND TLS.cert ######"
echo ""
echo "All your macaroons and the tls.cert gets gets deleted and recreated."
echo ""
cd
echo "- deleting old macaroons"
sudo rm /home/bitcoin/.lnd/data/chain/${network}/${chain}net/*.macaroon
2019-01-21 20:49:13 +01:00
sudo rm /home/bitcoin/.lnd/data/chain/${network}/${chain}net/macaroons.db
2019-01-21 20:45:00 +01:00
echo "- resetting TLS cert"
sudo /home/admin/config.scripts/lnd.newtlscert.sh
2019-01-21 20:53:56 +01:00
echo "- restarting LND ... wait 20 secs"
sudo systemctl start lnd
sleep 20
lncli unlock
2019-01-21 20:45:00 +01:00
echo "- copy new macaroons to admin user"
sudo cp /home/bitcoin/.lnd/data/chain/${network}/${chain}net/*.macaroon /home/admin/.lnd/data/chain/${network}/${chain}net/
2019-01-21 20:49:13 +01:00
sudo cp /home/bitcoin/.lnd/data/chain/${network}/${chain}net/macaroons.db /home/admin/.lnd/data/chain/${network}/${chain}net/
2019-01-21 20:45:00 +01:00
sudo chown admin:admin -R /home/admin/.lnd/data/chain/${network}/${chain}net/*.macaroon
2019-01-21 20:49:13 +01:00
sudo chown admin:admin /home/admin/.lnd/data/chain/${network}/${chain}net/macaroons.db
2019-01-21 20:53:56 +01:00
echo "OK DONE"
2019-01-21 20:45:00 +01:00
2019-01-15 20:19:36 +01:00
else
echo "FAIL: unknown '${exportType}' -run-> ./lnd.export.sh -h"
fi