Skip to content

Instantly share code, notes, and snippets.

@rcguy
Last active August 24, 2021 01:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcguy/911a7db3e2a880d0008c to your computer and use it in GitHub Desktop.
Save rcguy/911a7db3e2a880d0008c to your computer and use it in GitHub Desktop.
Install and setup: new rtorrent user, apache2, php5, XMLRPC, rTorrent, Libtorrent, ruTorrent.Tested on: Ubuntu Server 14.10 x64 / 4 Cores / 4GB RAM / 20 GB SSD / VPS
#!/bin/bash
# Install and setup: new rtorrent user, apache2, XMLRPC, rTorrent, Libtorrent, ruTorrent.
# Tested on: Ubuntu Server 14.10 x64 / 4 Cores / 4GB RAM / 20 GB SSD
# ==> VARIABLES <==
# Software Versions
LIBTORRENT_VER="0.13.6"
RTORRENT_VER="0.9.6"
RUTORRENT_VER="3.7"
RUTORRENT_PLUGINS_VER="3.6"
# Apache2
APACHE_ROOT="/var/www/html"
# ruTorrent.
RUTORRENT_USER="admin"
RUTORRENT_USER_PASSWORD="admin"
RUTORRENT_THEME="Oblivion" # Options: Oblivion, Dark, Blue, Acid or leave blank
RUTORRENT_CONFIG="$APACHE_ROOT/rutorrent/conf/config.php"
RUTORRENT_PLUGINS_DIR="$APACHE_ROOT/rutorrent/plugins"
RUTORRENT_PLUGINS_USER_CONF_DIR="$APACHE_ROOT/rutorrent/conf/users/$RUTORRENT_USER/plugins"
# rTorrent settings.
RTORRENT_USER="rtorrent"
RTORRENT_USER_HOME="/opt/rtorrent"
RTORRENT_DOWNLOADS_DIR="/home/$USER/downloads"
RTORRENT_DOWNLOADS_GROUP="rtorrent-data"
RTORRENT_DOWNLOADS_UMASK="002"
RTORRENT_PORT="50000-50000"
RTORRENT_MAX_MEM="2048M"
# URLs
LIBTORRENT="http://rtorrent.net/downloads/libtorrent-$LIBTORRENT_VER.tar.gz"
RTORRENT="http://rtorrent.net/downloads/rtorrent-$RTORRENT_VER.tar.gz"
RUTORRENT="http://dl.bintray.com/novik65/generic/rutorrent-$RUTORRENT_VER.tar.gz"
RUTORRENT_PLUGINS="http://dl.bintray.com/novik65/generic/plugins-$RUTORRENT_PLUGINS_VER.tar.gz"
GEOIPCITY="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"
XMLRPC="http://svn.code.sf.net/p/xmlrpc-c/code/stable"
HTPASSWD_PY_SCRIPT="http://sourceforge.net/projects/autodl-irssi/files/inst-files/htpasswd.py/download"
# Misc.
TMP_DIR="$RTORRENT_HOME/install"
PHP=`which php`
IP_ADDRESS=$(ifconfig eth0 | grep "inet addr:" | cut -d':' -f 2 | awk '{print $1}')
# ==> MAIN PROGRAM <==
set -e
# Add user & group.
adduser --system --group --disabled-login --disabled-password --home $RTORRENT_USER_HOME $RTORRENT_USER
addgroup $RTORRENT_DOWNLOADS_GROUP
# Update Everything and install some needed dependencies. # Temp: php5-sqlite sqlite
apt-get update
apt-get upgrade -y
apt-get autoremove -y
apt-get autoclean -y
apt-get install subversion build-essential automake libtool libssl-dev libcppunit-dev libcurl4-openssl-dev libsigc++-2.0-dev libcppunit-dev unzip unrar-free libncurses5-dev apache2 apache2-utils php5 php5-cli php5-curl php5-xmlrpc libapache2-mod-php5 php5-geoip mediainfo -y
# Install XMLRPC.
mkdir $TMP_DIR
cd $TMP_DIR
svn checkout $XMLRPC xmlrpc-c
cd xmlrpc-c
./configure --disable-cplusplus
make
make install
# Install Libtorrent.
cd $TMP_DIR
wget $LIBTORRENT
tar xvzf libtorrent-$LIBTORRENT_VER.tar.gz
cd libtorrent-$LIBTORRENT_VER
./autogen.sh
./configure
make
make install
# Install rTorrent.
cd $TMP_DIR
wget $RTORRENT
tar xvzf rtorrent-$RTORRENT_VER.tar.gz
cd rtorrent-$RTORRENT_VER
./autogen.sh
./configure --with-xmlrpc-c
make
make install
ldconfig
if [ ! -d $RTORRENT_DOWNLOADS_DIR ]; then
mkdir -p $RTORRENT_DOWNLOADS_DIR
fi
mkdir $RTORRENT_USER_HOME/{.session,watch}
cat > $RTORRENT_USER_HOME/.rtorrent.rc <<EOF
execute = {sh,-c,rm -f $RTORRENT_USER_HOME/.session/rpc.socket}
scgi_local = $RTORRENT_USER_HOME/.session/rpc.socket
execute = {sh,-c,chmod 0666 $RTORRENT_USER_HOME/.session/rpc.socket}
encoding_list = UTF-8
system.umask.set = $RTORRENT_DOWNLOADS_UMASK
check_hash = no
max_memory_usage = $RTORRENT_MAX_MEM
directory = $RTORRENT_DOWNLOADS_DIR
session = $RTORRENT_USER_HOME/.session
#schedule = watch_directory,5,5,load_start=$RTORRENT_USER_HOME/watch/*.torrent
port_range = $RTORRENT_PORT
upload_rate = 0
download_rate = 0
use_udp_trackers = yes
max_uploads = 50
min_peers=10
max_peers=100
peer_exchange = no
dht = disable
encryption = allow_incoming,try_outgoing,enable_retry
execute = {sh,-c,$PHP $APACHE_ROOT/rutorrent/php/initplugins.php $RUTORRENT_USER &}
EOF
# Install ruTorrent
cd $TMP_DIR
wget $RUTORRENT
tar xvzf rutorrent-$RUTORRENT_VER.tar.gz
mv rutorrent $APACHE_ROOT
# Install ruTorrent 3.6 Plugins.
cd $TMP_DIR
wget $RUTORRENT_PLUGINS
tar xvzf plugins-$RUTORRENT_PLUGINS_VER.tar.gz
cd plugins/
mv rpc/ theme/ trafic/ $RUTORRENT_PLUGINS_DIR # <== DO NOT CHANGE OR REMOVE THIS LINE
# List of plugins: https://github.com/Novik/ruTorrent/wiki/Plugins#currently-there-are-the-following-plugins
# Add or Remove any Plugins you want installed;
mv _getdir/ _noty/ _task/ cpuload/ create/ check_port/ datadir/ diskspace/ erasedata/ geoip/ lookat/ mediainfo/ seedingtime/ source/ $RUTORRENT_PLUGINS_DIR
# Install GeoIPCity.
cd $TMP_DIR
wget $GEOIPCITY
gunzip GeoLiteCity.dat.gz
if [ ! -d /usr/share/GeoIP ]; then
mkdir /usr/share/GeoIP
fi
mv GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
# Create the .htpasswd file.
cd $TMP_DIR
wget $HTPASSWD_PY_SCRIPT -O htpasswd.py
python ./htpasswd.py -c -b $RTORRENT_USER_HOME/.htpasswd $RUTORRENT_USER $RUTORRENT_USER_PASSWORD
# Configure Apache2.
mv /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.bak
rm /etc/apache2/sites-enabled/000-default.conf
cat > /etc/apache2/sites-available/default.conf <<EOF
<VirtualHost $IP_ADDRESS:80>
ServerName $IP_ADDRESS
ServerAdmin webmaster@localhost
DocumentRoot $APACHE_ROOT/
<Directory />
AllowOverride None
</Directory>
<Directory $APACHE_ROOT/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory $APACHE_ROOT/rutorrent/>
AuthUserFile $RTORRENT_USER_HOME/.htpasswd
AuthName "Tits or GTFO!"
AuthType Basic
Require valid-user
</Directory>
SetEnvIf Request_URI "^/rutorrent/.*$" rutorrent
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log common
CustomLog \${APACHE_LOG_DIR}/rutorrent-access.log common env=rutorrent
</VirtualHost>
EOF
cat > $APACHE_ROOT/index.html <<EOF
<!DOCTYPE html>
<html>
<body style="background-color:gray">
<head>
<title>All The Things!</title>
</head>
<body>
<div align="center">
<h1> You can check out any time you like, but you can never leave!</h1>
<a href="/rutorrent" target="_blank"><h2>ruTorrent</h2></a>
<a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" target="_blank"><h2>Click Me! Click Me!</h2></a>
</div>
</body>
</html>
EOF
# Edit ruTorrent Config.
cp $RUTORRENT_CONFIG $RUTORRENT_CONFIG.bak
sh -c "sed -i 's#\\\$scgi_port = 5000;#\\\$scgi_port = 0;#' $RUTORRENT_CONFIG"
sh -c "sed -i 's#\\\$scgi_host = \"127.0.0.1\";#\\\$scgi_host = \"unix://$RTORRENT_USER_HOME/.session/rpc.socket\";#' $RUTORRENT_CONFIG"
sh -c "sed -i \"s#\\\$topDirectory = '/';#\\\$topDirectory = '$RTORRENT_DOWNLOADS_DIR/';#\" $RUTORRENT_CONFIG"
# Setup ruTorrent Plugins User Configs.
mkdir -p $RUTORRENT_PLUGINS_USER_CONF_DIR/{trafic,theme}
cp $RUTORRENT_PLUGINS_DIR/trafic/conf.php $RUTORRENT_PLUGINS_USER_CONF_DIR/trafic/conf.php
cp $RUTORRENT_PLUGINS_DIR/theme/conf.php $RUTORRENT_PLUGINS_USER_CONF_DIR/theme/conf.php
sh -c "sed -i 's#\\\$updateInterval = 15;#\\\$updateInterval = 5;#' $RUTORRENT_PLUGINS_USER_CONF_DIR/trafic/conf.php"
sh -c "sed -i 's#\\\$defaultTheme = \"\";#\\\$defaultTheme = \"$RUTORRENT_THEME\";#' $RUTORRENT_PLUGINS_USER_CONF_DIR/theme/conf.php"
# Finish up.
chmod 0775 -R $RTORRENT_USER_HOME/{.session,watch}
chmod 0775 $RTORRENT_DOWNLOADS_DIR
chmod 0755 $APACHE_ROOT/rutorrent
chmod 0755 $(find $RUTORRENT_PLUGINS_DIR -type d)
chown -R $RTORRENT_USER:$RTORRENT_DOWNLOADS_GROUP $RTORRENT_DOWNLOADS_DIR
chmod g+s -R $RTORRENT_DOWNLOADS_DIR
chown -R $RTORRENT_USER:$RTORRENT_USER $RTORRENT_USER_HOME
chown -R www-data:www-data $APACHE_ROOT
a2enmod auth_digest
a2ensite default.conf
service apache2 restart
rm -rf $TMP_DIR
rm -rf $APACHE_ROOT/html
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment