Raspberry Pi VPN, Socks5 Proxy, Deluge, Jackett, MiniDLNA, Sonarr, Radarr, Lidarr. With USB Hard disk Samba Shares

This all started because i found the deluge sensor in home assistant and had to build my own torrent box but with all the added features i could hope for.

Hope you all like my latest project.

click here for Github wiki

Raspberry Pi + VPN, Socks5 Proxy, Deluge, Jackett, MiniDLNA, Sonarr, Radarr, Lidarr. With USB Hard disk Samba Shares.

Hardware Needed

  • Raspberry Pi 3B
  • USB Hard Drive

Services

  • Samba Share HDD
  • Torrent Server - Deluge
  • DLNA media server - MiniDLNA
  • Movie Torrent Server - Radarr
  • TV Torrent Server - Sonarr
  • Music Torrent Server - Lidarr
  • Torrent Provider Indexer TorzNAB Server - Jackett
  • VPN Secured Internet access for Downloading
  • Additional Netherlands based Socks5 Proxy support in Deluge via PIA
  • Watch Folder to drag and drop torrents into Deluge

Firstly a big thanks to techwiztime for the inspiration and tutorial for how I got this first part working
See:

Setting it up.

Download latest raspberry pi image available from raspbian. I have used in this tutorial Rasbian stretch Lite.

Format SD Card and burn the image using Win32diskimg or Etcher.
Remove SD card from reader and then reinsert card once more to see a list of files on the root of memory card.
Add a new file called ssh (with no extention) to the root of SD.
Insert the memory card into raspi and connect network cable and power in that order.
Login to PI using a SSH client e.g. Terminal or Putty.

sudo apt-get update

sudo apt-get upgrade

I’m using PIA (Private Internet Access) as my VPN of choice. It allows for Socks5 with Auth, really good for deluge and a really solid VPN Provider. See www.privateinternetaccess.com for plans and pricing.

Install Openvpn.

sudo apt install openvpn -y

cd /etc/openvpn

sudo wget https://www.privateinternetaccess.com/openvpn/openvpn.zip 

sudo unzip openvpn.zip

cd openvpn

sudo nano login.conf

Add 2 lines,
On the first line: your-vpn-login-user
On the Second line: your-vpn-password

login

Ctrl+x y enter

Modify file permissions.

Sudo chmod 400 login.conf

Copy the ovpn

sudo cp AU\ Sydney.ovpn Sydney.conf

Edit the newly created conf file

Sudo nano Sydney.conf

Look at the file and locate the line < auth-user pass >
Add the login.conf location to this line

auth-user-pass /etc/openvpn/login.conf

Also while in this file add the location of ssl cert by locating the lines < crl-verify > and < ca >

Crl-verify /etc/openvpn/crl.rsa.2048.pem
ca /etc/openvpn/crl.rsa.2048.pem

Ctrl+x y enter

Autostart the vpn at login.

Sudo nano /etc/default/openvpn

Under the last line add

AUTOSTART="Sydney"

Ctrl+x y enter

Reboot pi

sudo reboot

Check the ip of our pi to see if we are connected via VPN

curl ipinfo.io/ip

Your IP should be different from your real exernal ip you can check this by going to another pc and googling whats my ip.

Setup USB HDD for use with raspberry pi. Using EXT4 file system.

sudo parted /dev/sda

Press p

mktable msdos

Yes to continue

Setup EXT parition

mkpart primary ext4 0% 100%

Type p again

See partition on screen

sudo mkfs.ext4 /dev/sda

Y to continue

Create a mount point

sudo mkdir /mnt/torrents

Mount to check

sudo mount /dev/sda1 /mnt/torrents

Check drives mounted

df -h

See dev/sda1 is mounted

Auto mount on reboot

sudo nano /etc/fstab

After the last /dev entry add the following. Try keep formatting with spaces and tabs

/dev/sda1             /mnt/torrents            ext4          defaults      0             0

Ctrl+x y enter

Reboot

sudo reboot 

After reboot check to see if the USB HDD automatically booted

df -h 

Install and configure Deluge

You can simply install deluge from the terminal using the package manager.

sudo apt-get install deluge

You then need to start the daemon

sudo service deluged start

Then to interact with the daemon using the web ui you must start that

sudo service deluge-web start

Setup Mounts and USB Directories with Deluge.

Create mounts for deluge

sudo mkdir /mnt/torrents/downloading
sudo mkdir /mnt/torrents/completed
sudo mkdir /mnt/torrents/watch
sudo mkdir /mnt/torrents/backups

Open web browser and navigate to http://your-pi-address:8112

Login to deluge with the default password “deluge”

On the webpage Go to.
Preference
Downloads

Add the torrent folders as follows.

Back in putty (terminal) add the following media folders for completed files download from Radarr Sonarr Lidarr

sudo mkdir /mnt/torrents/MEDIA
sudo mkdir /mnt/torrents/MEDIA/movies
sudo mkdir /mnt/torrents/MEDIA/music
sudo mkdir /mnt/torrents/MEDIA/tv

Configure Deluge to Run on Startup

Before we leave the Deluge setup, there is one final detail to attend to. We need to set up the Deluge daemon and WebUI to run automatically when our Raspberry Pi boots up. To do so simply and without the fuss of editing more complicated init files and settings, we’ll simple annotate the rc.local file. Run the following command in a Terminal to do so.

sudo nano /etc/rc.local

With the rc.local file loaded, add the following lines to the end of the file. Note: you do not need to add the the second command ending in “deluge-web” if you are not using the WebGUI. This may also be a good place to add your VPN program, if you’re using one.

Start Deluge on boot:

sudo -u pi /usr/bin/python /usr/bin/deluged &
sudo -u pi /usr/bin/python /usr/bin/deluge-web &

Install Mono

Add the Mono repository to your system

The package repository hosts the packages you need, add it with the following commands.
Note: the packages should work on newer Raspbian versions too but we only test the ones listed below.

sudo apt install apt-transport-https dirmngr


sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF


echo "deb https://download.mono-project.com/repo/debian stable-raspbianstretch main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list


sudo apt update


sudo apt install mono-devel

The package mono-devel should be installed to compile code.

Install Sonar

Add Sonarr’s repository to your software source

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0xFDA5DFFC

sudo echo "deb http://apt.sonarr.tv/ master main" | sudo tee /etc/apt/sources.list.d/sonarr.list

Install/Update Sonarr

   sudo apt-get update
   sudo apt-get install nzbdrone

Start Sonarr

mono --debug /opt/NzbDrone/NzbDrone.exe

Open Browser http://localhost:8989

Change ownership of NzbDrone folder

sudo chown -R pi:pi /opt/NzbDrone

Startup for Sonarr

sudo nano /etc/systemd/system/sonarr.service

Add the following code.

[Unit]
Description=Sonarr Daemon
After=network.target
	
[Service]
User=pi
Restart=always
RestartSec=5
Type=simple
ExecStart=/usr/bin/mono /opt/NzbDrone/NzbDrone.exe
TimeoutStopSec=20
	
[Install]
WantedBy=multi-user.target

Save File CTRL+x y ENTER.

Enable Sonarr service

sudo systemctl enable sonarr

Start Sonarr Service

sudo service sonarr start

Install Radarr

grab the radarr release from here. Copy the link location then go back to PuTTy or your SSH client.

Change directory to /opt

cd /opt 

Download the Radarr release.

Sudo wget https://github.com/Radarr/Radarr/releases/download/v0.2.0.1120/Radarr.develop.0.2.0.1120.linux.tar.gz

Extract the release you just downloaded.

sudo tar -xvf Radarr.develop.0.2.0.1120.linux.tar.gz

This will extract the file into a folder called Radarr. Next change ownership of the directory to the pi user.

sudo chown -R pi:pi /opt/Radarr

Startup for Radarr

sudo nano /etc/systemd/system/radarr.service

Add the following code.

[Unit]
Description=Radarr Daemon
After=network.target

[Service]
User=pi
Restart=always
RestartSec=5
Type=simple
ExecStart=/usr/bin/mono --debug /opt/Radarr/Radarr.exe
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

CTRL+x y ENTER

sudo systemctl enable radarr

sudo service radarr start

Radarr Will now be accessable on your web browser at http://YOUR-WEB-ADDRESS:7878

MiniDLNA

MiniDLNA is a lightweight media server designed to support the DLNA and UPnP protocols. This works pretty nicely with almost any device you may want to consume media content on and it’s so lightweight it’s an ideal match for the Pi.
So, let’s get started. First, run a full update and then install the minidlna package.

apt-get update

apt-get upgrade

apt-get install minidlna

Once installed, we’ll go ahead and edit the configuration file as follows.

sudo nano /etc/minidlna.conf

media_dir=A,/mnt/torrents/MEDIA/music
    media_dir=P,/mnt/torrents/MEDIA/pictures
    media_dir=V,/mnt/torrents/MEDIA/movies
media_dir=V,/mnt/torrents/MEDIA/tv
friendly_name=Raspberry Pi
    inotify=yes

Fairly self explanitory, I hope. Set your directories, set a name for your media server, and ensure that the media library is automatically refreshed.
Now we start minidlna and we should have a working media server!

sudo service minidlna start

Upon the fist run, the media library will be built. This may take a while depending on how many files you have, once it’s done you shouldn’t have to do it again though.
Finally, ask minidlna to start up automatically upon boot.

sudo update-rc.d minidlna defaults

MiniDLNA streams 1080p to XBoxes, Playstations, Smart TVs and other computers

Install TorzNab Indexer - Jackett

Jackett works as a proxy server: it translates queries from apps (Sonarr, Radarr, SickRage, CouchPotato, Mylar, DuckieTV, etc) into tracker-site-specific http queries, parses the html response, then sends results back to the requesting software. This allows for getting recent uploads (like RSS) and performing searches. Jackett is a single repository of maintained indexer scraping & translation logic - removing the burden from other apps.

Install libcurl

sudo apt-get install libcurl4-openssl-dev

Download and extract the latest Jackett.Binaries.Mono.tar.gz release from the releases page and run Jackett using mono with the command mono --debug JackettConsole.exe.

Mono must be compiled with the Roslyn compiler (default), using MCS will cause “An error has occurred.” errors (See "an error has occurred" trying to load dashboard on QNAP after latest update · Issue #2704 · Jackett/Jackett · GitHub).

Aggregate indexers
A special “all” indexer is available at

 http://localhost:9117/api/v2.0/indexers/all/results/torznab/api

It will query all configured indexers and return the combined results.
To get all Jackett indexers including their capabilities you can use t=indexers on the all indexer. To get only configured/unconfigured indexers you can also add configured=true/false as query parameter.

Set startup

Request server for all users - Ombi

Add the apt repository to the apt sources list:

echo "deb [arch=amd64,armhf] http://repo.ombi.turd.me/stable/ jessie main" | sudo tee "/etc/apt/sources.list.d/ombi.list"

This repo is signed. This means packages get validated before installation. So, to safely download and install Ombi packages the Ombi key needs to be installed:

wget -qO - https://repo.ombi.turd.me/pubkey.txt | sudo apt-key add -

Now update the package list and install Ombi:

sudo apt update && sudo apt install ombi

sudo reboot

If no errors are shown, Ombi has been installed successfully and will automatically start at boot time.
Ombi should now be reachable on

 http://your-ip-address:5000

Packages in this repo use systemd, you can use the systemctl or the service command to start, stop, and restart Ombi.