[tor-relays] TOR installation (walentyczerwinski85)

Patrice Bönig mailinglist at pboenig.de
Sun May 23 09:17:33 UTC 2021


Hi,

sure, I wrote a script for this. I always compile Tor to use it as a 
relay on a Raspberry Pi.

I have attached the script.


regards,
Patrice





######
# Script #
######


##############################################################################################################

## This script is for a automatic installation of tor out of the sources.


## What it will do:
#
# 1. It downloads the newest tarball, compiles and installs it.
# 2. It copies the data dir (with the keys) and the torrc.
# 3. It removes all installations files.
# 4. It starts tor as the current user
# 5. It adds tor as crontab (@bootup) of current user
# 6. changes the permissions of the tor logs, tor folder and torrc for 
the current user
# 6. At the end it shows the logs to check the tor startup process


## What are the requirements for this installation script
#
# - the torrc must be in the same folder as this script
# - check the paths used in this script if they fit for your system (the 
default paths are for Pi OS)
# - this script must be in a location where it has write permisssions 
(for example home folder of current user)


## What this script can't do
#
# Tor is not compiled wioth systemd support, so this won't work until 
you switch it on.

##############################################################################################################

#! /bin/bash



# echo output colour #
green="tput setaf 2"
white="tput setaf 7"
yellow="tput setaf 3"
red="tput setaf 1"
#####################



$yellow
echo -e "\n\n####################"
echo -e "# Tor Installation #"
echo -e "####################\n"


# lynx installation
sudo apt install -y lynx


# show tor version for comparison
$yellow
echo -e "\nTor version on the system ->"
$green
tor --version | cut -b 13-20
echo # new line
$yellow
echo -e "Tor version online available ->"
$green
lynx -nonumbers -dump https://dist.torproject.org | grep 
"https://dist.torproject.org/tor-" | grep -v "alpha" | grep -v "rc" | 
grep -v "asc" | tail -1 | cut -b 33-40


# question for installation
$red
echo -e "\n\n"
read -p "Installing new version? [y/n]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then


     $green
     echo -e "\nstopping tor on system...\n"
     $white
     sudo killall tor
     $green
     echo -e "\ndone.\n"


     $green
     echo -e "\nsystem update and installing needed packages...\n"
     $white
     sudo apt update
     sudo apt upgrade -y
     sudo apt install -y libevent-dev libssl-dev zlib1g-dev asciidoc
     $green
     echo -e "\ndone.\n"

     $white
     build_dir="temp"
     mkdir $build_dir
     cd $build_dir # in ./temp


     $green
     echo -e "\ndownloading tor from https://dist.torproject.org ...\n"
     $white
     lynx -nonumbers -dump https://dist.torproject.org | grep 
"https://dist.torproject.org/tor-" | grep -v "alpha" | grep -v "rc" | 
grep -v "asc" | tail -1 | xargs wget
     tar -xvf tor*.tar.gz
     cd `ls -d */` # in ./temp/tor-*
     $green
     echo -e "\ndone.\n"


     $green
     echo -e "\nbacking up data dir, and changing its user..."
     $white
     sudo cp -arv /var/lib/tor ./tor
     sudo chown -R $(whoami) ./tor
     $green
     echo -e "\ndone.\n"


     $green
     echo -e "\ncompiling, removing old version, installing new 
version...\n"
     $white
     ./configure && make && sudo make uninstall && sudo make install
     $green
     echo -e "\ndone.\n"


     $green
     echo -e "\ncopying torrc and restoring data directory...\n"
     $white
     sudo cp -av ../../torrc /usr/local/etc/tor/torrc
     sudo chwon $(whoami):root /usr/local/etc/tor/torrc
     sudo cp -arv ./tor /var/lib/tor
     $green
     echo -e "\ndone.\n"


     cd .. # in ./temp
     cd .. # in ./


     $green
     echo -e "\nremoving build folder and installation files...\n"
     $white
     sudo rm -R $build_dir
     sudo apt autoclean
     sudo apt autoremove
     $green
     echo -e "\ndone.\n"


     $green
     echo -e "\nadding tor as crontab to start it on @reboot...\n"
     $white
     if sudo grep -q "@reboot /usr/local/bin/tor --quiet" 
/var/spool/cron/crontabs/$(whoami)
     then
         echo -e "tor is already present as crontab"
     else
         #echo -e "@reboot /usr/local/bin/tor --quiet" | sudo tee -a 
/var/spool/cron/crontabs/$(whoami)
         echo -e "tor is added as crontab"
     fi
     $green
     echo -e "\ndone.\n"


     $green
     echo -e "\nchanging user of log files...\n"
     $white
     sudo chown -R $(whoami) /var/log/tor
     $green
     echo -e "\ndone.\n"


     $green
     echo -e "\nstarting tor...\n"
     $white
     # start tor
     /usr/local/bin/tor --quiet
     echo # new line


     $yellow
     echo -e "\ntor log\n"
     $white
     sudo tail -c+1 -f /var/log/tor/notices.log


else
     $white
     exit 1
fi






More information about the tor-relays mailing list