Hello Patrice
would be great if you can share your script , thanks.
Hi,
sure, with pleasure. But I have to say I am not a professional
programmer. There are surely better ways to do this, but it works for me.
Before you can use it you have to make it executable with this command:
chmod +x build_tor_from_source.sh
And make sure to read the info in the script.
After that you are ready to roll.
regards
Patrice
## build_tor_from_source.sh
###
## 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"
# 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 lynx
$green
echo -e "\ndone.\n"
$white
build_dir="temp"
mkdir $build_dir
cd $build_dir # in ./temp
$green
echo -e "\ndownloading tor from git repo...\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 system 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 tor on boot...\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
__