#!/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