mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-28 19:06:19 -05:00
Torrents reach the Internet only through a fail-closed VPN (WireGuard or OpenVPN, any provider), so peers never see a WROLPi's own address. - A network namespace (Pi/Debian) or the vpn container (Docker) with an nftables kill switch; NAT-PMP or fixed port forwarding. - qBittorrent inside it, sandboxed; torrents kept in config/torrents/. - Torrent download form, Torrents page, Share as torrent, nav warning, and VPN settings in both Controller UIs. - Help docs: Torrents, and The VPN for Torrents. QA'd on a Raspberry Pi with a real provider over WireGuard and OpenVPN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.4 KiB
Bash
Executable file
43 lines
1.4 KiB
Bash
Executable file
#!/bin/sh
|
|
# The tunnel and the torrent client in one container, so the client can never be left on a network the tunnel no
|
|
# longer guards (a container joined to another's network keeps its old, dead one when that container is recreated).
|
|
#
|
|
# qBittorrent starts only once the tunnel has installed its kill switch (it writes its first status after that), and
|
|
# runs as an unprivileged user with no capabilities. If either stops, the container stops, and Docker restarts both.
|
|
set -u
|
|
|
|
PROFILE=/profile
|
|
STATUS=/run/wrolpi-vpn/status.json
|
|
QBITTORRENT_UID=${QBITTORRENT_UID:-1000}
|
|
QBITTORRENT_GID=${QBITTORRENT_GID:-1000}
|
|
|
|
rm -f "${STATUS}"
|
|
python3 /app/tunnel.py run --resolv-conf /etc/resolv.conf &
|
|
TUNNEL=$!
|
|
|
|
while [ ! -f "${STATUS}" ]; do
|
|
if ! kill -0 "${TUNNEL}" 2>/dev/null; then
|
|
echo "The tunnel stopped before its kill switch was in place" >&2
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
setpriv --reuid="${QBITTORRENT_UID}" --regid="${QBITTORRENT_GID}" --clear-groups \
|
|
--inh-caps=-all --bounding-set=-all --no-new-privs \
|
|
env HOME="${PROFILE}" sh -c "python3 /app/qbittorrent_prepare.py --profile ${PROFILE} \
|
|
&& exec qbittorrent-nox --confirm-legal-notice --profile=${PROFILE}" &
|
|
QBITTORRENT=$!
|
|
|
|
stop() {
|
|
kill "${QBITTORRENT}" "${TUNNEL}" 2>/dev/null
|
|
wait
|
|
}
|
|
trap 'stop; exit 0' TERM INT
|
|
|
|
while kill -0 "${TUNNEL}" 2>/dev/null && kill -0 "${QBITTORRENT}" 2>/dev/null; do
|
|
sleep 2
|
|
done
|
|
echo "The tunnel or qBittorrent stopped; stopping both" >&2
|
|
stop
|
|
exit 1
|