This is a repository of all the files you need to configure the ultimate torrent setup.
Refer to the wiki for instructions: Ultimate Torrent Setup Wiki
This guide will help you setup the ultimate automatic torrent downloading solution. You will setup and configure, on Ubuntu server 14.04, rTorrent+ruTorrent, Sonarr, CouchPotato and Apache as a reverse proxy for all these. This guide assumes that you would like to be able to access all these interfaces from anywhere on the Internet (using a login form secured with an SSL certificate) and that you have a domain name you will use. This guide includes making a self-signed certificate if you don't have or don't want to purchase an SSL cert. Just keep in mind that you will get a certificate warning until you add a permanent exception in your browser. I would suggest using a certificate that is signed by a legitimate Certificate Authority. I personally use one that I got absolutely free from StartSSL.
We will be using the ruTorrent plugins autotools, ratio & extratio to accomplish what we want. The way these plugins work is best described by an example:
Say you have a directory /torrent for your torrent downloads. What you would do is create three sub dirs in that directory called watch, download and complete. Inside these directories will contain a mirrored directory structure for the different categories of torrents you download. So your structure might look like this:
So if you drop a torrent into /torrent/watch/tv/sonarr, the torrent download is started in /torrent/download/tv/sonarr. Also a label is automatically applied to the torrent based on the directory: in this example our torrent would receive the label tv/sonarr. Once the torrent is finished downloading, a hard link will be created in /torrent/complete/tv/sonarr. A hard link means that a duplicate file is made, but it shares the same data as the original. This is better than copying because it is instant and you don't have to duplicate the data on your hard drive. So now if we just have Sonarr watch the /torrent/complete/tv/sonarr directory it can process the hard linked files and move them to a final TV directory, AND we can continue to seed with the original file in /torrent/download/tv/sonarr with no problems. Even when we delete the file in the download directory, it won't affect the other hard link in the place where Sonarr placed it.
We'll also create some Ratio Rules that will seed a torrent of a specific label to a specified ratio and then automatically delete the torrent. So you won't have to monitor your torrents and manually clean them up when they've seeded enough, they will automatically seed to the perfect amount and then delete themselves.
The end result will be: you add a show to Sonarr, Sonarr will automatically search for new episodes and download the torrent file as soon as it's available. The torrent will be added and started in rTorrent. As soon as the download is complete, Sonarr will process the hard link of the data by renaming it nicely and placing it in a nice, organized TV Shows folder. Meanwhile rTorrent will still be seeding the original file until it reaches the defined ratio, and then will auto delete the torrent and the original file from the download dir. 100% automated TV downloading! Couchpotato does the same thing for movies.
Login as your user then execute these commands one line at a time.
Update Ubuntu
sudo apt-get update
sudo apt-get dist-upgrade
Install Prereqs
sudo apt-get install -y git-core subversion build-essential automake libtool libcppunit-dev libcurl4-openssl-dev libsigc++-2.0-dev libncurses5-dev zip rar unrar apache2 apache2-utils php5 php5-curl php5-geoip mediainfo libav-tools
Download the configs repo, which contain the necessary config files you will need.
cd ~
git clone https://github.com/xombiemp/ultimate-torrent-setup.git configs
cd /usr/local/src
sudo svn checkout http://svn.code.sf.net/p/xmlrpc-c/code/advanced xmlrpc-c
cd xmlrpc-c
sudo ./configure
sudo make
sudo make install
cd /usr/local/src
sudo git clone https://github.com/rakshasa/libtorrent.git
cd libtorrent
sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install
cd /usr/local/src
sudo git clone https://github.com/rakshasa/rtorrent.git
cd rtorrent
sudo ./autogen.sh
sudo ./configure --with-xmlrpc-c
sudo make
sudo make install
sudo ldconfig
Create the config directory for rTorrent
mkdir -p ~/.config/rtorrent
Create and change directory to where you are going to download all your torrents to. For this guide we are using /data.
sudo mkdir /data
cd /data
Then execute this command which will create the folder structure I illustrated earlier:
sudo mkdir -p torrent/{complete/{movie/couchpotato,music,tv/sonarr,game,book,software,other},download/{movie/couchpotato,music,tv/sonarr,game,book,software,other},watch/{movie/couchpotato,music,tv/sonarr,game,book,software,other}} Media/{Movies,'TV Shows'}
Give these folders full permissions by executing this on the parent directory:
sudo chmod -R 777 /data
or whatever your path is.
Make rTorrent config file:
cd ~
mv ~/configs/rtorrent.rc ~/.config/rtorrent/
Edit ~/.config/rtorrent/rtorrent.rc and look for where it says
/CHANGE/THIS/PATH
for the directory path and edit the path for your setup. In our example, the directory path is the download directory we created previously, /data/torrent/download. Look for
YOURUSER
in the session path and change it to your username.
Also look for
APACHE_WEBAUTH_USER
at the bottom and change it to the user that you want to use for Apache web authentication (we haven't created the login yet but we will later). Change any other random options that you want.
sudo mv ~/configs/rtorrent.conf /etc/init/
Edit /etc/init/rtorrent.conf and change the three occurrences of the following to your user:
YOURUSER
The script update-rutorrent will install ruTorrent and any plugins you want automatically. Then whenever you run it again it will update ruTorrent and any plugins that have updates.
sudo mv ~/configs/update-rutorrent /usr/local/bin/
sudo chmod +x /usr/local/bin/update-rutorrent
Edit /usr/local/bin/update-rutorrent and change the webroot_path if it is different for you (probably not). Edit the plugins variable to include or exclude any plugins that you want. You can leave it as it is to use the plugins that I use. The ones you have to keep are autotools, ratio, extratio and throttle. Once all the edits are made to the script, run it to install ruTorrent and your plugins:
sudo update-rutorrent
Edit /var/www/rutorrent/conf/config.php Change $topDirectory to the top directory where your torrents are downloaded. In our example:
$topDirectory = '/data/';
Change:
$saveUploadedTorrents = false;
Edit /var/www/rutorrent/plugins/autotools/conf.php The $autowatch_interval variable is how often in seconds it looks in the watch folders for new torrent files. I changed mine to:
$autowatch_interval = 60;
Edit /var/www/rutorrent/plugins/fileshare/conf.php Set the $downloadpath variable to match the domain you will use to access your site:
$downloadpath = 'http://yourdomain.com/public/share.php';
Edit /var/www/rutorrent/plugins/screenshots/conf.php Set the following variable value:
$pathToExternals['ffmpeg'] = '/usr/bin/avconv';
Edit /var/www/rutorrent/plugins/unpack/conf.php Set the following variable values:
$deleteAutoArchives = true;
$unpackToTemp = true;
sudo mv ~/configs/apache-portal.conf /etc/apache2/sites-available/
sudo a2dissite 000-default.conf
sudo a2ensite apache-portal.conf
Edit /etc/apache2/sites-available/apache-portal.conf and find all four instances of
SessionCryptoPassphrase CHANGEME
and change CHANGEME to the same unique passphrase of your choosing. You won't need to use it, it's just for encrypting the session cookie.
sudo a2enmod rewrite request headers proxy_http auth_form session_cookie session_crypto ssl
sudo mv ~/configs/site/* /var/www/
sudo mkdir /var/www/public
sudo ln -s /var/www/rutorrent/plugins/fileshare/share.php /var/www/public/
sudo chown -R www-data:www-data /var/www/*
sudo htpasswd -c /etc/apache2/passwd APACHE_WEBAUTH_USER
Replace APACHE_WEBAUTH_USER in the command with the same username as you put in the bottom of rtorrent.rc.
Edit /etc/ssl/openssl.cnf and uncomment the line that says:
req_extensions = v3_req # The extensions to add to a certificate request
Go the v3_req section and add subjectAltName variable at the bottom so it looks like
[ v3_req ]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
Under that section add another section that lists your domain name so it looks like
[ alt_names ]
DNS.1 = yourdomain.com
DNS.2 = *.yourdomain.com
Now generate your certificate:
sudo openssl req -new -newkey rsa:2048 -x509 -extensions v3_req -days 36500 -nodes -out /etc/apache2/ssl.pem -keyout /etc/apache2/ssl.pem
You’ll now have to fill out some info about your certificate. This is an example:
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:California
Locality Name (eg, city) []:Los Angeles
Organization Name (eg, company) [Internet Widgits Pty Ltd]:FakeName
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:FakeName
Email Address []:
Edit /etc/apache2/apache2.conf and add the directive for your server’s hostname:
ServerName “hostname”
Edit /etc/php5/apache2/php.ini and search for the line that contains date.timezone =. Set the value for your timezone from PHP Timezones. Mine looks like:
date.timezone = America/Denver
Edit /etc/php5/cli/php.ini and do the same thing as above.
cd ~
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FDA5DFFC
sudo echo "deb http://apt.sonarr.tv/ master main" | sudo tee /etc/apt/sources.list.d/sonarr.list
sudo apt-get update
sudo apt-get install -y nzbdrone
sudo mv ~/configs/sonarr.conf /etc/init/
Edit /etc/init/sonarr.conf and change the following to your user name:
setuid YOURUSER
cd ~
git clone https://github.com/RuudBurger/CouchPotatoServer.git .couchpotato
sudo cp ~/.couchpotato/init/ubuntu /etc/init.d/couchpotato
sudo chmod +x /etc/init.d/couchpotato
sudo update-rc.d couchpotato defaults
mkdir ~/.config/couchpotato
sudo mv ~/configs/couchpotato /etc/default/
sudo rm -r ~/configs/
Edit /etc/default/couchpotato and change the following to your user name:
CP_USER=YOURUSER
sudo service apache2 restart
sudo service rtorrent restart
sudo service sonarr start
sudo service couchpotato start
sudo service sonarr stop
sudo service couchpotato stop
Edit ~/.config/NzbDrone/config.xml and change:
<UrlBase>/sonarr</UrlBase>
Edit ~/.config/couchpotato/settings.conf and change:
url_base = /couchpotato
sudo service sonarr start
sudo service couchpotato start
First browse to https://yourdomain.com/rutorrent
You will be presented with the login window:
Login with the username and password you created earlier.
Click on the gear cog to enter the settings.
In Autotools enable all the options and browse to your complete and watch directories. Also, be sure to select Hard Link for the operation type:
In History I only check Deletion. This is nice because Sonarr could download a torrent, seed it to 2.0, and delete it all while you are sleeping. So the History plugin will let you see a record of when it was deleted and what your ratio was, just for your sanity:
In Unpack check enable autounpacking:
In Ratio Groups set up a default group and a Sonarr group:
Click ok. Then click on the wrench/screwdriver next to the gear cog and click on Ratio Rules. Set up a rule for Sonarr:
You can setup another Ratio Rule for Couchpotato downloads too, if you want. Alternatively, you could set up ratio rules for each individual tracker by selecting "One of torrent's tracker URLs contain" from the drop down list.
Now when you add a torrent you just click on the directory button and choose which category it is. Then it will automatically receive that label and it will download to the proper directory.
Now browse to https://yourdomain.com/sonarr
Click on Settings and you'll see the Media Managment tab.
Move the switch to Shown next to Advanced Settings. Switch Rename Episodes to Yes. Set the renaming formats to the way you want. Mine are set to conform to Plex naming standards. Click the Save button.
Click on the Indexers tab.
Click the plus button to add your desired providers. Configure the provider with the info it asks for, which you will usually find in your respective rss feed url for the tracker. If your tracker does not support search, I would suggest checking out Jackett. It is a separate webapp that adds search capabilities to many trackers. I haven't used it personally, but I've heard it works well.
Click on the Download Client tab.
Click the plus sign and click Torrent Blackhole. For the Torrent Folder browse to your sonarr watch directory. In our example it would be /data/torrent/watch/tv/sonarr. For the Watch Folder browse to your sonarr complete folder. In our example it would be /data/torrent/complete/tv/sonarr.
Click on Series -> Add Series -> Import Existing Series On Disk
Browse to your TV Shows folder. In our example it would be /data/Media/TV Shows/
Click the close button.
Now browse to https://yourdomain.com/couchpotato
You'll see a Wizard when you first login. Just click the Finish button; we'll configure the settings manually.
Click the gear cog and click settings.
Uncheck Launch the browser when I start.
Click on Searcher, check the box for Advanced Settings
Change the search frequency if you want.
Click Categories
You can create a category like the above that requires the source to be Blu-Ray.
bluray, blu-ray, blu & ray
Click on Qualities
I've found that these sizes work well. I've missed some downloads when I used the default values.
Click Downloaders
Click Black hole and browse to your watch couchpotato directory.
Click Renamer and match my settings
Click Metadata and match my settings
Now that everything is configured you can add TV shows to Sonarr and movies to Couchpotato and watch the magic. You can update Sonarr using apt-get. CouchPotato will notify you in it's interface when it has updates available. You can keep ruTorrent up to date by running the update-rutorrent script again. If rTorrent releases an update that you want to install, just follow the install sections of this guide again with the new files for xmlrpc, libtorrent and rTorrent.
Enjoy 100% automated TV and movie downloading!
These are some additional things you can do that make this setup even better.
Both Sonarr and CouchPotato have the ability to notify you when they start a download and finish a download. My favorite provider, and the one I use, is Pushover. Pushover supports both iOS and Android and is simply a one time purchase rather than a monthly subscription.
Click Settings -> Connect. Check Pushover (or your provider of choice) and configure the settings.
Click the gear cog -> Settings -> Notifications. Check Pushover (or your provider of choice) and configure the settings.
Now you will receive a notification when ever a show or movie starts and finishes downloading.
Now that everything is setup, you'll probably find yourself wanting to access these interfaces from your mobile device. I have an iPhone, so all the screenshots will be from that, but since these are all webapps, this should work from any device.
A mobile plugin was created by zebraxxl, but it appears he has abandoned it. I have created a fork of rutorrentMobile and made a number of enhancements.
The update-rutorrent script is set to automatically install this plugin so it should already be installed. Now from your mobile browser, browse to https://yourdomain.com/rutorrent and you should see the mobile interface for rutorrent. Add to your mobile home screen to create a web app.
Sonarr has a responsive design that is very functional on a mobile device. From your mobile browser, browse to https://yourdomain.com/sonarr and you should see the interface for Sonarr. Add to your mobile home screen to create a web app.
There is nothing special required for CouchPotato. Just from your mobile browser, browse to https://yourdomain.com/couchpotato and you should see the mobile interface for CouchPotato. Add to your mobile home screen to create a web app.
If you haven't heard about BitTorrent Sync yet, go read about it. It is awesome! It's like Dropbox, but instead of syncing to the cloud first, the folders sync from Peer to Peer. We can set up BitTorrent Sync on our watch directory so that we are able to drop .torrent files into those directories from any device. On iOS for instance, you can download a .torrent file in Safari and then use the Open with... option to place the file in one of the watch folders, depending on the category. Then BitTorrent Sync will sync that file to all the Peers connected to it, includng our Ubuntu server, which means the .torrent file will be downloaded to the correct watch folder and picked up by ruTorrent immediately!
cd ~
wget https://download-cdn.getsyncapp.com/stable/linux-x64/BitTorrent-Sync_x64.tar.gz
sudo tar xvzf BitTorrent-Sync_x64.tar.gz -C /usr/local/bin/ btsync
rm BitTorrent-Sync_x64.tar.gz
mkdir ~/.config/btsync
btsync --dump-sample-config > ~/.config/btsync/config.json
sudo wget https://raw.github.com/xombiemp/ultimate-torrent-setup/master/btsync.conf -P /etc/init/
Edit /etc/init/btsync.conf and change the three occurrences of the following to your user name:
YOURUSER
Edit ~/.config/btsync/config.json Change the following to what you want:
"device_name": "My Sync Device"
Uncomment and change the following to /home/YOURUSER/.config/btsync/
"storage_path" : "/home/user/.sync"
Add the following to /etc/apache2/sites-available/apache-portal.conf under the <VirtualHost *:443> section and change the SessionCryptoPassphrase to what the others are.
<Location /btsync>
Require valid-user
AuthType form
AuthFormProvider file
AuthFormLoginSuccessLocation /btsync
AuthUserFile "/etc/apache2/passwd"
AuthName "My Login"
Session On
SessionMaxAge 1800
SessionCookieName session path=/
SessionCryptoPassphrase CHANGEME
ErrorDocument 401 /login.html
ProxyPass http://localhost:8888
ProxyPassReverse http://localhost:8888
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
</Location>
and add this under the <VirtualHost *:443> section
Redirect permanent /gui /btsync/gui
sudo service btsync start
sudo service apache2 restart
Now browse to https://yourdomain.com/btsync
Click continue with out filling in a username or password. Accept the agreement and click continue. Click This is my first Sync 2.0 device, finally click Create Identity.
Click the Add Folder button:
Browse to your watch directory. In our example it is /data/torrent/watch/. Then click the Open button.
Now click the 3 dots menu next to the folder and click Preferences:
Configure it how you want. This is how I have mine configured.
Now you can click the gear cog -> My Devices to add your desktop and any mobile devices you want.
When you download a torrent click the Open in BitTorrent Sync option and then the BitTorrent Sync app will launch.
Just browse to the correct watch folder, based on the category of torrent, and then it will sync back to your Ubuntu server and be picked up and started immediately by ruTorrent and receive the correct label based on the folder you placed it in.
</div>