raspiblitz/home.admin/70initLND.sh

247 lines
7.7 KiB
Bash
Raw Normal View History

2018-07-17 13:12:03 +02:00
#!/bin/sh
echo ""
2018-07-29 01:33:54 +02:00
# load network
network=`cat .network`
2018-08-08 17:36:04 +02:00
# get chain
2018-08-24 03:29:53 +02:00
chain="test"
isMainChain=$(sudo cat /mnt/hdd/${network}/${network}.conf 2>/dev/null | grep "#testnet=1" -c)
if [ ${isMainChain} -gt 0 ];then
chain="main"
fi
2018-08-08 17:36:04 +02:00
2018-07-17 13:12:03 +02:00
# verify that bitcoin is running
2018-07-29 01:33:54 +02:00
echo "*** Checking ${network} ***"
2018-08-24 03:26:57 +02:00
bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running)
2018-08-24 12:42:18 +02:00
if [ ${bitcoinRunning} -eq 0 ]; then
2018-08-24 12:40:22 +02:00
#doublecheck
bitcoinRunning=$(${network}-cli getblockchaininfo | grep -c verificationprogress)
fi
2018-07-17 13:12:03 +02:00
if [ ${bitcoinRunning} -eq 0 ]; then
# HDD is not available yet
2018-07-29 01:33:54 +02:00
echo "FAIL - ${network}d is not running"
2018-07-17 13:12:03 +02:00
echo "recheck with orignal tutorial -->"
echo "https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_30_bitcoin.md"
fi
2018-07-29 01:33:54 +02:00
echo "OK - ${network}d is running"
2018-07-17 13:12:03 +02:00
echo ""
2018-08-24 00:46:30 +02:00
###### Wait for Blochain Sync --> LET DO THIS LATER ON LND SCAN
#echo "*** Syncing Blockchain ***"
#ready=0
#while [ ${ready} -eq 0 ]
# do
# progress="$(sudo -u bitcoin ${network}-cli getblockchaininfo | jq -r '.verificationprogress')"
# verySmallProgress=$(echo $progress | grep -c 'e-');
# if [ ${verySmallProgress} -eq 1 ]; then
# progress="0.00";
# fi
# ready=$(echo $progress'>0.99' | bc -l)
# sync_percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')")
# #echo "progress($progress) verySmallProgress($verySmallProgress) ready($ready) sync_percentage($sync_percentage)"
# if [ ${#ready} -eq 0 ]; then
# echo "waiting for init ... can take a while"
# ready=0
# elif [ "$sync_percentage" = "0.00%" ]; then
# echo "waiting for network ... can take a while"
# ready=0
# elif [ ${ready} -eq 0 ]; then
# echo "${sync_percentage}"
# else
# echo "finishing sync ... can take a while"
# fi
# sleep 3
# done
#echo "OK - Blockchain is synced"
#echo ""
2018-07-17 13:12:03 +02:00
###### LND Config
echo "*** LND Config ***"
configExists=$( sudo ls /mnt/hdd/lnd/ | grep -c lnd.conf )
if [ ${configExists} -eq 0 ]; then
2018-07-31 20:13:08 +02:00
sudo cp /home/admin/assets/lnd.${network}.conf /mnt/hdd/lnd/lnd.conf
2018-07-17 13:12:03 +02:00
sudo chown bitcoin:bitcoin /mnt/hdd/lnd/lnd.conf
if [ -d /home/bitcoin/.lnd ]; then
echo "OK - LND config written"
else
echo "FAIL - Was not able to setup LND"
exit 1
fi
else
echo "OK - exists"
fi
echo ""
###### Start LND
echo "*** Starting LND ***"
2018-08-24 04:38:35 +02:00
lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running)
2018-07-17 13:12:03 +02:00
if [ ${lndRunning} -eq 0 ]; then
2018-07-29 12:21:52 +02:00
sed -i "5s/.*/Wants=${network}d.service/" ./assets/lnd.service
sed -i "6s/.*/After=${network}d.service/" ./assets/lnd.service
sudo cp /home/admin/assets/lnd.service /etc/systemd/system/lnd.service
2018-08-07 14:03:59 +02:00
sudo chmod +x /etc/systemd/system/lnd.service
2018-07-17 13:12:03 +02:00
sudo systemctl enable lnd
sudo systemctl start lnd
2018-08-23 21:54:37 +02:00
echo "Starting LND ... give 120 seconds to init."
sleep 120
2018-07-17 13:12:03 +02:00
fi
###### Check LND is running
2018-08-23 21:54:37 +02:00
lndRunning=0
while [ ${lndRunning} -eq 0 ]
do
lndRunning=$(systemctl status lnd.service | grep -c running)
if [ ${lndRunning} -eq 0 ]; then
date +%s
echo "LND not ready yet ... waiting another 60 seconds."
echo "If this takes too long (more then 10min total) --> CTRL+c and report Problem"
sleep 60
fi
done
2018-07-17 13:12:03 +02:00
echo "OK - LND is running"
echo ""
###### Instructions on Creating LND Wallet
2018-08-08 19:50:46 +02:00
walletExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${chain}net/wallet.db 2>/dev/null | grep wallet.db -c)
2018-08-09 11:54:15 +02:00
echo "walletExists(${walletExists})"
2018-08-09 12:04:31 +02:00
sleep 2
2018-08-08 17:36:04 +02:00
if [ ${walletExists} -eq 0 ]; then
2018-08-09 02:22:27 +02:00
# delete old macaroons if exist
sudo rm /mnt/hdd/lnd/*.macaroon 2>/dev/null
sudo rm /home/admin/.lnd/*.macaroon 2>/dev/null
2018-07-17 13:12:03 +02:00
# setup state signals, that no wallet has been created yet
2018-08-09 11:54:15 +02:00
dialog --backtitle "RaspiBlitz - LND Lightning Wallet (${network}/${chain})" --msgbox "
2018-07-29 01:33:54 +02:00
${network} and Lighthing Services are installed.
2018-07-17 13:12:03 +02:00
You now need to setup your Lightning Wallet:
We will now call the command: lncli create
lncli = Lightning Network Command Line Interface
Learn more: https://api.lightning.community
Press OK and follow the 'Helping Instructions'.
" 14 52
clear
echo "****************************************************************************"
echo "Helping Instructions --> for creating a new LND Wallet"
echo "****************************************************************************"
echo "A) For 'Wallet Password' use your PASSWORD C --> !! minimum 8 characters !!"
echo "B) Answere 'n' because you dont have a 'cipher seed mnemonic' (24 words) yet"
echo "C) For 'passphrase' to encrypt your 'cipher seed' use PASSWORD D (optional)"
echo "****************************************************************************"
echo ""
echo "lncli create"
2018-08-09 10:48:51 +02:00
# execute command and monitor error
_error="./.error.out"
2018-08-21 04:17:08 +02:00
sudo -u bitcoin /usr/local/bin/lncli create 2>$_error
2018-08-09 10:48:51 +02:00
error=`cat ${_error}`
if [ ${#error} -gt 0 ]; then
echo ""
echo "!!! FAIL !!! SOMETHING WENT WRONG:"
echo "${error}"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
echo "Press ENTER to retry ... or CTRL-c to EXIT"
read key
2018-08-09 11:34:37 +02:00
echo "Starting RETRY ..."
2018-08-09 10:48:51 +02:00
./70initLND.sh
exit 1
fi
2018-07-17 13:12:03 +02:00
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!! Make sure to write down the 24 words (cipher seed mnemonic) !!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "If you are ready. Press ENTER."
read key
# set SetupState to 75 (mid thru this process)
echo "65" > /home/admin/.setup
fi
2018-08-08 17:36:04 +02:00
2018-08-07 16:28:15 +02:00
echo "--> lets wait 60 seconds for LND to get ready"
sleep 60
2018-07-17 13:12:03 +02:00
###### Copy LND macaroons to admin
echo ""
echo "*** Copy LND Macaroons to user admin ***"
2018-08-07 16:28:15 +02:00
macaroonExists=$(sudo -u bitcoin ls -la /home/bitcoin/.lnd/admin.macaroon | grep -c admin.macaroon)
2018-08-09 12:04:31 +02:00
if [ ${macaroonExists} -eq 0 ]; then
2018-08-09 12:08:28 +02:00
./AAunlockLND.sh
2018-08-09 12:04:31 +02:00
sleep 3
fi
macaroonExists=$(sudo -u bitcoin ls -la /home/bitcoin/.lnd/admin.macaroon | grep -c admin.macaroon)
2018-07-17 13:12:03 +02:00
if [ ${macaroonExists} -eq 0 ]; then
2018-08-07 16:28:15 +02:00
sudo -u bitcoin ls -la /home/bitcoin/.lnd/admin.macaroon
2018-07-17 13:12:03 +02:00
echo ""
echo "FAIL - LND Macaroons not created"
echo "Please check the following LND issue:"
echo "https://github.com/lightningnetwork/lnd/issues/890"
2018-08-07 16:28:15 +02:00
echo "You may want try again with starting ./70initLND.sh"
2018-07-17 13:12:03 +02:00
exit 1
fi
2018-08-09 13:04:23 +02:00
sudo mkdir /home/admin/.lnd 2>/dev/null
2018-07-17 13:12:03 +02:00
macaroonExists=$(sudo ls -la /home/admin/.lnd/ | grep -c admin.macaroon)
if [ ${macaroonExists} -eq 0 ]; then
sudo mkdir /home/admin/.lnd
sudo cp /home/bitcoin/.lnd/tls.cert /home/admin/.lnd
sudo cp /home/bitcoin/.lnd/admin.macaroon /home/admin/.lnd
sudo chown -R admin:admin /home/admin/.lnd/
echo "OK - LND Macaroons created"
else
echo "OK - Macaroons are already copied"
fi
###### Unlock Wallet (if needed)
echo "*** Check Wallet Lock ***"
2018-07-29 01:33:54 +02:00
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
2018-07-17 13:12:03 +02:00
if [ ${locked} -gt 0 ]; then
echo "OK - Wallet is locked ... starting unlocking dialog"
2018-08-09 12:08:28 +02:00
./AAunlockLND.sh
2018-07-17 13:12:03 +02:00
else
echo "OK - Wallet is already unlocked"
fi
### Show Lighthning Sync
echo ""
echo "*** Check LND Sync ***"
item=0
2018-08-24 00:11:33 +02:00
lndSyncing=$(sudo -u bitcoin /usr/local/bin/lncli getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
2018-07-17 13:12:03 +02:00
if [ ${lndSyncing} -eq 0 ]; then
echo "OK - wait for LND to be synced"
while :
do
2018-07-31 21:43:57 +02:00
2018-07-17 13:12:03 +02:00
# show sync status
./80scanLND.sh
2018-08-24 00:54:10 +02:00
sleep 15
2018-07-31 21:43:57 +02:00
2018-07-17 13:12:03 +02:00
# break loop when synced
2018-08-24 00:11:33 +02:00
lndSyncing=$(sudo -u bitcoin /usr/local/bin/lncli getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
2018-07-17 13:12:03 +02:00
if [ ${lndSyncing} -eq 1 ]; then
break
fi
2018-07-31 21:43:57 +02:00
# break loop when wallet is locked
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -eq 1 ]; then
break
fi
2018-08-24 00:54:10 +02:00
sleep 15
2018-07-17 13:12:03 +02:00
done
clear
else
echo "OK - LND is in sync"
fi
# set SetupState (scan is done - so its 80%)
echo "80" > /home/admin/.setup
2018-07-25 17:40:50 +02:00
###### finishSetup
2018-07-17 13:12:03 +02:00
./90finishSetup.sh