#!/usr/bin/env bash set -euo pipefail # One-command installer for rTorrent + pyTorrent on Arch Linux. # Arch uses current repository packages by default. Source build is opt-in. if [[ "${EUID}" -ne 0 ]]; then echo "Run as root: sudo $0" >&2 exit 1 fi SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)" RTORRENT_USER="${RTORRENT_USER:-rtorrent}" RTORRENT_HOME="${RTORRENT_HOME:-/home/${RTORRENT_USER}}" RTORRENT_BASE_DIR="${RTORRENT_BASE_DIR:-/opt/rtorrent_build}" RTORRENT_SCGI_PORT="${RTORRENT_SCGI_PORT:-5000}" RTORRENT_SCGI_BACKEND="${RTORRENT_SCGI_BACKEND:-tcp}" RTORRENT_SCGI_SOCKET="${RTORRENT_SCGI_SOCKET:-/run/rtorrent/rtorrent.sock}" RTORRENT_SCGI_PROXY_LISTEN="${RTORRENT_SCGI_PROXY_LISTEN:-127.0.0.1:5050}" RTORRENT_SCGI_PROXY_TOKEN="${RTORRENT_SCGI_PROXY_TOKEN:-}" RTORRENT_TORRENT_PORT="${RTORRENT_TORRENT_PORT:-51300}" RTORRENT_REF="${RTORRENT_REF:-v0.16.11}" LIBTORRENT_REF="${LIBTORRENT_REF:-v0.16.11}" PYTORRENT_APP_DIR="${PYTORRENT_APP_DIR:-/opt/pytorrent}" PYTORRENT_PORT="${PYTORRENT_PORT:-8090}" PYTORRENT_BASE_URL="${PYTORRENT_BASE_URL:-http://127.0.0.1:${PYTORRENT_PORT}}" PYTORRENT_PROFILE_NAME="${PYTORRENT_PROFILE_NAME:-Local rTorrent}" PYTORRENT_API_TOKEN="${PYTORRENT_API_TOKEN:-}" PYTORRENT_SERVICE_NAME="${PYTORRENT_SERVICE_NAME:-pytorrent}" PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-}" RTORRENT_BUILD_FROM_SOURCE="${RTORRENT_BUILD_FROM_SOURCE:-0}" RTORRENT_FORCE_CONFIG="${RTORRENT_FORCE_CONFIG:-1}" normalize_scgi_settings() { case "${RTORRENT_SCGI_BACKEND}" in tcp|unix) ;; *) echo "Invalid RTORRENT_SCGI_BACKEND: ${RTORRENT_SCGI_BACKEND}" >&2; exit 1 ;; esac if [[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]]; then if [[ -z "${RTORRENT_SCGI_PROXY_TOKEN}" ]]; then RTORRENT_SCGI_PROXY_TOKEN="$(LC_ALL=C tr -dc 'A-Za-z0-9_-' &2 echo "Supported options: --build-rtorrent, --with-xmlrpc-c, --scgi-backend tcp|unix, --scgi-unix-socket, --rtorrent-socket PATH" >&2 exit 1 ;; esac done normalize_scgi_settings if [[ "${RTORRENT_WITH_XMLRPC_C:-0}" == "1" ]]; then RTORRENT_BUILD_FROM_SOURCE=1 RTORRENT_EXTRA_ARGS+=(--with-xmlrpc-c) fi command -v pacman >/dev/null 2>&1 || { echo "pacman is required on Arch Linux." >&2; exit 1; } pacman -Sy --noconfirm --needed ca-certificates curl tar gzip sudo python python-pip git rsync rtorrent ensure_rtorrent_user() { if ! getent group "${RTORRENT_USER}" >/dev/null; then groupadd --system "${RTORRENT_USER}" fi if ! id "${RTORRENT_USER}" >/dev/null 2>&1; then local shell="/usr/bin/nologin" [[ -x "${shell}" ]] || shell="/sbin/nologin" useradd --system --gid "${RTORRENT_USER}" --home-dir "${RTORRENT_HOME}" --create-home --shell "${shell}" "${RTORRENT_USER}" fi mkdir -p "${RTORRENT_HOME}/downloads" "${RTORRENT_HOME}/.session" "${RTORRENT_HOME}/watch" chown -R "${RTORRENT_USER}:${RTORRENT_USER}" "${RTORRENT_HOME}" } write_rtorrent_config() { local config="${RTORRENT_HOME}/.rtorrent.rc" if [[ -f "${config}" && "${RTORRENT_FORCE_CONFIG}" != "1" ]]; then echo "Keeping existing config: ${config}" return fi local scgi_line if [[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]]; then scgi_line="network.scgi.open_local = ${RTORRENT_SCGI_SOCKET} execute.nothrow = chmod,660,${RTORRENT_SCGI_SOCKET}" else scgi_line="network.scgi.open_port = 127.0.0.1:${RTORRENT_SCGI_PORT}" fi cat > "${config}" < /etc/systemd/system/rtorrent@.service <