2021-05-23 23:38:12 -05:00
#!/bin/bash
2021-12-14 23:34:35 +01:00
# check if started with sudo
if [ " $EUID " -ne 0 ] ; then
echo "error='run as root'"
exit 1
fi
2021-07-15 21:08:14 +02:00
# this provision file is just executed on fresh setups
# not on recoveries or updates
2021-05-23 23:38:12 -05:00
# LOGFILE - store debug logs of bootstrap
2021-09-09 01:19:09 +02:00
logFile = "/home/admin/raspiblitz.provision-setup.log"
2021-05-23 23:38:12 -05:00
# INFOFILE - state data from bootstrap
infoFile = "/home/admin/raspiblitz.info"
source ${ infoFile }
# SETUPFILE - setup data of RaspiBlitz
setupFile = "/var/cache/raspiblitz/temp/raspiblitz.setup"
source ${ setupFile }
# CONFIGFILE - configuration of RaspiBlitz
configFile = "/mnt/hdd/raspiblitz.conf"
source ${ configFile }
2021-05-24 13:09:51 -05:00
# log header
2021-09-09 00:12:46 +02:00
echo "" > ${ logFile }
2022-01-13 19:44:13 +01:00
chmod 640 ${ logFile }
2022-01-16 22:07:17 +01:00
chown root:sudo ${ logFile }
2021-05-24 13:09:51 -05:00
echo "###################################" >> ${ logFile }
echo "# _provision.setup.sh" >> ${ logFile }
echo "###################################" >> ${ logFile }
2021-05-23 23:38:12 -05:00
2022-01-25 12:07:11 +01:00
# make sure a raspiblitz.conf exists
confExists = $( ls /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "raspiblitz.conf" )
if [ " ${ confExists } " != "1" ] ; then
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-config" "No raspiblitz.conf abvailable." ${ logFile }
exit 6
fi
2021-05-23 23:38:12 -05:00
###################################
# Preserve SSH keys
# just copy dont link anymore
# see: https://github.com/rootzoll/raspiblitz/issues/1798
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "SSH Keys"
2021-05-23 23:38:12 -05:00
# link ssh directory from SD card to HDD
2021-09-30 18:24:22 +02:00
/home/admin/config.scripts/blitz.ssh.sh backup
2021-05-23 23:38:12 -05:00
###################################
# Prepare Blockchain Service
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "Blockchain Setup"
source <( /home/admin/_cache.sh get network chain hddBlocksBitcoin)
2021-05-23 23:38:12 -05:00
if [ " ${ network } " = = "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-network" "" "" ${ logFile }
exit 2
2021-05-23 23:38:12 -05:00
fi
if [ " ${ chain } " = = "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-chain" "" "" ${ logFile }
exit 3
2021-05-23 23:38:12 -05:00
fi
# copy configs files and directories
echo ""
echo " *** Prepare ${ network } *** " >> ${ logFile }
2021-09-30 18:24:22 +02:00
mkdir /mnt/hdd/${ network } >>${ logFile } 2>& 1
chown -R bitcoin:bitcoin /mnt/hdd/${ network } >>${ logFile } 2>& 1
2021-09-05 13:05:35 +02:00
sudo -u bitcoin mkdir /mnt/hdd/${ network } /blocks >>${ logFile } 2>& 1
sudo -u bitcoin mkdir /mnt/hdd/${ network } /chainstate >>${ logFile } 2>& 1
2021-09-30 18:24:22 +02:00
cp /home/admin/assets/${ network } .conf /mnt/hdd/${ network } /${ network } .conf
chown bitcoin:bitcoin /mnt/hdd/${ network } /${ network } .conf >>${ logFile } 2>& 1
mkdir /home/admin/.${ network } >>${ logFile } 2>& 1
cp /home/admin/assets/${ network } .conf /home/admin/.${ network } /${ network } .conf
chown -R admin:admin /home/admin/.${ network } >>${ logFile } 2>& 1
2021-09-05 13:51:39 +02:00
# make sure all directories are linked
2021-09-30 18:24:22 +02:00
/home/admin/config.scripts/blitz.datadrive.sh link >> ${ logFile }
2021-09-05 13:51:39 +02:00
# test bitcoin config
2021-12-19 16:27:27 +00:00
confExists = $( ls /mnt/hdd/${ network } /${ network } .conf | grep -c " ${ network } .conf " )
2021-09-05 13:05:35 +02:00
echo " File Exists: /mnt/hdd/ ${ network } / ${ network } .conf --> ${ confExists } " >> ${ logFile }
2021-05-23 23:38:12 -05:00
2021-12-14 23:34:35 +01:00
# set password B as RPC password (from setup file)
2021-09-30 20:37:00 +02:00
echo "# setting PASSWORD B" >> ${ logFile }
2022-05-05 10:59:50 +02:00
/home/admin/config.scripts/blitz.passwords.sh set b " ${ passwordB } " >> ${ logFile }
2021-05-26 11:07:35 -05:00
2021-05-23 23:38:12 -05:00
# optimize RAM for blockchain validation (bitcoin only)
2022-01-25 12:07:11 +01:00
if [ " ${ network } " = = "bitcoin" ] ; then
2021-05-23 23:38:12 -05:00
echo "*** Optimizing RAM for Sync ***" >> ${ logFile }
kbSizeRAM = $( cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g' )
2021-09-30 20:37:00 +02:00
echo " kbSizeRAM( ${ kbSizeRAM } ) " >> ${ logFile }
2021-05-23 23:38:12 -05:00
echo "dont forget to reduce dbcache once IBD is done" > " /mnt/hdd/ ${ network } /blocks/selfsync.flag "
# RP4 4GB
if [ ${ kbSizeRAM } -gt 3500000 ] ; then
echo " Detected RAM >=4GB --> optimizing ${ network } .conf " >> ${ logFile }
2021-09-30 18:24:22 +02:00
sed -i "s/^dbcache=.*/dbcache=2560/g" /mnt/hdd/${ network } /${ network } .conf
2021-05-23 23:38:12 -05:00
# RP4 2GB
elif [ ${ kbSizeRAM } -gt 1500000 ] ; then
echo " Detected RAM >=2GB --> optimizing ${ network } .conf " >> ${ logFile }
2021-09-30 18:24:22 +02:00
sed -i "s/^dbcache=.*/dbcache=1536/g" /mnt/hdd/${ network } /${ network } .conf
2021-05-23 23:38:12 -05:00
#RP3/4 1GB
else
echo " Detected RAM <=1GB --> optimizing ${ network } .conf " >> ${ logFile }
2021-09-30 18:24:22 +02:00
sed -i "s/^dbcache=.*/dbcache=512/g" /mnt/hdd/${ network } /${ network } .conf
2021-05-23 23:38:12 -05:00
fi
fi
# start network service
echo ""
2021-09-05 13:05:35 +02:00
echo " *** Start ${ network } (SETUP) *** " >> ${ logFile }
2022-02-19 19:49:13 +01:00
/home/admin/_cache.sh set message "Blockchain Testrun"
2021-05-23 23:38:12 -05:00
echo "- This can take a while .." >> ${ logFile }
2021-09-30 18:24:22 +02:00
cp /home/admin/assets/${ network } d.service /etc/systemd/system/${ network } d.service
systemctl enable ${ network } d.service
systemctl start ${ network } d.service
2021-05-23 23:38:12 -05:00
# check if bitcoin has started
bitcoinRunning = 0
loopcount = 0
while [ ${ bitcoinRunning } -eq 0 ]
do
2021-09-30 18:24:22 +02:00
>& 2 echo " # ( ${ loopcount } /50) checking if ${ network } d is running ... " >> ${ logFile }
2021-05-25 14:12:26 -05:00
bitcoinRunning = $( sudo -u bitcoin ${ network } -cli getblockchaininfo 2>/dev/null | grep "initialblockdownload" -c)
2021-09-30 18:24:22 +02:00
sleep 8
2021-05-23 23:38:12 -05:00
sync
loopcount = $(( $loopcount + 1 ))
2021-09-30 18:24:22 +02:00
if [ ${ loopcount } -gt 50 ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "btc-testrun-fail" " ${ network } d not running " " sudo -u bitcoin ${ network } -cli getblockchaininfo | grep " initialblockdownload" -c --> ${ bitcoinRunning } " ${ logFile }
2021-09-09 00:08:15 +02:00
exit 4
2021-05-23 23:38:12 -05:00
fi
done
2021-07-18 11:03:06 +01:00
echo " OK ${ network } startup successful " >> ${ logFile }
2021-05-23 23:38:12 -05:00
###################################
# Prepare Lightning
2021-12-14 23:34:35 +01:00
source /mnt/hdd/raspiblitz.conf
2021-05-25 14:46:20 -05:00
echo " Prepare Lightning ( ${ lightning } ) " >> ${ logFile }
2021-05-23 23:38:12 -05:00
2021-12-14 23:34:35 +01:00
if [ " ${ hostname } " = = "" ] ; then
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-hostname" "" "" ${ logFile }
exit 41
fi
2021-07-16 21:50:26 +02:00
if [ " ${ lightning } " != "lnd" ] ; then
2021-07-15 21:08:14 +02:00
###################################
2021-07-16 20:16:39 +02:00
# Remove LND from systemd
2021-07-16 21:50:26 +02:00
echo "Remove LND" >> ${ logFile }
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "Deactivate Lightning"
2022-01-13 19:44:13 +01:00
systemctl disable lnd 2>/dev/null
2021-12-19 16:27:27 +00:00
rm /etc/systemd/system/lnd.service 2>/dev/null
systemctl daemon-reload
2021-07-15 22:05:53 +02:00
fi
2021-07-15 21:08:14 +02:00
2021-05-23 23:38:12 -05:00
if [ " ${ lightning } " = = "lnd" ] ; then
###################################
# LND
2021-07-16 21:50:26 +02:00
echo "############## Setup LND" >> ${ logFile }
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "LND Setup"
2021-05-23 23:38:12 -05:00
2021-12-14 23:34:35 +01:00
# password C (raspiblitz.setup)
2021-12-20 20:16:09 +00:00
if [ " ${ passwordC } " = = "" ] && [ " ${ lndrescue } " = "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-passwordc" "config: missing passwordC" "" ${ logFile }
2021-09-09 00:08:15 +02:00
exit 5
2021-05-23 23:38:12 -05:00
fi
2022-01-13 19:44:13 +01:00
# install lnd if needed (sd card without fatpack)
# if already installed - it will just skip
/home/admin/config.scripts/lnd.install.sh install >> ${ logFile }
2021-12-14 23:34:35 +01:00
# if user uploaded an LND rescue file (raspiblitz.setup)
2021-05-23 23:38:12 -05:00
if [ " ${ lndrescue } " != "" ] ; then
echo " Restore LND data from uploaded rescue file ${ lndrescue } ... " >> ${ logFile }
2022-01-04 19:08:38 +00:00
source <( /home/admin/config.scripts/lnd.backup.sh lnd-import " ${ lndrescue } " )
2021-05-23 23:38:12 -05:00
if [ " ${ error } " != "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lndrescue-import" "setup: lnd import backup failed" " ${ error } " ${ logFile }
2021-09-09 00:08:15 +02:00
exit 6
2021-05-23 23:38:12 -05:00
fi
2021-12-21 07:54:51 +00:00
# fix config after import
/home/admin/config.scripts/lnd.install.sh on mainnet
2021-05-23 23:38:12 -05:00
else
2021-12-14 23:34:35 +01:00
# preparing new LND config (raspiblitz.setup)
2021-05-23 23:38:12 -05:00
echo "Creating new LND config ..." >> ${ logFile }
sudo -u bitcoin mkdir /mnt/hdd/lnd 2> /dev/null
2021-12-19 16:27:27 +00:00
cp /home/admin/assets/lnd.bitcoin.conf /mnt/hdd/lnd/lnd.conf
chown bitcoin:bitcoin /mnt/hdd/lnd/lnd.conf
/home/admin/config.scripts/lnd.install.sh on mainnet
/home/admin/config.scripts/lnd.setname.sh mainnet ${ hostname }
2021-05-23 23:38:12 -05:00
fi
2021-09-05 13:51:39 +02:00
# make sure all directories are linked
2021-12-19 16:27:27 +00:00
/home/admin/config.scripts/blitz.datadrive.sh link
2021-09-05 13:51:39 +02:00
2021-05-23 23:38:12 -05:00
# check if now a config exists
2021-12-19 16:27:27 +00:00
configLinkedCorrectly = $( ls /home/bitcoin/.lnd/lnd.conf | grep -c "lnd.conf" )
2021-05-23 23:38:12 -05:00
if [ " ${ configLinkedCorrectly } " != "1" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-link-broken" "link /home/bitcoin/.lnd/lnd.conf broken" "" ${ logFile }
2021-09-09 00:08:15 +02:00
exit 7
2021-05-23 23:38:12 -05:00
fi
# Init LND service & start
echo "*** Init LND Service & Start ***" >> ${ logFile }
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "LND Testrun"
2021-05-23 23:38:12 -05:00
# just in case
2021-12-19 16:27:27 +00:00
systemctl stop lnd 2>/dev/null
systemctl disable lnd 2>/dev/null
2021-05-23 23:38:12 -05:00
2021-12-09 14:08:04 +01:00
# copy lnd service
2021-12-19 16:27:27 +00:00
cp /home/admin/assets/lnd.service /etc/systemd/system/lnd.service >> ${ logFile }
2021-05-26 10:47:35 -05:00
2021-05-23 23:38:12 -05:00
# start lnd up
echo "Starting LND Service ..." >> ${ logFile }
2021-12-19 16:27:27 +00:00
systemctl enable lnd >> ${ logFile }
systemctl start lnd >> ${ logFile }
2021-12-14 23:34:35 +01:00
echo "Starting LND Service ... executed" >> ${ logFile }
2021-05-23 23:38:12 -05:00
# check that lnd started
lndRunning = 0
loopcount = 0
while [ ${ lndRunning } -eq 0 ]
do
2021-12-14 23:34:35 +01:00
lndRunning = $( systemctl status lnd.service | grep -c running)
2021-05-23 23:38:12 -05:00
if [ ${ lndRunning } -eq 0 ] ; then
date +%s >> ${ logFile }
echo "LND not ready yet ... waiting another 60 seconds." >> ${ logFile }
sleep 10
fi
loopcount = $(( $loopcount + 1 ))
if [ ${ loopcount } -gt 100 ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-start-fail" "lnd service not getting to running status" " sudo systemctl status lnd.service | grep -c running --> ${ lndRunning } " ${ logFile }
2021-09-09 00:08:15 +02:00
exit 8
2021-05-23 23:38:12 -05:00
fi
done
echo "OK - LND is running" ${ logFile }
sleep 10
# Check LND health/fails (to be extended)
2021-12-14 23:34:35 +01:00
tlsExists = $( ls /mnt/hdd/lnd/tls.cert 2>/dev/null | grep -c "tls.cert" )
2021-05-23 23:38:12 -05:00
if [ ${ tlsExists } -eq 0 ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-no-tls" "lnd not created TLS cert" "no /mnt/hdd/lnd/tls.cert" ${ logFile }
2021-09-09 00:08:15 +02:00
exit 9
2021-05-23 23:38:12 -05:00
fi
2021-12-20 23:16:50 +00:00
# WALLET --> LNDRESCUE
if [ " ${ lndrescue } " != "" ] ; then
echo "WALLET --> LNDRESCUE " >> ${ logFile }
/home/admin/_cache.sh set message "LND Wallet (LNDRESCUE)"
2022-01-04 19:08:38 +00:00
# WALLET --> SEED (+ SCB to be restored later)
2021-05-25 14:46:20 -05:00
elif [ " ${ seedWords } " != "" ] ; then
2021-05-23 23:38:12 -05:00
2021-12-14 23:34:35 +01:00
echo "WALLET --> SEED" >> ${ logFile }
/home/admin/_cache.sh set message "LND Wallet (SEED)"
2021-11-30 11:58:06 +00:00
if ! pip list | grep grpc; then sudo -H python3 -m pip install grpcio = = 1.38.1; fi
2022-01-04 19:08:38 +00:00
source <( /home/admin/config.scripts/lnd.initwallet.py seed mainnet " ${ passwordC } " " ${ seedWords } " " ${ seedPassword } " )
2021-05-23 23:38:12 -05:00
if [ " ${ err } " != "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-wallet-seed" "lnd.initwallet.py seed returned error" " /home/admin/config.scripts/lnd.initwallet.py seed mainnet ... --> ${ err } + ${ errMore } " ${ logFile }
2021-09-09 00:08:15 +02:00
exit 12
2021-05-23 23:38:12 -05:00
fi
2022-01-04 19:08:38 +00:00
2022-01-25 12:07:11 +01:00
# set lnd into recovery mode (gets activated after setup reboot)
/home/admin/config.scripts/lnd.backup.sh mainnet recoverymode on >> ${ logFile }
echo "Rescanning will activate after setup-reboot ..." >> ${ logFile }
2022-01-04 19:08:38 +00:00
2021-05-23 23:38:12 -05:00
# WALLET --> NEW
else
2022-06-05 23:00:32 +02:00
echo "# WALLET --> NEW" >> ${ logFile }
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "LND Wallet (NEW)"
if ! pip list | grep grpc; then sudo -H python3 -m pip install grpcio = = 1.38.1; fi
2022-01-04 19:08:38 +00:00
source <( /home/admin/config.scripts/lnd.initwallet.py new mainnet " ${ passwordC } " )
2021-05-23 23:38:12 -05:00
if [ " ${ err } " != "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-wallet-new" "lnd.initwallet.py new returned error" " /home/admin/config.scripts/lnd.initwallet.py new mainnet ... --> ${ err } + ${ errMore } " ${ logFile }
/home/admin/_cache.sh set state "error"
/home/admin/_cache.sh set message "setup: lnd wallet NEW failed"
2021-05-23 23:38:12 -05:00
echo " FAIL see ${ logFile } "
2021-12-14 23:34:35 +01:00
echo "FAIL: setup: lnd wallet SEED failed (2)" >> ${ logFile }
2021-05-23 23:38:12 -05:00
echo " ${ err } " >> ${ logFile }
echo " ${ errMore } " >> ${ logFile }
2021-09-09 00:08:15 +02:00
exit 13
2021-05-23 23:38:12 -05:00
fi
# write created seedwords into SETUPFILE to be displayed to user on final setup later
2022-06-05 23:00:32 +02:00
echo "# writing seed info to setup file" >> ${ logFile }
2021-05-25 18:08:45 -05:00
echo " seedwordsNEW=' ${ seedwords } ' " >> ${ setupFile }
2021-05-25 16:08:48 -05:00
echo " seedwords6x4NEW=' ${ seedwords6x4 } ' " >> ${ setupFile }
2021-05-23 23:38:12 -05:00
fi
# sync macaroons & TLS to other users
echo "*** Copy LND Macaroons to user admin ***" >> ${ logFile }
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "LND Credentials"
2021-05-23 23:38:12 -05:00
# check if macaroon exists now - if not fail
2022-01-04 19:08:38 +00:00
attempt = 0
while [ $( sudo -u bitcoin ls -la /home/bitcoin/.lnd/data/chain/${ network } /${ chain } net/admin.macaroon 2>/dev/null | grep -c admin.macaroon) -eq 0 ] ; do
echo " Waiting 2 mins for LND to create macaroons ... ( ${ attempt } 0s) " >> ${ logFile }
sleep 10
attempt = $(( attempt+1))
if [ $attempt -eq 12 ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-no-macaroons" "lnd did not create macaroons" " /home/bitcoin/.lnd/data/chain/ ${ network } / ${ chain } net/admin.macaroon --> missing " ${ logFile }
2021-09-09 00:08:15 +02:00
exit 14
2022-01-04 19:08:38 +00:00
fi
done
2021-05-23 23:38:12 -05:00
2021-12-20 23:16:50 +00:00
# now sync macaroons & TLS to other users
2021-12-19 16:27:27 +00:00
/home/admin/config.scripts/lnd.credentials.sh sync >> ${ logFile }
2021-05-23 23:38:12 -05:00
# make a final lnd check
source <( /home/admin/config.scripts/lnd.check.sh basic-setup)
if [ " ${ err } " != "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-check-error" "lnd.check.sh basic-setup with error" " /home/admin/config.scripts/lnd.check.sh basic-setup --> ${ err } " ${ logFile }
2021-09-09 00:08:15 +02:00
exit 15
2021-05-23 23:38:12 -05:00
fi
2021-11-30 20:08:10 +01:00
# stop lnd for the rest of the provision process
echo "stopping lnd for the rest provision again (will start on next boot)" >> ${ logFile }
systemctl stop lnd >> ${ logFile }
2021-05-23 23:38:12 -05:00
fi
2021-09-26 10:30:09 +01:00
if [ " ${ lightning } " = = "cl" ] ; then
2021-05-23 23:38:12 -05:00
###################################
# c-lightning
2021-07-17 00:54:31 +02:00
echo "############## c-lightning" >> ${ logFile }
2022-01-13 19:44:13 +01:00
# install c-lightning (when not done by sd card fatpack)
# if already installed - will skip
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "C-Lightning Install"
2022-01-13 19:44:13 +01:00
/home/admin/config.scripts/cl.install.sh install >> ${ logFile }
# switch mainnet config on
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "C-Lightning Setup"
2022-01-13 19:44:13 +01:00
/home/admin/config.scripts/cl.install.sh on mainnet >> ${ logFile }
2021-05-23 23:38:12 -05:00
2022-06-05 23:00:32 +02:00
# switch cln-grpc on
2022-06-15 09:04:01 +02:00
/home/admin/config.scripts/cl-plugin.cln-grpc.sh install >> ${ logFile }
2022-06-05 23:00:32 +02:00
/home/admin/config.scripts/cl-plugin.cln-grpc.sh on >> ${ logFile }
2021-07-17 00:54:31 +02:00
# OLD WALLET FROM CLIGHTNING RESCUE
2021-09-26 10:30:09 +01:00
if [ " ${ clrescue } " != "" ] ; then
2021-07-17 00:54:31 +02:00
2021-09-26 10:30:09 +01:00
echo " Restore CL data from uploaded rescue file ${ clrescue } ... " >> ${ logFile }
2022-01-04 19:08:38 +00:00
source <( /home/admin/config.scripts/cl.backup.sh cl-import " ${ clrescue } " )
2021-07-17 16:18:34 +02:00
if [ " ${ error } " != "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "cl-import-backup" "cl.backup.sh cl-import with error" " /home/admin/config.scripts/cl.backup.sh cl-import ${ clrescue } --> ${ error } " ${ logFile }
2021-09-09 00:08:15 +02:00
exit 16
2021-07-17 16:18:34 +02:00
fi
2021-07-17 00:54:31 +02:00
2021-12-19 16:27:27 +00:00
# detect if the imported hsm_secret is encrypted and set in raspiblitz.conf
# use the variables for the default network
source <( /home/admin/config.scripts/network.aliases.sh getvars cl mainnet)
hsmSecretPath = "/home/bitcoin/.lightning/bitcoin/hsm_secret"
# check if encrypted
trap 'rm -f "$output"' EXIT
output = $( mktemp -p /dev/shm/)
echo "test" | sudo -u bitcoin lightning-hsmtool decrypt " $hsmSecretPath " \
2> " $output "
if [ " $( grep -c "hsm_secret is not encrypted" < " $output " ) " -gt 0 ] ; then
echo "# The hsm_secret is not encrypted"
echo "# Record in raspiblitz.conf"
2022-01-04 19:08:38 +00:00
/home/admin/config.scripts/blitz.conf.sh set " ${ netprefix } clEncryptedHSM " "off"
2021-12-19 16:27:27 +00:00
else
cat $output
echo "# The hsm_secret is encrypted"
echo "# Record in raspiblitz.conf"
2022-01-04 19:08:38 +00:00
/home/admin/config.scripts/blitz.conf.sh set " ${ netprefix } clEncryptedHSM " "off"
2021-12-19 16:27:27 +00:00
fi
2022-02-09 16:04:24 +00:00
# update from raspiblitz.conf
source ${ configFile }
2021-12-19 16:27:27 +00:00
# set the lightningd service file on each active network
# init backup plugin, restart cl
if [ " ${ cl } " = = "on" ] || [ " ${ cl } " = = "1" ] ; then
/home/admin/config.scripts/cl.install-service.sh mainnet
/home/admin/config.scripts/cl-plugin.backup.sh on mainnet
fi
if [ " ${ tcl } " = = "on" ] || [ " ${ tcl } " = = "1" ] ; then
/home/admin/config.scripts/cl.install-service.sh testnet
/home/admin/config.scripts/cl-plugin.backup.sh on testnet
fi
if [ " ${ scl } " = = "on" ] || [ " ${ scl } " = = "1" ] ; then
/home/admin/config.scripts/cl.install-service.sh signet
/home/admin/config.scripts/cl-plugin.backup.sh on signet
fi
2021-07-17 00:54:31 +02:00
# OLD WALLET FROM SEEDWORDS
2021-07-17 16:55:34 +02:00
elif [ " ${ seedWords } " != "" ] ; then
2021-07-17 00:54:31 +02:00
2022-06-05 23:00:32 +02:00
echo "# Restore CL wallet from seedWords ..." >> ${ logFile }
2021-12-14 23:34:35 +01:00
source <( /home/admin/config.scripts/cl.hsmtool.sh seed-force mainnet " ${ seedWords } " " ${ seedPassword } " )
2021-07-17 00:54:31 +02:00
2021-07-17 01:55:02 +02:00
# check if wallet really got created
2021-12-14 23:34:35 +01:00
walletExistsNow = $( ls /home/bitcoin/.lightning/bitcoin/hsm_secret 2>/dev/null | grep -c "hsm_secret" )
2021-07-17 01:55:02 +02:00
if [ $walletExistsNow -eq 0 ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "cl-wallet-seed" "cl.hsmtool.sh seed-force not created wallet" "ls /home/bitcoin/.lightning/bitcoin/hsm_secret --> 0" ${ logFile }
2021-09-09 00:08:15 +02:00
exit 17
2021-07-17 01:55:02 +02:00
fi
2021-07-17 00:54:31 +02:00
# NEW WALLET
else
2022-06-05 23:00:32 +02:00
echo "# Generate new CL wallet ..." >> ${ logFile }
2021-07-20 18:26:17 +02:00
2021-12-19 16:27:27 +00:00
# a new wallet is generated in /home/admin/config.scripts/cl.install.sh on mainnet
walletExistsNow = $( ls /home/bitcoin/.lightning/bitcoin/hsm_secret 2>/dev/null | grep -c "hsm_secret" )
seedwordsFileExitNow = $( ls /home/bitcoin/.lightning/bitcoin/seedwords.info 2>/dev/null | grep -c "seedwords.info" )
if [ " ${ walletExistsNow } " -gt 0 ] && [ " ${ seedwordsFileExitNow } " -gt 0 ] ; then
# get existing ${seedwords} and "${seedwords6x4}"
source /home/bitcoin/.lightning/bitcoin/seedwords.info
else
# generate new wallet
source <( /home/admin/config.scripts/cl.hsmtool.sh new-force mainnet)
fi
2021-07-17 00:54:31 +02:00
# check if got new seedwords
if [ " ${ seedwords } " = = "" ] || [ " ${ seedwords6x4 } " = = "" ] ; then
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "cl-wallet-new-noseeds" "cl.hsmtool.sh new-force did not returned seedwords" "/home/admin/config.scripts/cl.hsmtool.sh new-force mainnet --> seedwords=''" ${ logFile }
2021-09-09 00:08:15 +02:00
exit 18
2021-07-17 00:54:31 +02:00
fi
2021-07-17 01:55:02 +02:00
# check if wallet really got created
2021-12-19 16:27:27 +00:00
walletExistsNow = $( ls /home/bitcoin/.lightning/bitcoin/hsm_secret 2>/dev/null | grep -c "hsm_secret" )
2021-07-17 01:55:02 +02:00
if [ $walletExistsNow -eq 0 ] ; then
2021-12-19 16:27:27 +00:00
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "cl-wallet-new-nowallet" "cl.hsmtool.sh new-force did not create wallet" "/home/bitcoin/.lightning/bitcoin/hsm_secret --> missing" ${ logFile }
2021-09-09 00:08:15 +02:00
exit 19
2021-07-17 01:55:02 +02:00
fi
2021-07-17 00:54:31 +02:00
# write created seedwords into SETUPFILE to be displayed to user on final setup later
2022-06-05 23:00:32 +02:00
echo "# writing seed info to setup file" >> ${ logFile }
2021-07-17 00:54:31 +02:00
echo " seedwordsNEW=' ${ seedwords } ' " >> ${ setupFile }
echo " seedwords6x4NEW=' ${ seedwords6x4 } ' " >> ${ setupFile }
fi
2021-07-15 21:08:14 +02:00
2021-11-30 20:08:10 +01:00
# stop c-lightning for the rest of the provision process
echo "stopping lightningd for the rest provision again (will start on next boot)" >> ${ logFile }
systemctl stop lightningd >> ${ logFile }
2021-05-23 23:38:12 -05:00
fi
2021-11-30 20:08:10 +01:00
# stop bitcoind for the rest of the provision process
echo "stopping bitcoind for the rest provision again (will start on next boot)" >> ${ logFile }
systemctl stop bitcoind >> ${ logFile }
2021-12-14 23:34:35 +01:00
/home/admin/_cache.sh set message "Provision Setup Finish"
2021-05-23 23:38:12 -05:00
echo "END Setup" >> ${ logFile }
2021-07-16 21:50:26 +02:00
exit 0