From 7f1a0f04a51e0d8365d6d74b2cad0e81b530fc0b Mon Sep 17 00:00:00 2001 From: rootzoll Date: Sun, 2 Dec 2018 19:52:01 +0100 Subject: [PATCH] more config scripts --- home.admin/00settingsMenuServices.sh | 57 +++-- home.admin/_bootstrap.sh | 12 + home.admin/config.scripts/bonus.rtl.sh | 99 +++++++ home.admin/config.scripts/internet.tor.sh | 284 +++++++++++++++++++++ home.admin/config.scripts/lnd.autonat.sh | 15 +- home.admin/config.scripts/lnd.autopilot.sh | 7 +- home.admin/config.scripts/network.chain.sh | 5 + 7 files changed, 458 insertions(+), 21 deletions(-) create mode 100755 home.admin/config.scripts/bonus.rtl.sh create mode 100755 home.admin/config.scripts/internet.tor.sh diff --git a/home.admin/00settingsMenuServices.sh b/home.admin/00settingsMenuServices.sh index 93af58b..3cb72dd 100644 --- a/home.admin/00settingsMenuServices.sh +++ b/home.admin/00settingsMenuServices.sh @@ -8,6 +8,8 @@ CHOICES=$(dialog --checklist "Activate/Deactivate Services:" 15 40 5 \ 1 "Channel Autopilot" ${autoPilot} \ 2 "Testnet" ${chain} \ 3 "Router AutoNAT" ${autoNatDiscovery} \ +4 "Run behind TOR" ${runBehindTor} \ +5 "RTL Webinterface" ${rtlWebinterface} \ 2>&1 >/dev/tty) #CHOICES=$(dialog --checklist "Activate/Deactivate Services:" 15 40 5 \ #1 "Channel Autopilot" ${autoPilot} \ @@ -19,6 +21,8 @@ CHOICES=$(dialog --checklist "Activate/Deactivate Services:" 15 40 5 \ dialogcancel=$? clear +rideTheLighthing + # check if user canceled dialog if [ ${dialogcancel} -eq 1 ]; then echo "user canceled" @@ -31,10 +35,7 @@ needsReboot=0 choice="off"; check=$(echo "${CHOICES}" | grep -c "1") if [ ${check} -eq 1 ]; then choice="on"; fi if [ "${autoPilot}" != "${choice}" ]; then - echo "Autopilot Setting changed" - echo "Stopping Service" - sudo systemctl stop lnd - echo "Executing change" + echo "Autopilot Setting changed .." sudo /home/admin/config.scripts/lnd.autopilot.sh ${choice} needsReboot=1 else @@ -48,11 +49,7 @@ if [ "${chain}" != "${choice}" ]; then if [ "${network}" = "litecoin" ] && [ "${choice}"="test" ]; then dialog --title 'FAIL' --msgbox 'Litecoin-Testnet not available.' 5 25 else - echo "Testnet Setting changed" - echo "Stopping Service" - sudo systemctl stop lnd - sudo systemctl stop ${network}d - echo "Executing change" + echo "Testnet Setting changed .." sudo /home/admin/config.scripts/network.chain.sh ${choice}net needsReboot=1 fi @@ -64,22 +61,44 @@ fi choice="off"; check=$(echo "${CHOICES}" | grep -c "3") if [ ${check} -eq 1 ]; then choice="on"; fi if [ "${autoNatDiscovery}" != "${choice}" ]; then - echo "AutoNAT Setting changed" - echo "Stopping Services" - sudo systemctl stop lnd - sudo systemctl stop ${network}d - echo "Disable LND" - sudo systemctl disable lnd - echo "Executing change" + echo "AutoNAT Setting changed .." sudo /home/admin/config.scripts/lnd.autonat.sh ${choice} - echo "Enable LND" - sudo systemctl enable lnd needsReboot=1 else - echo "Autopilot Setting unchanged." + echo "AutoNAT Setting unchanged." +fi + +# TOR process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "4") +if [ ${check} -eq 1 ]; then choice="on"; fi +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 +choice="off"; check=$(echo "${CHOICES}" | grep -c "5") +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} + if [ "${coice}" = "on" ]; then + 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" + dialog --title 'OK' --msgbox "${l1}\n${l2}\n${l3}\n${l4}" 9 25 + fi + needsReboot=1 +else + echo "RTL Webinterface Setting unchanged." fi if [ ${needsReboot} -eq 1 ]; then + sleep 2 dialog --title 'OK' --msgbox 'System will reboot to activate changes.' 5 25 sudo shutdown -r now fi \ No newline at end of file diff --git a/home.admin/_bootstrap.sh b/home.admin/_bootstrap.sh index 172bbda..99f5d14 100644 --- a/home.admin/_bootstrap.sh +++ b/home.admin/_bootstrap.sh @@ -319,6 +319,18 @@ if [ ${#autoNatDiscovery} -eq 0 ]; then echo "autoNatDiscovery=off" >> $configFile fi +# TOR +# runBehindTor=off|on +if [ ${#runBehindTor} -eq 0 ]; then + echo "runBehindTor=off" >> $configFile +fi + +# RideTheLightning RTL +# rtlWebinterface=off|on +if [ ${#runBehindTor} -eq 0 ]; then + echo "rtlWebinterface=off" >> $configFile +fi + ################################## # CHECK CONFIG CONSISTENCY ################################## diff --git a/home.admin/config.scripts/bonus.rtl.sh b/home.admin/config.scripts/bonus.rtl.sh new file mode 100755 index 0000000..5e4cc53 --- /dev/null +++ b/home.admin/config.scripts/bonus.rtl.sh @@ -0,0 +1,99 @@ + +#!/bin/bash + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "small config script to switch WebGUI RideTheLightning on or off" + echo "bonus.rtl.sh [on|off]" + exit 1 +fi + +# check and load raspiblitz config +# to know which network is running +source /mnt/hdd/raspiblitz.conf 2>/dev/null +if [ ${#network} -eq 0 ]; then + echo "FAIL - missing /mnt/hdd/raspiblitz.conf" + exit 1 +fi + +# stop services +echo "making sure services are not running" +sudo systemctl stop RTL 2>/dev/null + +# switch on +if [ $1 -eq 1 ] || [ "$1" = "on" ]; then + echo "*** INSTALL RTL ***" + + # setting value in raspi blitz config + sudo sed -i "s/^rtlWebinterface=.*/rtlWebinterface=on/g" /mnt/hdd/raspiblitz.conf + + isInstalled=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service') + if [ ${isInstalled} -eq 0 ]; then + + # disable RPC listen + # to prevent tls cer auth error + echo "*** Modify lnd.conf ***" + sudo sed -i "s/^rpclisten=0.0.0.0:10009/#rpclisten=0.0.0.0:10009/g" /mnt/hdd/lnd/lnd.conf + sudo systemctl restart lnd + echo "" + + # install latest nodejs + echo "*** Install NodeJS ***" + curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash - + sudo apt-get install -y nodejs + echo "" + + # close source code + echo "*** Get the RTL Source Code ***" + git clone https://github.com/ShahanaFarooqui/RTL.git + cd RTL + npm install + cd .. + echo "" + + # open firewall + echo "*** Updating Firewall ***" + sudo ufw allow 3000 + sudo ufw --force enable + echo "" + + # install service + echo "*** Install RTL systemd for ${network} on ${chain} ***" + sudo cp /home/admin/assets/RTL.service /etc/systemd/system/RTL.service + sudo sed -i "s|chain/bitcoin/mainnet|chain/${network}/${chain}net|" /etc/systemd/system/RTL.service + sudo systemctl enable RTL + echo "OK - RTL is now ACTIVE" + else + echo "RTL already installed." + fi + + echo "needs reboot to activate new setting" + exit 0 +fi + +# switch off +if [ $1 -eq 0 ] || [ "$1" = "off" ]; then + echo "*** REMOVING RTL ***" + + # setting value in raspi blitz config + sudo sed -i "s/^rtlWebinterface=.*/rtlWebinterface=off/g" /mnt/hdd/raspiblitz.conf + + isInstalled=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service') + if [ ${isInstalled} -eq 1 ]; then + echo "*** REMOVING RTL ***" + sudo systemctl stop RTL + sudo systemctl disable RTL + sudo rm /etc/systemd/system/RTL.service + sudo rm -r /home/admin/RTL + echo "OK RTL removed." + else + echo "RTL is not installed." + fi + + echo "needs reboot to activate new setting" + exit 0 +fi + +echo "FAIL - Unknown Paramter $1" +echo "may needs reboot to run normal again" +exit 1 \ No newline at end of file diff --git a/home.admin/config.scripts/internet.tor.sh b/home.admin/config.scripts/internet.tor.sh new file mode 100755 index 0000000..90c698b --- /dev/null +++ b/home.admin/config.scripts/internet.tor.sh @@ -0,0 +1,284 @@ + +#!/bin/bash + +# Background: +# https://medium.com/@lopp/how-to-run-bitcoin-as-a-tor-hidden-service-on-ubuntu-cff52d543756 +# https://bitcoin.stackexchange.com/questions/70069/how-can-i-setup-bitcoin-to-be-anonymous-with-tor +# https://github.com/lightningnetwork/lnd/blob/master/docs/configuring_tor.md + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "small config script to switch TOR on or off" + echo "internet.tor.sh [on|off]" + exit 1 +fi + +# check and load raspiblitz config +# to know which network is running +source /mnt/hdd/raspiblitz.conf 2>/dev/null +if [ ${#network} -eq 0 ]; then + echo "FAIL - missing /mnt/hdd/raspiblitz.conf" + exit 1 +fi + +# location of TOR config +torrc="/etc/tor/torrc" + +# stop services +echo "making sure services are not running" +sudo systemctl stop lnd 2>/dev/null +sudo systemctl stop ${network}d 2>/dev/null +sudo systemctl stop tor@default 2>/dev/null + +# switch on +if [ $1 -eq 1 ] || [ "$1" = "on" ]; then + echo "switching the TOR ON" + + # setting value in raspi blitz config + sudo sed -i "s/^runBehindTor=.*/runBehindTor=on/g" /mnt/hdd/raspiblitz.conf + + # check if TOR was already installed and is funtional + echo "" + echo "*** Check if TOR service is functional ***" + torRunning=$(curl --connect-timeout 10 --socks5-hostname 127.0.0.1:9050 https://check.torproject.org | grep "Congratulations. This browser is configured to use Tor." -c) + if [ ${torRunning} -gt 0 ]; then + clear + echo "You are all good - TOR is already running." + echo "" + exit 0 + else + echo "TOR not running ... proceed with switching to TOR." + echo "" + fi + + echo "*** Adding Tor Sources to sources.list ***" + echo "deb http://deb.torproject.org/torproject.org stretch main" | sudo tee -a /etc/apt/sources.list + echo "deb-src http://deb.torproject.org/torproject.org stretch main" | sudo tee -a /etc/apt/sources.list + echo "OK" + echo "" + + echo "*** Installing dirmngr ***" + sudo apt install dirmngr + echo "" + + ## lopp: gpg --keyserver keys.gnupg.net --recv 886DDD89 + echo "*** Fetching GPG key ***" + gpg --keyserver keys.gnupg.net --recv A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 + gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add - + echo "" + + echo "*** Updating System ***" + sudo apt-get update + echo "" + + echo "*** Install Tor ***" + sudo apt install tor tor-arm -y + + echo "" + echo "*** Tor Config ***" + sudo rm -r -f /mnt/hdd/tor 2>/dev/null + sudo mkdir /mnt/hdd/tor + sudo mkdir /mnt/hdd/tor/sys + sudo mkdir /mnt/hdd/tor/web80 + sudo mkdir /mnt/hdd/tor/lnd9735 + sudo mkdir /mnt/hdd/tor/lndrpc9735 + sudo chmod -R 700 /mnt/hdd/tor + sudo chown -R bitcoin:bitcoin /mnt/hdd/tor + cat > ./torrc <