#!/bin/bash
function write_systemD_init() {
cat > /etc/systemd/system/rtorrent.service << EOF
[Unit]
Description=rTorrent
After=network.target
[Service]
User=rtorrent
Type=forking
KillMode=none
ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/local/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/local/bin/rtorrent
WorkingDirectory=%h
[Install]
WantedBy=default.target
EOF
cat > /etc/systemd/system/flood.service << EOF
[Unit]
Description=Flood rTorrent WebUI
After=network.target
[Service]
WorkingDirectory=/home/rtorrent/flood
ExecStart=/usr/bin/npm start --production /home/rtorrent/flood
User=flood
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable rtorrent.service
systemctl enable flood.service
systemctl start flood.service
systemctl start rtorrent.service
}
function write_systemV_init () {
cat > /etc/init.d/rtorrent.sh << EOF
#!/bin/bash
### BEGIN INIT INFO
# Provides: rtorrent
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop rtorrent daemon
### END INIT INFO
# ------------------------------------------------------------------------------
# /etc/init.d/rtorrent
#
# This script is an init script to run rtorrent in the background, using a
# screen. The script was designed and tested for Debian systems, but may work on
# other systems. On Debian, enable it by moving the script to
# "/etc/init.d/rtorrent" and issuing the command
# "update-rc.d rtorrent defaults 99"
# ____ _ _
# / ___| ___ ___ __| | |__ _____ __
# \___ \ / _ \/ _ \/ _` | '_ \ / _ \ \/ /
# ___) | __/ __/ (_| | |_) | (_) > <
# |____/ \___|\___|\__,_|_.__/ \___/_/\_\
#
# @see http://methvin.net/scripts/rtorrent
# @see http://tldp.org/LDP/abs/html/
# ------------------------------------------------------------------------------
## Username to run rtorrent under, make sure you have a .rtorrent.rc in the
## home directory of this user!
USER="rtorrent"
## Absolute path to the rtorrent binary.
RTORRENT="/usr/bin/rtorrent"
## Absolute path to the screen binary.
SCREEN="/usr/bin/screen"
## Name of the screen session, you can then "screen -r rtorrent" to get it back
## to the forground and work with it on your shell.
SCREEN_NAME="rtorrent"
## Absolute path to rtorrent's PID file.
PIDFILE="/var/run/rtorrent.pid"
## Absolute path to rtorrent's XMLRPC socket.
SOCKET="/var/run/rtorrent/rpc.socket"
## Check if the socket exists and if it exists delete it.
delete_socket() {
if [[ -e $SOCKET ]]; then
rm -f $SOCKET
fi
}
case "$1" in
## Start rtorrent in the background.
start)
echo "Starting rtorrent."
delete_socket
start-stop-daemon --start --background --oknodo \
--pidfile "$PIDFILE" --make-pidfile \
--chuid $USER \
--exec $SCREEN -- -DmUS $SCREEN_NAME $RTORRENT
if [[ $? -ne 0 ]]; then
echo "Error: rtorrent failed to start."
exit 1
fi
echo "rtorrent started successfully."
;;
## Stop rtorrent.
stop)
echo "Stopping rtorrent."
start-stop-daemon --stop --oknodo --pidfile "$PIDFILE"
if [[ $? -ne 0 ]]; then
echo "Error: failed to stop rtorrent process."
exit 1
fi
delete_socket
echo "rtorrent stopped successfully."
;;
## Restart rtorrent.
restart)
"$0" stop
sleep 1
"$0" start || exit 1
;;
## Print usage information if the user gives an invalid option.
*)
echo "Usage: $0 [start|stop|restart]"
exit 1
;;
esac
EOF
}
if [ "${1}" -eq "" ]; then
SERVERNAME="localhost"
else
SERVERNAME="${1}"
fi
apt install -y build-essential subversion autoconf g++ gcc curl comerr-dev pkg-config cfv libtool libssl-dev libncurses5-dev ncurses-term libsigc++-2.0-dev libcppunit-dev libcurl3 libcurl4-openssl-dev git ffmpeg mediainfo screen
cd /tmp
svn checkout http://svn.code.sf.net/p/xmlrpc-c/code/stable xmlrpc-c
cd xmlrpc-c/
./configure
make -j $(nproc)
make install
cd /tmp
git clone https://github.com/rakshasa/libtorrent.git
cd libtorrent
git checkout `git tag | tail -1`
./autogen.sh
./configure
make -j $(nproc)
make install
cd /tmp
git clone https://github.com/rakshasa/rtorrent.git
cd rtorrent
git checkout `git tag | tail -1`
./autogen.sh
./configure --with-xmlrpc-c
make -j $(nproc)
make install
ldconfig
#nginx mainline repository
cat >> /etc/apt/sources.list << EOF
deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx
EOF
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
apt update
apt install nginx -y
mkdir -p /etc/nginx/conf.d/
cat > /etc/nginx/conf.d/seedbox.conf << EOF
server {
listen 80;
server_name seedbox.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name $SERVERNAME
ssl on;
ssl_certificate /etc/letsencrypt/live/seedbox.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/seedbox.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/seedbox.example.com/chain.pem;
add_header Strict-Transport-Security "max-age=30";
ssl_protocols TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AESGCM:EECDH+AES;
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Requires nginx >= 1.5.9
ssl_stapling on; # Requires nginx >= 1.3.7
ssl_stapling_verify on; # Requires nginx => 1.3.7
ssl_prefer_server_ciphers on;
ssl_session_timeout 5m;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
location / {
client_max_body_size 1024m;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_request_buffering off;
proxy_http_version 1.1;
proxy_pass http://localhost:3000;
}
}
EOF
adduser --disabled-password rtorrent
mkdir -p /home/rtorrent/{downloads,.session}
chmod 775 -R /home/rtorrent
chown rtorrent:rtorrent -R /home/rtorrent
cat > /home/rtorrent/.rtorrent.rc << EOF
# Download location for rTorrent, for me it is /media/data/downloads for you it can be /home/rtorrent/downloads or torrents or whatever
directory = /home/rtorrent/downloads
# Session location for rTorrent
session = /home/rtorrent/.session
# rTorrent port settings
port_range = 45000-65000
port_random = no
# Check the hash after download
check_hash = no
# DHT settings (mostly for public trackers)
dht = off
peer_exchange = no
# Authorize UDP trackers
use_udp_trackers = yes
# Enable encryption
encryption = allow_incoming, try_outgoing, enable_retry
# SCGI port for Flood, ruTorrent etc.
scgi_port = 127.0.0.1:5000
#This fixes weird Flood bug where uploading some .torrent files gives 500 error
network.xmlrpc.size_limit.set = 2M
EOF
chown rtorrent:rtorrent /home/rtorrent/.rtorrent.rc
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
apt install -y nodejs
cd /home/rtorrent
git clone https://github.com/jfurrow/flood.git
cd flood
cp config.template.js config.js
npm install --production
adduser --disabled-password flood
chown -R flood:flood /home/rtorrent/flood/