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

111 lines
2.8 KiB
Bash
Raw Normal View History

2018-12-22 15:35:27 +01:00
#!/bin/bash
# requests missing in dietpi
sudo pip install requests 2>/dev/null
2018-12-22 15:35:27 +01:00
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# small config script to autounlock lnd after restart"
echo "# lnd.autounlock.sh [on|off] [?passwordC]"
2018-12-22 15:35:27 +01:00
exit 1
fi
# 1. parameter [on|off]
turn="off"
if [ "$1" = "1" ] || [ "$1" = "on" ]; then turn="on"; fi
# 2. parameter [?passwordC]
passwordC=$2
# run interactive if 'turn on' && no further parameters
if [ "${turn}" = "on" ] && [ ${#passwordC} -eq 0 ]; then
dialog --backtitle "LND Auto-Unlock" --inputbox "ENTER your PASSWORD C:
For more details see chapter in GitHub README
'Auto-unlock LND on startup'
https://github.com/rootzoll/raspiblitz
Password C will be stored on the device.
" 13 52 2>./.tmp
2020-01-06 22:21:47 +01:00
wasCancel=$( echo $? )
2018-12-22 15:35:27 +01:00
passwordC=$( cat ./.tmp )
2018-12-24 01:21:05 +01:00
2020-01-06 22:21:47 +01:00
if [ ${wasCancel} -eq 1 ]; then
echo "# CANCEL LND Auto-Unlock"
sleep 2
exit 1
fi
2018-12-22 15:35:27 +01:00
if [ ${#passwordC} -eq 0 ]; then
2020-01-06 22:16:58 +01:00
echo "# input cannot be empty - repeat"
2018-12-24 01:21:05 +01:00
sleep 3
2020-01-06 22:16:58 +01:00
sudo /home/admin/config.scripts/lnd.autounlock.sh on
exit 1
fi
2019-04-25 12:03:18 +02:00
2018-12-24 01:21:05 +01:00
# test if correct
echo "# testing password .. please wait"
2019-04-25 12:03:18 +02:00
echo "SYSTEMD RESTART LOG: lightning (LND)" > /home/admin/systemd.lightning.log
2018-12-24 01:21:05 +01:00
sudo systemctl restart lnd
sleep 4
2020-05-28 01:52:05 +02:00
error=""
2020-05-28 03:07:43 +02:00
source <(sudo /home/admin/config.scripts/lnd.unlock.sh "$passwordC")
2020-05-28 01:52:05 +02:00
if [ ${error} -gt 0 ];then
echo "# PASSWORD C is wrong - try again or cancel"
2018-12-24 01:21:05 +01:00
sleep 3
sudo /home/admin/config.scripts/lnd.autounlock.sh on
2018-12-22 15:35:27 +01:00
exit 1
fi
shred -u ./.tmp
2018-12-22 15:45:45 +01:00
fi
2018-12-22 15:35:27 +01:00
# config file
configFile="/mnt/hdd/raspiblitz.conf"
# lnd conf file
lndConfig="/mnt/hdd/lnd/lnd.conf"
# check if config file exists
configExists=$(ls ${configFile} | grep -c '.conf')
if [ ${configExists} -eq 0 ]; then
echo "err='missing ${configFile}''"
2018-12-22 15:35:27 +01:00
exit 1
fi
2018-12-22 16:44:15 +01:00
# make sure entry line for 'autoUnlock' exists
entryExists=$(cat ${configFile} | grep -c 'autoUnlock=')
2018-12-22 15:35:27 +01:00
if [ ${entryExists} -eq 0 ]; then
2018-12-22 16:44:15 +01:00
echo "autoUnlock=" >> ${configFile}
2018-12-22 15:35:27 +01:00
fi
# switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
2018-12-22 16:44:15 +01:00
echo "# switching the Auto-Unlock ON"
2018-12-22 15:35:27 +01:00
# setting value in raspi blitz config
2018-12-22 16:44:15 +01:00
sudo sed -i "s/^autoUnlock=.*/autoUnlock=on/g" /mnt/hdd/raspiblitz.conf
2018-12-22 15:35:27 +01:00
# password C needs to be stored on RaspiBlitz
echo "# storing password for root in /root/lnd.autounlock.pwd"
2018-12-22 16:44:15 +01:00
sudo sh -c "echo \"${passwordC}\" > /root/lnd.autounlock.pwd"
2018-12-22 15:35:27 +01:00
echo "# Auto-Unlock is now ON"
echo "# NOTE: you may need to reconnect mobile/external wallets (macaroon/tls)"
2018-12-22 15:35:27 +01:00
fi
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
echo "# switching the Auto-Unlock OFF"
2018-12-22 15:35:27 +01:00
# setting value in raspi blitz config
2018-12-22 16:44:15 +01:00
sudo sed -i "s/^autoUnlock=.*/autoUnlock=off/g" /mnt/hdd/raspiblitz.conf
2018-12-22 15:35:27 +01:00
# delete password C securly
echo "# shredding password on for RaspiBlitz Auto-Unlock"
2019-01-14 16:54:40 +01:00
sudo shred -u /root/lnd.autounlock.pwd 2>/dev/null
2018-12-22 15:35:27 +01:00
echo "# Auto-Unlock is now OFF"
2020-05-23 19:19:41 +01:00
fi