#!/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 if [ ${#network} -eq 0 ]; then echo "FAIL - missing /mnt/hdd/raspiblitz.conf" exit 1 fi # add default value to raspi config if needed if [ ${#runBehindTor} -eq 0 ]; then echo "runBehindTor=off" >> /mnt/hdd/raspiblitz.conf 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" = "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 "*** 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 <