install scrpts
This commit is contained in:
@@ -18,6 +18,7 @@ DEFAULT_BASE_DIR = "/opt/rtorrent_build"
|
||||
DEFAULT_LIBTORRENT_REF = "v0.16.11"
|
||||
DEFAULT_RTORRENT_REF = "v0.16.11"
|
||||
DEFAULT_XMLRPC_REF = "latest-stable"
|
||||
DEFAULT_RPC_BACKEND = "tinyxml2"
|
||||
DEFAULT_CARES_REF = "1.34.6"
|
||||
DEFAULT_CURL_REF = "8.19.0"
|
||||
DEFAULT_SERVICE_PATH = "/etc/systemd/system/rtorrent@.service"
|
||||
@@ -458,34 +459,40 @@ def build_libtorrent(base_dir, libtorrent_ref, curl_install=None, cares_install=
|
||||
return install_dir, version
|
||||
|
||||
|
||||
def build_rtorrent(base_dir, rtorrent_ref, libtorrent_install, xmlrpc_install, curl_install=None, cares_install=None, *, debug=False):
|
||||
def build_rtorrent(base_dir, rtorrent_ref, libtorrent_install, rpc_backend, xmlrpc_install=None, curl_install=None, cares_install=None, *, debug=False):
|
||||
source_dir = Path(base_dir) / "rtorrent"
|
||||
install_dir = Path(base_dir) / "rtorrent_install"
|
||||
|
||||
clone_or_update_repo("https://github.com/rakshasa/rtorrent.git", source_dir, rtorrent_ref, debug=debug)
|
||||
|
||||
xmlrpc_config = find_xmlrpc_config(base_dir, xmlrpc_install)
|
||||
if not xmlrpc_config:
|
||||
raise InstallError(f"Could not find custom xmlrpc-c-config under {base_dir}.")
|
||||
if not str(xmlrpc_config).startswith(str(Path(xmlrpc_install).resolve())):
|
||||
raise InstallError(f"Wrong xmlrpc-c-config selected: {xmlrpc_config}. Expected one under: {xmlrpc_install}")
|
||||
prefixes = [libtorrent_install]
|
||||
xmlrpc_config = None
|
||||
if rpc_backend == "xmlrpc-c":
|
||||
xmlrpc_config = find_xmlrpc_config(base_dir, xmlrpc_install)
|
||||
if not xmlrpc_config:
|
||||
raise InstallError(f"Could not find custom xmlrpc-c-config under {base_dir}.")
|
||||
if not str(xmlrpc_config).startswith(str(Path(xmlrpc_install).resolve())):
|
||||
raise InstallError(f"Wrong xmlrpc-c-config selected: {xmlrpc_config}. Expected one under: {xmlrpc_install}")
|
||||
verify_xmlrpc_environment(xmlrpc_config, debug=debug)
|
||||
prefixes.append(xmlrpc_install)
|
||||
elif rpc_backend != "tinyxml2":
|
||||
raise InstallError(f"Unsupported RPC backend: {rpc_backend}")
|
||||
|
||||
verify_xmlrpc_environment(xmlrpc_config, debug=debug)
|
||||
|
||||
prefixes = [libtorrent_install, xmlrpc_install]
|
||||
if curl_install:
|
||||
prefixes.append(curl_install)
|
||||
if cares_install:
|
||||
prefixes.append(cares_install)
|
||||
env = build_env(*prefixes)
|
||||
env["PATH"] = f"{xmlrpc_config.parent}:" + env.get("PATH", "")
|
||||
env["XMLRPC_C_CONFIG"] = str(xmlrpc_config)
|
||||
if xmlrpc_config:
|
||||
env["PATH"] = f"{xmlrpc_config.parent}:" + env.get("PATH", "")
|
||||
env["XMLRPC_C_CONFIG"] = str(xmlrpc_config)
|
||||
|
||||
with Spinner("Preparing rTorrent build system", enabled=not debug):
|
||||
run(["autoreconf", "-i"], cwd=str(source_dir), env=env, debug=debug)
|
||||
run(["make", "distclean"], cwd=str(source_dir), env=env, check=False, debug=debug)
|
||||
|
||||
configure_cmd = ["./configure", f"--prefix={install_dir}", "--with-xmlrpc-c"]
|
||||
rpc_flag = "--with-xmlrpc-c" if rpc_backend == "xmlrpc-c" else "--with-xmlrpc-tinyxml2"
|
||||
configure_cmd = ["./configure", f"--prefix={install_dir}", rpc_flag]
|
||||
with Spinner("Configuring rTorrent", enabled=not debug):
|
||||
run(configure_cmd, cwd=str(source_dir), env=env, debug=debug)
|
||||
with Spinner("Building rTorrent", enabled=not debug):
|
||||
@@ -493,7 +500,9 @@ def build_rtorrent(base_dir, rtorrent_ref, libtorrent_install, xmlrpc_install, c
|
||||
with Spinner("Installing rTorrent", enabled=not debug):
|
||||
run(["make", "install"], cwd=str(source_dir), env=env, debug=debug, log_name=f"make_install_{Path(source_dir).name}")
|
||||
|
||||
runtime_prefixes = [libtorrent_install, xmlrpc_install]
|
||||
runtime_prefixes = [libtorrent_install]
|
||||
if rpc_backend == "xmlrpc-c" and xmlrpc_install:
|
||||
runtime_prefixes.append(xmlrpc_install)
|
||||
if curl_install:
|
||||
runtime_prefixes.append(curl_install)
|
||||
if cares_install:
|
||||
@@ -504,7 +513,7 @@ def build_rtorrent(base_dir, rtorrent_ref, libtorrent_install, xmlrpc_install, c
|
||||
return install_dir, version
|
||||
|
||||
|
||||
def install_symlinks(rtorrent_install, libtorrent_install, xmlrpc_install, curl_install=None, cares_install=None, *, debug=False):
|
||||
def install_symlinks(rtorrent_install, libtorrent_install, xmlrpc_install=None, curl_install=None, cares_install=None, *, debug=False):
|
||||
rtorrent_bin = Path(rtorrent_install) / "bin" / "rtorrent"
|
||||
if not rtorrent_bin.exists():
|
||||
raise InstallError(f"Compiled rtorrent binary not found: {rtorrent_bin}")
|
||||
@@ -515,7 +524,9 @@ def install_symlinks(rtorrent_install, libtorrent_install, xmlrpc_install, curl_
|
||||
usr_local_bin.symlink_to(rtorrent_bin)
|
||||
print(f"Symlinked {usr_local_bin} -> {rtorrent_bin}")
|
||||
|
||||
lib_dirs = [f"{libtorrent_install}/lib", f"{xmlrpc_install}/lib"]
|
||||
lib_dirs = [f"{libtorrent_install}/lib"]
|
||||
if xmlrpc_install:
|
||||
lib_dirs.append(f"{xmlrpc_install}/lib")
|
||||
if curl_install:
|
||||
lib_dirs.append(f"{curl_install}/lib")
|
||||
if cares_install:
|
||||
@@ -663,7 +674,7 @@ def print_optional_libs_explanation():
|
||||
print("Optional libraries:")
|
||||
print(" - c-ares: asynchronous DNS resolver. It helps avoid blocking DNS lookups and can improve tracker/DHT-heavy workloads when curl is built with AsynchDNS support.")
|
||||
print(" - curl: HTTP/HTTPS transfer library used by libtorrent for tracker/web requests. Building a fresh curl can provide newer TLS/HTTP fixes and c-ares based async DNS.")
|
||||
print(" - minimal build: builds only xmlrpc-c, libtorrent and rTorrent; it uses the system libraries already available on Debian.")
|
||||
print(" - minimal build: builds only libtorrent and rTorrent; it uses the system libraries already available on Debian/RHEL.")
|
||||
|
||||
|
||||
def resolve_optional_build_mode(args):
|
||||
@@ -741,26 +752,36 @@ def verify_libtorrent_curl_integration(base_dir, libtorrent_install, curl_instal
|
||||
print("c-ares is not visible in libtorrent ldd; this can still be valid when libcurl is resolved differently.")
|
||||
|
||||
|
||||
def verify_install(base_dir, rtorrent_install, libtorrent_install, xmlrpc_install, curl_install=None, cares_install=None, *, debug=False):
|
||||
def verify_install(base_dir, rtorrent_install, libtorrent_install, rpc_backend, xmlrpc_install=None, curl_install=None, cares_install=None, *, debug=False):
|
||||
rtorrent_bin = Path(rtorrent_install) / "bin" / "rtorrent"
|
||||
which_rtorrent = capture(["which", "rtorrent"], check=False, debug=debug) or "not found in PATH"
|
||||
print(f"Resolved rtorrent from PATH: {which_rtorrent}")
|
||||
|
||||
linked = capture(["ldd", str(rtorrent_bin)], check=True, debug=debug)
|
||||
for libname, expected in [("libtorrent", str(Path(libtorrent_install) / "lib")), ("xmlrpc", str(Path(xmlrpc_install) / "lib"))]:
|
||||
checks = [("libtorrent", str(Path(libtorrent_install) / "lib"))]
|
||||
if rpc_backend == "xmlrpc-c":
|
||||
checks.append(("xmlrpc", str(Path(xmlrpc_install) / "lib")))
|
||||
for libname, expected in checks:
|
||||
lines = [line for line in linked.splitlines() if libname in line]
|
||||
print_link_lines(f"Linked {libname} lines:", lines)
|
||||
if not any(expected in line for line in lines):
|
||||
raise InstallError(f"rtorrent does not appear to be linked against the compiled {libname} from {expected}.")
|
||||
if rpc_backend == "tinyxml2":
|
||||
tinyxml_lines = [line for line in linked.splitlines() if "tinyxml2" in line.lower()]
|
||||
print_link_lines("Linked tinyxml2 lines:", tinyxml_lines)
|
||||
if not tinyxml_lines:
|
||||
raise InstallError("rTorrent does not appear to be linked against tinyxml2.")
|
||||
|
||||
if curl_install:
|
||||
verify_libtorrent_curl_integration(base_dir, libtorrent_install, curl_install, cares_install, debug=debug)
|
||||
|
||||
env = build_env(libtorrent_install, xmlrpc_install, curl_install, cares_install)
|
||||
env = build_env(libtorrent_install, xmlrpc_install if rpc_backend == "xmlrpc-c" else None, curl_install, cares_install)
|
||||
env["LANG"] = "C"
|
||||
env["LC_ALL"] = "C"
|
||||
env["TERM"] = env.get("TERM", "xterm")
|
||||
ld_paths = [str(Path(libtorrent_install) / "lib"), str(Path(xmlrpc_install) / "lib")]
|
||||
ld_paths = [str(Path(libtorrent_install) / "lib")]
|
||||
if rpc_backend == "xmlrpc-c" and xmlrpc_install:
|
||||
ld_paths.append(str(Path(xmlrpc_install) / "lib"))
|
||||
if curl_install:
|
||||
ld_paths.append(str(Path(curl_install) / "lib"))
|
||||
if cares_install:
|
||||
@@ -777,11 +798,12 @@ def verify_install(base_dir, rtorrent_install, libtorrent_install, xmlrpc_instal
|
||||
|
||||
|
||||
def build_parser():
|
||||
parser = argparse.ArgumentParser(description="RHEL-compatible installer for xmlrpc-c + libtorrent + rTorrent under /opt with optional c-ares/custom curl support.")
|
||||
parser = argparse.ArgumentParser(description="RHEL-compatible installer for libtorrent + rTorrent under /opt. RPC defaults to tinyxml2; xmlrpc-c is optional.")
|
||||
parser.add_argument("--base-dir", default=DEFAULT_BASE_DIR, help=f"Base build/install directory (default: {DEFAULT_BASE_DIR})")
|
||||
parser.add_argument("--libtorrent-ref", default=DEFAULT_LIBTORRENT_REF, help=f"Git branch, tag or commit for libtorrent (default: {DEFAULT_LIBTORRENT_REF})")
|
||||
parser.add_argument("--rtorrent-ref", default=DEFAULT_RTORRENT_REF, help=f"Git branch, tag or commit for rtorrent (default: {DEFAULT_RTORRENT_REF})")
|
||||
parser.add_argument("--xmlrpc-ref", default=DEFAULT_XMLRPC_REF, help="xmlrpc-c source version or URL (default: latest-stable)")
|
||||
parser.add_argument("--xmlrpc-ref", default=DEFAULT_XMLRPC_REF, help="xmlrpc-c source version or URL. Used only with --with-xmlrpc-c (default: latest-stable)")
|
||||
parser.add_argument("--with-xmlrpc-c", action="store_true", help="Build rTorrent with classic xmlrpc-c instead of the default tinyxml2 XML-RPC backend.")
|
||||
parser.add_argument("--cares-ref", default=DEFAULT_CARES_REF, help=f"c-ares release version (default: {DEFAULT_CARES_REF})")
|
||||
parser.add_argument("--curl-ref", default=DEFAULT_CURL_REF, help=f"curl release version (default: {DEFAULT_CURL_REF})")
|
||||
parser.add_argument("--user", default=DEFAULT_USER, help=f"System user for the service (default: {DEFAULT_USER})")
|
||||
@@ -793,7 +815,7 @@ def build_parser():
|
||||
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; optional c-ares/curl remain disabled unless --with-curl or --with-cares is used.")
|
||||
parser.add_argument("--debug", action="store_true", help="Show full command output during build steps.")
|
||||
parser.add_argument("--minimal", "--core-only", action="store_true", help="Build only xmlrpc-c, libtorrent and rTorrent. Do not build c-ares or custom curl.")
|
||||
parser.add_argument("--minimal", "--core-only", action="store_true", help="Build only libtorrent and rTorrent. Do not build c-ares or custom curl.")
|
||||
parser.add_argument("--no-cares", "--without-cares", dest="no_cares", action="store_true", help="Do not build c-ares. This also disables custom curl integration.")
|
||||
parser.add_argument("--no-curl", "--without-curl", dest="no_curl", action="store_true", help="Do not build custom curl. Implies no c-ares integration for libtorrent.")
|
||||
parser.add_argument("--with-cares", action="store_true", help="Build c-ares and custom curl with asynchronous DNS support.")
|
||||
@@ -811,14 +833,20 @@ def main():
|
||||
|
||||
packages = [
|
||||
"gcc", "gcc-c++", "make", "pkgconf-pkg-config", "libtool", "autoconf", "automake", "git", "ca-certificates",
|
||||
"openssl-devel", "ncurses-devel", "expat-devel", "curl", "libcurl-devel", "tar", "gzip", "zlib-devel", "which",
|
||||
"openssl-devel", "ncurses-devel", "expat-devel", "tinyxml2-devel", "curl", "libcurl-devel", "tar", "gzip", "zlib-devel", "which",
|
||||
"patch", "diffutils", "findutils", "file", "redhat-rpm-config", "libstdc++-devel"
|
||||
]
|
||||
if args.use_cares:
|
||||
packages.extend(["cmake", "libpsl-devel", "brotli-devel", "libzstd-devel"])
|
||||
|
||||
print("This script will:")
|
||||
print(f" - build xmlrpc-c from '{args.xmlrpc_ref}'")
|
||||
args.rpc_backend = "xmlrpc-c" if args.with_xmlrpc_c else DEFAULT_RPC_BACKEND
|
||||
|
||||
print(f" - use rTorrent RPC backend: {args.rpc_backend}")
|
||||
if args.rpc_backend == "xmlrpc-c":
|
||||
print(f" - build xmlrpc-c from '{args.xmlrpc_ref}'")
|
||||
else:
|
||||
print(" - use system tinyxml2 for XML-RPC")
|
||||
print(f" - build libtorrent from '{args.libtorrent_ref}'")
|
||||
print(f" - build rtorrent from '{args.rtorrent_ref}'")
|
||||
if args.use_cares:
|
||||
@@ -827,7 +855,7 @@ def main():
|
||||
print(" - benefit: async DNS via c-ares and newer curl for HTTP/HTTPS tracker requests")
|
||||
else:
|
||||
print(" - minimal build: skip c-ares/custom curl")
|
||||
print(" - build only xmlrpc-c, libtorrent and rTorrent; use RHEL system libraries")
|
||||
print(" - build only libtorrent and rTorrent; use RHEL system libraries")
|
||||
print(f" - install everything under '{args.base_dir}'")
|
||||
if args.only_build:
|
||||
print(" - skip service user, config and systemd setup")
|
||||
@@ -842,7 +870,10 @@ def main():
|
||||
ensure_packages(packages, debug=args.debug)
|
||||
ensure_dir(args.base_dir)
|
||||
|
||||
xmlrpc_install, xmlrpc_version = build_xmlrpc_c(args.base_dir, args.xmlrpc_ref, debug=args.debug)
|
||||
xmlrpc_install = None
|
||||
xmlrpc_version = None
|
||||
if args.rpc_backend == "xmlrpc-c":
|
||||
xmlrpc_install, xmlrpc_version = build_xmlrpc_c(args.base_dir, args.xmlrpc_ref, debug=args.debug)
|
||||
|
||||
cares_install = None
|
||||
cares_version = None
|
||||
@@ -857,12 +888,12 @@ def main():
|
||||
args.base_dir, args.libtorrent_ref, curl_install=curl_install, cares_install=cares_install, debug=args.debug
|
||||
)
|
||||
rtorrent_install, rtorrent_version = build_rtorrent(
|
||||
args.base_dir, args.rtorrent_ref, libtorrent_install, xmlrpc_install, curl_install=curl_install,
|
||||
cares_install=cares_install, debug=args.debug
|
||||
args.base_dir, args.rtorrent_ref, libtorrent_install, args.rpc_backend, xmlrpc_install=xmlrpc_install,
|
||||
curl_install=curl_install, cares_install=cares_install, debug=args.debug
|
||||
)
|
||||
|
||||
install_symlinks(rtorrent_install, libtorrent_install, xmlrpc_install, curl_install=curl_install, cares_install=cares_install, debug=args.debug)
|
||||
verify_install(args.base_dir, rtorrent_install, libtorrent_install, xmlrpc_install, curl_install=curl_install, cares_install=cares_install, debug=args.debug)
|
||||
install_symlinks(rtorrent_install, libtorrent_install, xmlrpc_install=xmlrpc_install, curl_install=curl_install, cares_install=cares_install, debug=args.debug)
|
||||
verify_install(args.base_dir, rtorrent_install, libtorrent_install, args.rpc_backend, xmlrpc_install=xmlrpc_install, curl_install=curl_install, cares_install=cares_install, debug=args.debug)
|
||||
|
||||
if not args.only_build:
|
||||
create_system_user(args.user, args.group, args.home, assume_yes=args.yes, debug=args.debug)
|
||||
@@ -870,7 +901,9 @@ def main():
|
||||
bind_address_directive = rtorrent_bind_address_directive(args.rtorrent_ref, rtorrent_version)
|
||||
print(f"Using rTorrent bind address directive: {bind_address_directive}")
|
||||
write_rtorrent_config(args.home, args.user, args.scgi_port, args.torrent_port, bind_address_directive, force_config=args.force_config)
|
||||
runtime_lib_dirs = [f"{libtorrent_install}/lib", f"{xmlrpc_install}/lib"]
|
||||
runtime_lib_dirs = [f"{libtorrent_install}/lib"]
|
||||
if args.rpc_backend == "xmlrpc-c" and xmlrpc_install:
|
||||
runtime_lib_dirs.append(f"{xmlrpc_install}/lib")
|
||||
if curl_install:
|
||||
runtime_lib_dirs.append(f"{curl_install}/lib")
|
||||
if cares_install:
|
||||
@@ -881,7 +914,9 @@ def main():
|
||||
|
||||
print("\nBuild summary")
|
||||
print("-------------")
|
||||
print(f"xmlrpc-c: {xmlrpc_version}")
|
||||
print(f"rpc: {args.rpc_backend}")
|
||||
if args.rpc_backend == "xmlrpc-c":
|
||||
print(f"xmlrpc-c: {xmlrpc_version}")
|
||||
print(f"libtorrent: {libtorrent_version}")
|
||||
print(f"rtorrent: {rtorrent_version.splitlines()[0] if rtorrent_version else args.rtorrent_ref}")
|
||||
if args.use_cares:
|
||||
|
||||
Reference in New Issue
Block a user