Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fullaxx committed Mar 14, 2019
1 parent 2ec08b8 commit a4ba0eb
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ------------------------------------------------------------------------------
# Pull base image
FROM ubuntu:bionic
MAINTAINER Brett Kuskie <[email protected]>

# ------------------------------------------------------------------------------
# Set environment variables
ENV DEBIAN_FRONTEND noninteractive
ENV LANG C

# ------------------------------------------------------------------------------
# Install applications and clean up
RUN apt-get update && apt-get install -y --no-install-recommends \
rtorrent openvpn screen tmux locales && \
sed -e 's/# en_US.UTF-8/en_US.UTF-8/' -i /etc/locale.gen && locale-gen && \
apt-get clean && rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/*

# ------------------------------------------------------------------------------
# Prepare rtorrent directories
RUN mkdir -p \
/rtorrent/torrents \
/rtorrent/session \
/rtorrent/complete

# ------------------------------------------------------------------------------
# Install startup scripts
COPY app/*.sh /app/

# ------------------------------------------------------------------------------
# Configure rtorrent
COPY rtorrent.rc /usr/share/rtorrent/rtorrent.rc

# ------------------------------------------------------------------------------
# Identify Volumes
VOLUME /rtorrent/torrents
VOLUME /rtorrent/session

# ------------------------------------------------------------------------------
# Define default command
CMD ["/app/app.sh"]
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# rtorrent-openvpn
A docker container running rtorrent with openvpn
# A docker container running rtorrent with openvpn

## Base Docker Image
Ubuntu 18.04 (x64)

## Get the image from Docker Hub

docker pull fullaxx/rtorrent-openvpn

## Required Volume Options
Input: Drop your torrents in /srv/docker/rtorrent/autoload/

-v /srv/docker/rtorrent/autoload:/rtorrent/autoload

Output: Your downloaded data will reside here

-v /srv/docker/rtorrent/torrents:/rtorrent/torrents

## Optional Volume Options
Configuration: Any .ovpn files or a custom rtorrent.rc can be placed in /srv/docker/rtorrent/config/

-v /srv/docker/rtorrent/config:/rtorrent/config

Session State: Use this to save your session for fast restore/resume

-v /srv/docker/rtorrent/session:/rtorrent/session

## Run the image
Run the image using the default port without OpenVPN

docker run \
-v /srv/docker/rtorrent/autoload:/rtorrent/autoload \
-v /srv/docker/rtorrent/torrents:/rtorrent/torrents \
-it -p 49164:49164 fullaxx/rtorrent-openvpn

Run the image using the default port with OpenVPN \
Make sure that your myopenvpnconfig.ovpn exists in /srv/docker/rtorrent/config/

docker run --cap-add=NET_ADMIN --device /dev/net/tun \
-v /srv/docker/rtorrent/autoload:/rtorrent/autoload \
-v /srv/docker/rtorrent/torrents:/rtorrent/torrents \
-v /srv/docker/rtorrent/config:/rtorrent/config \
-v /srv/docker/rtorrent/session:/rtorrent/session \
-e OVPNCFG='myopenvpnconfig.ovpn' \
-e OVPNSLEEPTIME='4' \
-it -p 49164:49164 fullaxx/rtorrent-openvpn

## Build it locally using the github repository

docker build -t="fullaxx/rtorrent-openvpn" github.com/fullaxx/rtorrent-openvpn
18 changes: 18 additions & 0 deletions app/app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

bail()
{
echo "$1"
exit 1
}

/app/openvpn.sh || bail "openvpn startup failed!"

if [ -r /rtorrent/config/rtorrent.rc ]; then
cp /rtorrent/config/rtorrent.rc /root/.rtorrent.rc
else
cp /usr/share/rtorrent/rtorrent.rc /root/.rtorrent.rc
fi

# exec rtorrent -n -o import=/rtorrent/config/rtorrent.rc
exec rtorrent
8 changes: 8 additions & 0 deletions app/dns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

echo > /etc/resolv.conf
echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf
echo "nameserver 1.1.1.1" >> /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf
3 changes: 3 additions & 0 deletions app/down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/app/killswitch.sh
3 changes: 3 additions & 0 deletions app/killswitch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ps a | grep -v grep | grep rtorrent | awk '{print $1}' | xargs kill
14 changes: 14 additions & 0 deletions app/openvpn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

OVPNSLEEPTIME=${OVPNSLEEPTIME:-5}

# https://www.cyberciti.biz/faq/bash-shell-check-for-any-mp3-files-in-directory/
#shopt -s nullglob
#OVPNCFG=`ls -1 /rtorrent/config/*.ovpn | head -n1`
#shopt -u nullglob

if [ x"${OVPNCFG}" != "x" ]; then
openvpn --config /rtorrent/config/${OVPNCFG} --daemon \
--script-security 2 --up /app/up.sh --down /app/down.sh || exit 1
sleep ${OVPNSLEEPTIME}
fi
3 changes: 3 additions & 0 deletions app/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/app/dns.sh
84 changes: 84 additions & 0 deletions rtorrent.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
#max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
#max_uploads = 15

# Global upload and download rate in KiB. "0" for unlimited.
#download_rate = 0
#upload_rate = 0

# Default directory to save the downloaded torrents.
directory = /rtorrent/torrents/

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = /rtorrent/session/

# Watch a directory for new torrents
# and stop those that have been deleted.
schedule = watch_directory,5,5,load_start=/rtorrent/autoload/*.torrent
#schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
#schedule = low_diskspace,5,60,close_low_diskspace=100M

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket
# and outgoing connections is bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 49164-49164

# Start opening ports at a random position within the port range.
#port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no

# Set whether the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
#
# dht = auto

# UDP port to use for DHT.
#
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes

0 comments on commit a4ba0eb

Please sign in to comment.