Update install_rtorrent.py

This commit is contained in:
gru
2026-05-14 08:40:44 +02:00
parent 804f150983
commit decce46378

View File

@@ -15,8 +15,8 @@ DEFAULT_USER = "rtorrent"
DEFAULT_GROUP = "rtorrent" DEFAULT_GROUP = "rtorrent"
DEFAULT_HOME = "/home/rtorrent" DEFAULT_HOME = "/home/rtorrent"
DEFAULT_BASE_DIR = "/opt/rtorrent_build" DEFAULT_BASE_DIR = "/opt/rtorrent_build"
DEFAULT_LIBTORRENT_REF = "v0.15.7" DEFAULT_LIBTORRENT_REF = "v0.16.11"
DEFAULT_RTORRENT_REF = "v0.15.7" DEFAULT_RTORRENT_REF = "v0.16.11"
DEFAULT_XMLRPC_REF = "latest-stable" DEFAULT_XMLRPC_REF = "latest-stable"
DEFAULT_CARES_REF = "1.34.6" DEFAULT_CARES_REF = "1.34.6"
DEFAULT_CURL_REF = "8.19.0" DEFAULT_CURL_REF = "8.19.0"
@@ -507,22 +507,23 @@ WantedBy=multi-user.target
run(["systemctl", "daemon-reload"]) run(["systemctl", "daemon-reload"])
def write_rtorrent_config(user_home, username): def build_rtorrent_config_content(username, scgi_port, torrent_port):
config_path = Path(user_home) / ".rtorrent.rc" return f"""
config_content = f"""
## https://git.linuxiarz.pl/gru/tools_scripts/_edit/master/install_rtorrent.py ## https://git.linuxiarz.pl/gru/tools_scripts/_edit/master/install_rtorrent.py
directory = /home/{username}/downloads # Generated by install_rtorrent.py
session = /home/{username}/.session
port_random = yes
encoding_list = UTF-8
execute.nothrow = chmod,777,/home/rtorrent/downloads directory.default.set = /home/{username}/downloads
network.scgi.open_port = 127.0.0.1:5000 session.path.set = /home/{username}/.session
network.port_range.set = 51300-51310 encoding.add = UTF-8
network.scgi.open_port = 127.0.0.1:{scgi_port}
network.port_range.set = {torrent_port}-{torrent_port}
network.port_random.set = no network.port_random.set = no
network.bind_address.set = 0.0.0.0 network.bind_address.ipv4.set = 0.0.0.0
system.file.allocate.set = 1
system.file.allocate.set = 0
system.umask.set = 0022 system.umask.set = 0022
dht.mode.set = disable dht.mode.set = disable
protocol.pex.set = no protocol.pex.set = no
trackers.use_udp.set = no trackers.use_udp.set = no
@@ -530,19 +531,36 @@ protocol.encryption.set = allow_incoming,enable_retry,prefer_plaintext
schedule2 = tied_directory,6,5,start_tied= schedule2 = tied_directory,6,5,start_tied=
schedule2 = untied_directory,7,5,stop_untied= schedule2 = untied_directory,7,5,stop_untied=
schedule2 = session_save,600,1800,((session.save)) schedule2 = session_save,300,300,((session.save))
schedule2 = watch_directory,60,60,load.normal=/home/{username}/watch/*.torrent
ratio.max.set = -1 ratio.max.set = -1
network.xmlrpc.size_limit.set = 33554432 network.xmlrpc.size_limit.set = 33554432
network.http.max_open.set = 32 network.http.max_open.set = 64
network.max_open_sockets.set = 2048 network.max_open_sockets.set = 8192
network.max_open_files.set = 4096 network.max_open_files.set = 32768
network.http.dns_cache_timeout.set = 3600 network.http.dns_cache_timeout.set = 0
pieces.memory.max.set = 1800M
""".lstrip()
""" def write_rtorrent_config(user_home, username, scgi_port, torrent_port, *, force_config=False):
config_path = Path(user_home) / ".rtorrent.rc"
config_content = build_rtorrent_config_content(username, scgi_port, torrent_port)
if config_path.exists() and not force_config:
print(f"Config already exists: {config_path}")
print("Not overwriting existing config. Proposed generated config would be:")
print("--- BEGIN PROPOSED .rtorrent.rc ---")
print(config_content, end="")
print("--- END PROPOSED .rtorrent.rc ---")
print("Use --force-config to overwrite the existing config.")
return False
config_path.write_text(config_content) config_path.write_text(config_content)
shutil.chown(config_path, user=username, group=username) shutil.chown(config_path, user=username, group=username)
print(f"Wrote config: {config_path}") print(f"Wrote config: {config_path}")
return True
def prepare_user_dirs(user_home, username): def prepare_user_dirs(user_home, username):
@@ -650,6 +668,9 @@ def build_parser():
parser.add_argument("--user", default=DEFAULT_USER, help=f"System user for the service (default: {DEFAULT_USER})") parser.add_argument("--user", default=DEFAULT_USER, help=f"System user for the service (default: {DEFAULT_USER})")
parser.add_argument("--group", default=DEFAULT_GROUP, help=f"System group for the service (default: {DEFAULT_GROUP})") parser.add_argument("--group", default=DEFAULT_GROUP, help=f"System group for the service (default: {DEFAULT_GROUP})")
parser.add_argument("--home", default=DEFAULT_HOME, help=f"Home directory for the service user (default: {DEFAULT_HOME})") parser.add_argument("--home", default=DEFAULT_HOME, help=f"Home directory for the service user (default: {DEFAULT_HOME})")
parser.add_argument("--scgi-port", type=int, default=DEFAULT_SCGI_PORT, help=f"SCGI listen port for rTorrent XMLRPC/SCGI (default: {DEFAULT_SCGI_PORT})")
parser.add_argument("--torrent-port", type=int, default=DEFAULT_TORRENT_PORT, help=f"Incoming BitTorrent listen port (default: {DEFAULT_TORRENT_PORT})")
parser.add_argument("--force-config", action="store_true", help="Overwrite existing ~/.rtorrent.rc. By default, existing config is left unchanged and the proposed changes are printed.")
parser.add_argument("--only-build", action="store_true", help="Only build and install libtorrent/rTorrent under /opt. Skip user, config and systemd.") parser.add_argument("--only-build", action="store_true", help="Only build and install libtorrent/rTorrent under /opt. Skip user, config and systemd.")
parser.add_argument("--yes", action="store_true", help="Assume yes for interactive prompts.") parser.add_argument("--yes", action="store_true", help="Assume yes for interactive prompts.")
parser.add_argument("--debug", action="store_true", help="Show full command output during build steps.") parser.add_argument("--debug", action="store_true", help="Show full command output during build steps.")
@@ -685,6 +706,7 @@ def main():
print(" - skip service user, config and systemd setup") print(" - skip service user, config and systemd setup")
else: else:
print(f" - configure systemd service for user '{args.user}'") print(f" - configure systemd service for user '{args.user}'")
print(f" - use SCGI port {args.scgi_port} and torrent port {args.torrent_port}")
if not prompt_yes_no("Continue?", default=True, assume_yes=args.yes): if not prompt_yes_no("Continue?", default=True, assume_yes=args.yes):
print("Aborted by user.") print("Aborted by user.")
@@ -718,7 +740,7 @@ def main():
if not args.only_build: if not args.only_build:
create_system_user(args.user, args.group, args.home, assume_yes=args.yes, debug=args.debug) create_system_user(args.user, args.group, args.home, assume_yes=args.yes, debug=args.debug)
prepare_user_dirs(args.home, args.user) prepare_user_dirs(args.home, args.user)
write_rtorrent_config(args.home, args.user) write_rtorrent_config(args.home, args.user, args.scgi_port, args.torrent_port, force_config=args.force_config)
runtime_lib_dirs = [f"{libtorrent_install}/lib", f"{xmlrpc_install}/lib"] runtime_lib_dirs = [f"{libtorrent_install}/lib", f"{xmlrpc_install}/lib"]
if curl_install: if curl_install:
runtime_lib_dirs.append(f"{curl_install}/lib") runtime_lib_dirs.append(f"{curl_install}/lib")