127 lines
3.8 KiB
Bash
Executable File
127 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# One-command installer for rTorrent + pyTorrent on Debian/Ubuntu.
|
|
# Notes:
|
|
# - rTorrent is built as a minimal v0.16.11 install by default.
|
|
# - pyTorrent is configured through its HTTP API after the service starts.
|
|
|
|
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_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:-scgi://127.0.0.1:${RTORRENT_SCGI_PORT}}"
|
|
|
|
export PYTORRENT_APP_DIR PYTORRENT_PORT PYTORRENT_SERVICE_NAME PYTORRENT_API_TOKEN
|
|
|
|
install_debian_stack_prerequisites() {
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update
|
|
apt-get install -y --no-install-recommends \
|
|
ca-certificates \
|
|
curl \
|
|
tar \
|
|
gzip \
|
|
sudo \
|
|
python3 \
|
|
python3-venv \
|
|
python3-pip \
|
|
build-essential \
|
|
pkg-config \
|
|
libtool \
|
|
autoconf \
|
|
automake \
|
|
git \
|
|
make \
|
|
gcc \
|
|
g++ \
|
|
libssl-dev \
|
|
libncurses-dev \
|
|
libncurses5-dev \
|
|
libncursesw5-dev \
|
|
libexpat1-dev \
|
|
libcurl4-openssl-dev \
|
|
libxml2-dev \
|
|
libreadline-dev \
|
|
zlib1g-dev \
|
|
bison \
|
|
flex \
|
|
m4 \
|
|
gettext \
|
|
texinfo \
|
|
patch \
|
|
diffutils \
|
|
file \
|
|
procps \
|
|
xz-utils
|
|
}
|
|
|
|
install_debian_stack_prerequisites
|
|
|
|
RTORRENT_INSTALL_ARGS=(
|
|
--yes
|
|
--minimal
|
|
)
|
|
if [[ "${PYTORRENT_DEBUG_INSTALL:-0}" == "1" ]]; then
|
|
RTORRENT_INSTALL_ARGS+=(--debug)
|
|
fi
|
|
|
|
python3 "${SCRIPT_DIR}/install_rtorrent.py" \
|
|
"${RTORRENT_INSTALL_ARGS[@]}" \
|
|
--force-config \
|
|
--base-dir "${RTORRENT_BASE_DIR}" \
|
|
--user "${RTORRENT_USER}" \
|
|
--group "${RTORRENT_USER}" \
|
|
--home "${RTORRENT_HOME}" \
|
|
--scgi-port "${RTORRENT_SCGI_PORT}" \
|
|
--torrent-port "${RTORRENT_TORRENT_PORT}" \
|
|
--rtorrent-ref "${RTORRENT_REF}" \
|
|
--libtorrent-ref "${LIBTORRENT_REF}"
|
|
|
|
cd "${PROJECT_DIR}"
|
|
bash "${PROJECT_DIR}/scripts/install_debian_ubuntu.sh"
|
|
|
|
if [[ -f "${PYTORRENT_APP_DIR}/.env" ]]; then
|
|
python3 - "${PYTORRENT_APP_DIR}/.env" <<'PY'
|
|
from pathlib import Path
|
|
import secrets
|
|
import sys
|
|
path = Path(sys.argv[1])
|
|
text = path.read_text()
|
|
if "PYTORRENT_SECRET_KEY=change-me" in text:
|
|
text = text.replace("PYTORRENT_SECRET_KEY=change-me", "PYTORRENT_SECRET_KEY=" + secrets.token_urlsafe(48))
|
|
path.write_text(text)
|
|
PY
|
|
chown "${PYTORRENT_USER:-pytorrent}:${PYTORRENT_USER:-pytorrent}" "${PYTORRENT_APP_DIR}/.env" || true
|
|
systemctl restart "${PYTORRENT_SERVICE_NAME}"
|
|
fi
|
|
|
|
CONFIGURE_ARGS=(
|
|
--base-url "${PYTORRENT_BASE_URL}"
|
|
--profile-name "${PYTORRENT_PROFILE_NAME}"
|
|
--scgi-url "${PYTORRENT_RTORRENT_SCGI_URL}"
|
|
)
|
|
if [[ -n "${PYTORRENT_API_TOKEN}" ]]; then
|
|
CONFIGURE_ARGS+=(--api-token "${PYTORRENT_API_TOKEN}")
|
|
fi
|
|
"${PYTORRENT_APP_DIR}/venv/bin/python" "${PYTORRENT_APP_DIR}/scripts/stack_installers/configure_pytorrent_api.py" "${CONFIGURE_ARGS[@]}"
|
|
|
|
echo "Done. pyTorrent: ${PYTORRENT_BASE_URL} | rTorrent SCGI: ${PYTORRENT_RTORRENT_SCGI_URL}"
|