#!/usr/bin/env bash #################################################################################################### # # Tor Auto Installer (for Debian/Ubuntu and RedHat based systems) # # Written by Someguy123 @ Privex Inc. # # If this script helps you, consider buying a server from Privex! # # - We accept cryptocurrency (BTC, LTC, XMR, DOGE, EOS, HIVE, HBD, and possibly more) # - We don't require any personal info - a name (can be an alias/username) and an e-mail # is all we ask for # - We're Belize-based, so we're able to stand up for PRIVACY and FREEDOM OF SPEECH to the max # - We allow Tor EXIT nodes and relays: https://www.privex.io/tor-exit-policy # # https://www.privex.io # # Released under X11 / MIT License # ######################### # # Quickstart: # # curl -fsSL https://cdn.privex.io/extras/install-tor.sh | bash # ######################### # # Tor Auto Installer is a bash script which is compatible with most Debian-based and # RedHat-based Linux distros. # # It automatically downloads and installs TorProject's repository, GPG key(s), plus any # special dependencies (e.g. EPEL for CentOS/RHEL/Oracle). # # Once the repo is setup, and any required GPG keys are imported etc. - it automatically # installs the Tor software (service + torsocks, not Tor Browser) via your distro's # package manager. # ######################### # # Supported Linux distros: # # - Ubuntu 16.04 (Xenial) # - Ubuntu 18.04 (Bionic) # - Ubuntu 20.04 (Focal) # - Debian 10 (Buster) # - Debian 9 (Jessie) # # - Fedora 33 (may work with older versions) # - CentOS 8 (may work with older versions) # - Oracle Linux 8 (may work with older versions) # - Red Hat Enterprise Linux 8 (RHEL 8) (may work with older versions) # # Tested on: # VPS/Dedi: Ubuntu 18.04, Ubuntu 20.04, Debian 10 # Docker Images: Fedora 33, CentOS 8, Oracle Linux 8.3, RHEL 8 # #################################################################################################### export PATH="${HOME}/.local/bin:/snap/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:${PATH}" : ${TOR_KEY_ID="A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89"} : ${TOR_KEY="https://deb.torproject.org/torproject.org/${TOR_KEY_ID}.asc"} : ${TOR_KEY_NAME="torproject-2020.gpg"} : ${TOR_REPO="https://deb.torproject.org/torproject.org"} : ${CODENAME=""} IS_DEBIAN=1 IS_REDHAT=0 TOR_CENTOS="[tor] name=Tor for Enterprise Linux \$releasever - \$basearch baseurl=https://rpm.torproject.org/centos/\$releasever/\$basearch enabled=1 gpgcheck=1 gpgkey=https://rpm.torproject.org/centos/public_gpg.key cost=100 " TOR_FEDORA="[tor] name=Tor for Fedora \$releasever - \$basearch baseurl=https://rpm.torproject.org/fedora/\$releasever/\$basearch enabled=1 gpgcheck=1 gpgkey=https://rpm.torproject.org/fedora/public_gpg.key cost=100 " DEB_CMD="" RH_CMD="yum" command -v apt-get &> /dev/null && DEB_CMD="apt-get" command -v apt &> /dev/null && DEB_CMD="apt" command -v dnf &> /dev/null && RH_CMD="dnf" if [ -t 1 ]; then RED="$(tput setaf 1)" GREEN="$(tput setaf 2)" YELLOW="$(tput setaf 3)" BLUE="$(tput setaf 4)" BOLD="$(tput bold)" NORMAL="$(tput sgr0)" RESET="$(tput sgr0)" else RED="" GREEN="" YELLOW="" BLUE="" BOLD="" NORMAL="" RESET="" fi sudo() { if (( EUID == 0 )); then "$@" return $? else if command -v sudo &> /dev/null; then env sudo "$@" return $? elif command -v su &> /dev/null; then su -p -l -c "$*" root return $? fi >&2 echo "${BOLD}${RED} >>> Neither sudo nor su available - and you're not root... Cannot run: $* ${RESET}" >&2 echo "${BOLD}${RED} >>> Attempting to run command as current user... ${RESET}" "$@" return $? fi } if ! command -v curl &> /dev/null; then echo -e "\n${BOLD}${YELLOW} >>> Command 'curl' not found. Installing it.\n${RESET}" if [[ -n "$DEB_CMD" ]]; then "$DEB_CMD" update "$DEB_CMD" install -y curl wget else "$RH_CMD" install -y curl wget fi fi if ! command -v distro &> /dev/null; then echo -e "\n${BOLD}${YELLOW} >>> Command 'distro' not found. Downloading from cdn.privex.io to /usr/local/bin/distro ...\n${RESET}" curl -fsSL https://cdn.privex.io/extras/distro.sh | sudo tee /usr/local/bin/distro sudo chmod +x /usr/local/bin/distro fi DISTRO="$(distro)" if [[ -z "$CODENAME" ]]; then case "$DISTRO" in "Ubuntu 18.04"|"Ubuntu Bionic"|"Ubuntu 18.04 Bionic Beaver"|"bionic") CODENAME="bionic" ;; "Ubuntu 20.04"|"Ubuntu Focal"|"Ubuntu 20.04 Focal Fossa"|"focal") CODENAME="focal" ;; "Ubuntu 16.04"|"Ubuntu Xenial"|"Ubuntu 16.04 Xenial"|"xenial") CODENAME="xenial" ;; "Debian GNU/Linux 10"|"Debian 10"|"Debian Buster"|"Debian 10 Buster") CODENAME="buster" ;; "Debian GNU/Linux 9"|"Debian 9"|"Debian Jessie"|"Debian 9 Jessie") CODENAME="jessie" ;; *) if grep -Ei "oracle|centos" <<< "$DISTRO"; then CODENAME="centos" IS_DEBIAN=0 IS_REDHAT=1 elif grep -i "fedora" <<< "$DISTRO"; then CODENAME="fedora" IS_DEBIAN=0 IS_REDHAT=1 elif grep -Ei "redhat|red hat|rhel" <<< "$DISTRO"; then CODENAME="redhat" IS_DEBIAN=0 IS_REDHAT=1 else if command -v yum &>/dev/null || command -v dnf &>/dev/null; then echo -e "\n${BOLD}${YELLOW} >>> Unable to determine distro ... Assuming CentOS binaries will be compatible.\n${RESET}" IS_DEBIAN=0 IS_REDHAT=1 CODENAME="centos" else echo -e "\n${BOLD}${YELLOW} >>> Unable to determine distro ... Assuming Debian 10 Buster binaries will be compatible.\n${RESET}" CODENAME="buster" IS_DEBIAN=1 IS_REDHAT=0 fi fi ;; esac else echo -e "\n${BOLD}${GREEN} >>> Env var CODENAME set externally. Using codename: ${CODENAME}\n${RESET}" fi echo -e "\n${BOLD}${GREEN} >>> Using codename: ${CODENAME}\n${RESET}" if (( IS_DEBIAN )); then echo -e "\n${BOLD}${GREEN} >>> Running apt update ...\n${RESET}" apt-get update -qy echo -e "\n${BOLD}${GREEN} >>> Installing apt-transport-https and software-properties-common ...\n${RESET}" apt-get install -qy apt-transport-https software-properties-common echo -e "\n${BOLD}${GREEN} >>> Downloading and importing torproject key: $TOR_KEY \n${RESET}" curl -fsSL "$TOR_KEY" | gpg --import echo -e "\n${BOLD}${GREEN} >>> Exporting key $TOR_KEY_ID to /etc/apt/trusted.gpg.d/${TOR_KEY_NAME} \n${RESET}" gpg --export "$TOR_KEY_ID" | tee "/etc/apt/trusted.gpg.d/${TOR_KEY_NAME}" > /dev/null fi add-repo() { local repof="$1" repoct="$2" if [[ -f "$repof" ]]; then echo -e "\n${BOLD}${YELLOW} >>> Repo file '${repof}' already exists. Not creating repo file.\n${RESET}" else echo -e "\n${BOLD}${GREEN} >>> Creating repo file: ${repof} \n${RESET}" tee -a "$repof" <<< "$repoct" echo fi } if [[ "$CODENAME" == "centos" || "$CODENAME" == "redhat" || "$CODENAME" == "fedora" ]]; then : ${TOR_REPO_FILE="/etc/yum.repos.d/tor.repo"} [[ "$CODENAME" == "fedora" ]] && TOR_YUMCT="$TOR_FEDORA" || TOR_YUMCT="$TOR_CENTOS" add-repo "$TOR_REPO_FILE" "$TOR_YUMCT" else : ${TOR_REPO_FILE="/etc/apt/sources.list.d/torproject.list"} deb_repo_ct="deb ${TOR_REPO} ${CODENAME} main deb-src ${TOR_REPO} ${CODENAME} main " add-repo "$TOR_REPO_FILE" "$deb_repo_ct" fi #echo -e "\n${BOLD}${GREEN} >>> ...\n${RESET}" if (( IS_DEBIAN )); then echo -e "\n${BOLD}${GREEN} >>> Running apt update ...\n${RESET}" apt update -qy echo -e "\n${BOLD}${GREEN} >>> Installing/updating Tor and TorProject keyring... \n${RESET}" apt-get install -qy deb.torproject.org-keyring tor else echo -e "\n${BOLD}${GREEN} [...] Using package manager command: ${RH_CMD}\n${RESET}" if grep -qi "oracle" <<< "$DISTRO"; then echo -e "\n${BOLD}${YELLOW} >>> Downloading and installing EPEL for Oracle...\n${RESET}" curl -fsSL https://cdn.privex.io/extras/repos/ol8-epel.repo | sudo tee -a /etc/yum.repos.d/ol8-epel.repo dnf makecache dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm dnf makecache elif grep -Eqi "redhat|red hat|rhel" <<< "$DISTRO"; then echo -e "\n${BOLD}${YELLOW} >>> Downloading and installing EPEL for Red Hat Enterprise Linux (RHEL)...\n${RESET}" dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm dnf makecache else echo -e "\n${BOLD}${GREEN} >>> Installing/updating epel-release\n${RESET}" "$RH_CMD" install epel-release -y fi echo -e "\n${BOLD}${GREEN} >>> Installing/updating Tor\n${RESET}" "$RH_CMD" install tor -y fi echo -e "\n${BOLD}${GREEN} [+++] FINISHED. \n${RESET}" systemctl status tor@default.service