raspiblitz/home.admin/00settingsMenuServices.sh

182 lines
6.3 KiB
Bash
Raw Normal View History

#!/bin/bash
# get raspiblitz config
source /mnt/hdd/raspiblitz.conf
2018-12-02 23:08:20 +01:00
if [ ${#autoPilot} -eq 0 ]; then autoPilot="off"; fi
if [ ${#autoNatDiscovery} -eq 0 ]; then autoNatDiscovery="off"; fi
if [ ${#runBehindTor} -eq 0 ]; then runBehindTor="off"; fi
if [ ${#rtlWebinterface} -eq 0 ]; then rtlWebinterface="off"; fi
if [ ${#chain} -eq 0 ]; then chain="main"; fi
# map chain to on/off
chainValue="off"
if [ "${chain}" = "test" ]; then chainValue="on"; fi
2018-12-20 14:13:42 +01:00
# map domain to on/off
domainValue="off"
2018-12-21 00:47:46 +01:00
dynDomainMenu="'DynamicDNS (domainname)'"
if [ ${#dynDomain} -gt 0 ]; then
domainValue="on"
dynDomainMenu="'${dynDomain}'"
fi
2018-12-20 14:13:42 +01:00
# show select dialog
2018-12-20 22:52:54 +01:00
CHOICES=$(dialog --checklist 'Activate/Deactivate Services:' 15 45 7 \
1 'Channel Autopilot' ${autoPilot} \
2 'Testnet' ${chainValue} \
3 'Router AutoNAT' ${autoNatDiscovery} \
2018-12-21 00:47:46 +01:00
4 ${dynDomainMenu} ${domainValue} \
2018-12-20 22:52:54 +01:00
5 'Run behind TOR' ${runBehindTor} \
6 'RTL Webinterface' ${rtlWebinterface} \
2018-10-15 22:29:07 +02:00
2>&1 >/dev/tty)
2018-10-16 00:04:20 +02:00
dialogcancel=$?
clear
# check if user canceled dialog
2018-10-16 00:04:20 +02:00
if [ ${dialogcancel} -eq 1 ]; then
echo "user canceled"
exit 1
fi
2018-12-01 20:25:33 +01:00
needsReboot=0
# AUTOPILOT process choice
choice="off"; check=$(echo "${CHOICES}" | grep -c "1")
if [ ${check} -eq 1 ]; then choice="on"; fi
2018-11-27 04:19:57 +01:00
if [ "${autoPilot}" != "${choice}" ]; then
2018-12-02 19:52:01 +01:00
echo "Autopilot Setting changed .."
2018-11-27 04:19:57 +01:00
sudo /home/admin/config.scripts/lnd.autopilot.sh ${choice}
2018-12-01 20:25:33 +01:00
needsReboot=1
2018-11-27 04:19:57 +01:00
else
echo "Autopilot Setting unchanged."
2018-12-01 20:25:33 +01:00
fi
# TESTNET process choice
choice="main"; check=$(echo "${CHOICES}" | grep -c "2")
if [ ${check} -eq 1 ]; then choice="test"; fi
if [ "${chain}" != "${choice}" ]; then
if [ "${network}" = "litecoin" ] && [ "${choice}"="test" ]; then
dialog --title 'FAIL' --msgbox 'Litecoin-Testnet not available.' 5 25
else
2018-12-02 19:52:01 +01:00
echo "Testnet Setting changed .."
2018-12-01 20:25:33 +01:00
sudo /home/admin/config.scripts/network.chain.sh ${choice}net
2018-12-04 22:24:28 +01:00
walletExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${choice}net/wallet.db 2>/dev/null | grep -c 'wallet.db')
if [ ${walletExists} -eq 0 ]; then
2018-12-05 01:49:34 +01:00
echo "Need to creating a new wallet ... wait 20secs"
sudo systemctl start lnd
2018-12-05 01:49:34 +01:00
sleep 20
tryAgain=1
while [ ${tryAgain} -eq 1 ]
do
echo "****************************************************************************"
echo "Creating a new LND Wallet for ${network}/${choice}net"
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 "****************************************************************************"
2018-12-20 20:11:02 +01:00
sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net create 2>error.out
error=`sudo cat error.out`
if [ ${#error} -eq 0 ]; then
2018-12-05 01:12:45 +01:00
sleep 2
2018-12-05 01:53:28 +01:00
# WIN
tryAgain=0
echo "!!! Make sure to write down the 24 words (cipher seed mnemonic) !!!"
echo "If you are ready. Press ENTER."
else
# FAIL
tryAgain=1
echo "!!! FAIL ---> SOMETHING WENT WRONG !!!"
echo "${error}"
echo "Press ENTER to retry ... or CTRL-c to EXIT"
fi
read key
done
2018-12-05 11:18:18 +01:00
echo "Check for Macaroon .. (10sec)"
sleep 10
2018-12-05 01:48:37 +01:00
macaroonExists=$(sudo ls /home/bitcoin/.lnd/data/chain/${network}/${choice}net/admin.macaroon | grep -c 'admin.macaroon')
if [ ${macaroonExists} -eq 0 ]; then
echo "*** PLEASE UNLOCK your wallet with PASSWORD C to create macaroon"
2018-12-05 11:18:18 +01:00
lncli unlock 2>/dev/null
2018-12-05 01:48:37 +01:00
sleep 6
fi
macaroonExists=$(sudo ls /home/bitcoin/.lnd/data/chain/${network}/${choice}net/admin.macaroon | grep -c 'admin.macaroon')
if [ ${macaroonExists} -eq 0 ]; then
echo "FAIL --> Was not able to create macaroon"
echo "Please report problem."
exit 1
fi
2018-12-05 00:58:44 +01:00
echo "stopping lnd again"
sleep 5
sudo systemctl stop lnd
fi
2018-12-05 01:48:37 +01:00
echo "Update Admin Macaroon"
2018-12-05 01:12:45 +01:00
sudo rm -r /home/admin/.lnd/data/chain/${network}/${choice}net 2>/dev/null
sudo mkdir /home/admin/.lnd/data/chain/${network}/${choice}net
sudo cp /home/bitcoin/.lnd/data/chain/${network}/${choice}net/admin.macaroon /home/admin/.lnd/data/chain/${network}/${choice}net
sudo chown -R admin:admin /home/admin/.lnd/
2018-12-05 01:48:37 +01:00
2018-12-01 20:25:33 +01:00
needsReboot=1
fi
else
echo "Testnet Setting unchanged."
fi
2018-12-01 22:24:32 +01:00
# AUTONAT process choice
choice="off"; check=$(echo "${CHOICES}" | grep -c "3")
if [ ${check} -eq 1 ]; then choice="on"; fi
if [ "${autoNatDiscovery}" != "${choice}" ]; then
2018-12-02 19:52:01 +01:00
echo "AutoNAT Setting changed .."
2018-12-01 22:24:32 +01:00
sudo /home/admin/config.scripts/lnd.autonat.sh ${choice}
needsReboot=1
else
2018-12-02 19:52:01 +01:00
echo "AutoNAT Setting unchanged."
fi
2018-12-20 14:13:42 +01:00
# Dynamic Domain
2018-12-02 19:52:01 +01:00
choice="off"; check=$(echo "${CHOICES}" | grep -c "4")
if [ ${check} -eq 1 ]; then choice="on"; fi
2018-12-20 14:13:42 +01:00
if [ "${domainValue}" != "${choice}" ]; then
echo "Dynamic Domain changed .."
2018-12-20 22:52:54 +01:00
sudo /home/admin/config.scripts/internet.dyndomain.sh ${choice}
needsReboot=1
2018-12-20 14:13:42 +01:00
else
echo "Dynamic Domain unchanged."
fi
# TOR process choice
choice="off"; check=$(echo "${CHOICES}" | grep -c "5")
if [ ${check} -eq 1 ]; then choice="on"; fi
2018-12-02 19:52:01 +01:00
if [ "${runBehindTor}" != "${choice}" ]; then
echo "TOR Setting changed .."
sudo /home/admin/config.scripts/internet.tor.sh ${choice}
needsReboot=1
else
echo "TOR Setting unchanged."
fi
# RTL process choice
2018-12-20 14:13:42 +01:00
choice="off"; check=$(echo "${CHOICES}" | grep -c "6")
2018-12-02 19:52:01 +01:00
if [ ${check} -eq 1 ]; then choice="on"; fi
if [ "${rtlWebinterface}" != "${choice}" ]; then
echo "RTL Webinterface Setting changed .."
sudo /home/admin/config.scripts/bonus.rtl.sh ${choice}
2018-12-03 23:25:55 +01:00
if [ "${choice}" = "on" ]; then
2018-12-02 19:52:01 +01:00
l1="RTL web servcie should be installed - AFTER NEXT REBOOT:"
l2="Try to open the following URL in your local webrowser"
l3="and unlock your wallet from there with PASSWORD C."
l4="---> http://${localip}:3000"
2018-12-12 14:06:37 +01:00
dialog --title 'OK' --msgbox "${l1}\n${l2}\n${l3}\n${l4}" 9 45
2018-12-02 19:52:01 +01:00
fi
needsReboot=1
2018-12-02 23:50:14 +01:00
else
2018-12-02 19:52:01 +01:00
echo "RTL Webinterface Setting unchanged."
2018-12-01 22:24:32 +01:00
fi
2018-12-01 20:25:33 +01:00
if [ ${needsReboot} -eq 1 ]; then
2018-12-02 19:52:01 +01:00
sleep 2
2018-12-02 23:50:14 +01:00
dialog --title 'OK' --msgbox 'System will reboot to activate changes.' 6 26
2018-12-04 01:23:12 +01:00
echo "rebooting .."
2018-12-01 20:25:33 +01:00
sudo shutdown -r now
2018-10-16 00:24:36 +02:00
fi