Christian Rotzoll
6 years ago
committed by
GitHub
17 changed files with 301 additions and 42 deletions
@ -0,0 +1,9 @@ |
|||
#!/bin/bash |
|||
|
|||
# SHORTCUT COMMANDS you can call as user 'admin' from terminal |
|||
|
|||
# command: raspiblitz |
|||
# calls the the raspiblitz mainmenu |
|||
function raspiblitz() { |
|||
/home/admin/00mainMenu.sh |
|||
} |
@ -1,2 +1,2 @@ |
|||
# RaspiBlitz Version - always [main].[sub] |
|||
codeVersion="0.98" |
|||
codeVersion="0.99" |
@ -0,0 +1,119 @@ |
|||
#!/bin/bash |
|||
|
|||
# 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]" |
|||
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 |
|||
passwordC=$( cat ./.tmp ) |
|||
|
|||
# test if empty |
|||
if [ ${#passwordC} -eq 0 ]; then |
|||
echo "CANCEL input cannot be empty" |
|||
sleep 3 |
|||
exit 1 |
|||
fi |
|||
|
|||
# test if correct |
|||
echo "testing password .. please wait" |
|||
sudo systemctl restart lnd |
|||
sleep 4 |
|||
result=$(sudo python /home/admin/config.scripts/lnd.unlock.py ${passwordC}) |
|||
invalid=$(echo "${result}" | grep -c 'invalid') |
|||
if [ ${invalid} -gt 0 ];then |
|||
echo "PASSWORD C is wrong - try again or cancel" |
|||
sleep 3 |
|||
sudo /home/admin/config.scripts/lnd.autounlock.sh on |
|||
exit 1 |
|||
fi |
|||
shred ./.tmp |
|||
fi |
|||
|
|||
# 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 "FAIL - missing ${configFile}" |
|||
exit 1 |
|||
fi |
|||
|
|||
# make sure entry line for 'autoUnlock' exists |
|||
entryExists=$(cat ${configFile} | grep -c 'autoUnlock=') |
|||
if [ ${entryExists} -eq 0 ]; then |
|||
echo "autoUnlock=" >> ${configFile} |
|||
fi |
|||
|
|||
# switch on |
|||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then |
|||
|
|||
# make sure config values are uncommented |
|||
sudo sed -i "s/^#restlisten=.*/restlisten=/g" /mnt/hdd/lnd/lnd.conf |
|||
sudo sed -i "s/^#tlsextraip=.*/tlsextraip=/g" /mnt/hdd/lnd/lnd.conf |
|||
|
|||
# make sure config values exits |
|||
exists=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep -c 'restlisten=') |
|||
if [ ${exists} -eq 0 ]; then |
|||
sudo sed -n -i 'p;4a restlisten=' /mnt/hdd/lnd/lnd.conf |
|||
fi |
|||
exists=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep -c 'tlsextraip') |
|||
if [ ${exists} -eq 0 ]; then |
|||
sudo sed -n -i 'p;5a tlsextraip=' /mnt/hdd/lnd/lnd.conf |
|||
fi |
|||
|
|||
# set needed config values |
|||
sudo sed -i "s/^restlisten=.*/restlisten=0.0.0.0:8080/g" /mnt/hdd/lnd/lnd.conf |
|||
sudo sed -i "s/^tlsextraip=.*/tlsextraip=0.0.0.0/g" /mnt/hdd/lnd/lnd.conf |
|||
|
|||
# refresh TLS cert |
|||
sudo /home/admin/config.scripts/lnd.newtlscert.sh |
|||
|
|||
echo "switching the Auto-Unlock ON" |
|||
|
|||
# setting value in raspi blitz config |
|||
sudo sed -i "s/^autoUnlock=.*/autoUnlock=on/g" /mnt/hdd/raspiblitz.conf |
|||
|
|||
# password C needs to be stored on RaspiBlitz |
|||
echo "storing password for root in /root/lnd.autounlock.pwd" |
|||
sudo sh -c "echo \"${passwordC}\" > /root/lnd.autounlock.pwd" |
|||
|
|||
echo "Auto-Unlock is now ON" |
|||
fi |
|||
|
|||
# switch off |
|||
if [ "$1" = "0" ] || [ "$1" = "off" ]; then |
|||
echo "switching the Auto-Unlock OFF" |
|||
|
|||
# setting value in raspi blitz config |
|||
sudo sed -i "s/^autoUnlock=.*/autoUnlock=off/g" /mnt/hdd/raspiblitz.conf |
|||
|
|||
# delete password C securly |
|||
echo "shredding password on RaspiBlitz" |
|||
sudo shred -u /root/lnd.autounlock.pwd |
|||
|
|||
echo "Auto-Unlock is now OFF" |
|||
fi |
@ -0,0 +1,29 @@ |
|||
|
|||
#!/bin/bash |
|||
|
|||
# stop services |
|||
echo "making sure services are not running" |
|||
sudo systemctl stop lnd 2>/dev/null |
|||
|
|||
echo "deleting TLSCert" |
|||
sudo rm /mnt/hdd/lnd/tls.* 2>/dev/null |
|||
echo "let lnd generate new TLSCert" |
|||
sudo -u bitcoin /usr/local/bin/lnd &>/dev/null & |
|||
echo "wait until generated" |
|||
newCertExists=0 |
|||
count=0 |
|||
while [ ${newCertExists} -eq 0 ] |
|||
do |
|||
count=$(($count + 1)) |
|||
echo "(${count}/60) check for cert" |
|||
if [ ${count} -gt 60 ]; then |
|||
echo "FAIL - was not able to generate new LND certs" |
|||
exit 1 |
|||
fi |
|||
newCertExists=$(sudo ls /mnt/hdd/lnd/tls.cert 2>/dev/null | grep -c '.cert') |
|||
sleep 2 |
|||
done |
|||
sudo killall /usr/local/bin/lnd |
|||
echo "copy new cert to admin user" |
|||
sudo cp /mnt/hdd/lnd/tls.cert /home/admin/.lnd |
|||
echo "OK TLS certs are fresh" |
@ -0,0 +1,9 @@ |
|||
# parameter #1: password c to unlock wallet |
|||
import base64, codecs, json, requests, sys |
|||
url = 'https://localhost:8080/v1/unlockwallet' |
|||
cert_path = '/mnt/hdd/lnd/tls.cert' |
|||
data = { |
|||
'wallet_password': base64.b64encode(sys.argv[1]).decode() |
|||
} |
|||
r = requests.post(url, verify=cert_path, data=json.dumps(data)) |
|||
print(r.json()) |
Loading…
Reference in new issue