forked from ohhdemgirls/PlexInTheCloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08-rtorrent.sh
executable file
·135 lines (107 loc) · 3.64 KB
/
08-rtorrent.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
source vars
## INFO
# This script installs and configures rtorrent
##
#######################
# Pre-Install
#######################
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Execute 'sudo su' to swap to the root user."
exit 1
fi
#######################
# Dependencies
#######################
apt-get install -y tmux
#######################
# Install
#######################
apt-get install -y rtorrent
#######################
# Setup
#######################
mkdir -p /home/$username/rtorrent
#######################
# Configure
#######################
tee "/home/$username/.rtorrent.rc" > /dev/null <<EOF
# Maximum and minimum number of peers to connect to per torrent.
# rtorrent will connect aggressively until it reaches the minimum,
# but stop connecting to new clients when it reaches max.
min_peers = 40
max_peers = 150
# Same as above but for seeding completed torrents (-1 = same as downloading)
min_peers_seed = 250
max_peers_seed = 5000
# Maximum number of simultaneous uploads per torrent.
max_uploads = 30
# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 0
# Default directory to save the downloaded torrents.
directory = /home/$username/rutorrent/downloads
# Session folder used by rtorrent to store current data
session = /home/$username/rtorrent/session
session.use_lock.set = yes
# Run the rtorrent process as a daemon in the background
#system.daemon.set = true
# Stop torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=1024M
# Port range to use for listening.
port_range = $torrentPort-$torrentPort
# Start opening ports at a random position within the port range.
port_random = no
# Check hash for finished torrents to confirm that the files are correct
check_hash = yes
# Set whether the client should try to connect to UDP trackers.
use_udp_trackers = yes
# Allow encrypted connection and retry with encryption if it fails.
#encryption = allow_incoming,enable_retry,prefer_plaintext
encryption = allow_incoming,try_outgoing,enable_retry
# Disabled DHT and peer exchange. (You can remove this if you're only using public trackers)
dht = disable
peer_exchange = no
# Finally, the SCGI port rtorrent will be listening on, for communication via ruTorrent
scgi_port = 127.0.0.1:5040
#execute2 = {sh,-c,/usr/bin/php /var/www/rutorrent/php/initplugins.php $username &}
EOF
#######################
# Structure
#######################
mkdir -p /home/$username/rtorrent/session
mkdir -p /home/$username/rtorrent/downloads
#mkdir -p /home/$username/rtorrent/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'}
#######################
# Systemd Service File
#######################
tee "/etc/systemd/system/rtorrent.service" > /dev/null <<EOF
[Unit]
Description=rTorrent
Requires=network.target local-fs.target
[Service]
Type=oneshot
RemainAfterExit=yes
KillMode=none
User=$username
ExecStart=/usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent
ExecStop=/usr/bin/tmux send-keys -t rt:rtorrent C-q
[Install]
WantedBy=multi-user.target
EOF
#######################
# Permissions
#######################
chown -R $username:$username /home/$username/rtorrent
chown $username:$username /home/$username/.rtorrent.rc
chmod -R 0755 /home/$username/rtorrent
#######################
# Remote Access
#######################
ufw allow $torrentPort
#######################
# Autostart
#######################
systemctl daemon-reload
systemctl start rtorrent
systemctl enable rtorrent