Last active
December 14, 2022 01:41
-
-
Save flatmapthatshit/6ff8d1ac441092b33339890b5145de3a to your computer and use it in GitHub Desktop.
Alternative to https://github.com/binhex/arch-rtorrentvpn/blob/master/run/nobody/rutorrent.sh that works when ENABLE_RPC2=no
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# if rtorrent is already running then use xmlrpc to reconfigure | |
if [[ "${rtorrent_running}" == "true" ]]; then | |
# useful for debug and finding valid methods | |
#rtxmlrpc system.listMethods | |
# note '' is required? as first parameter for subsequent rxmlrpc commands | |
# set new value for incoming port | |
if rtxmlrpc network.port_range.set '' "${VPN_INCOMING_PORT}-${VPN_INCOMING_PORT}"; then | |
# set rtorrent port to current vpn port (used when checking for changes on next run) | |
rtorrent_port="${VPN_INCOMING_PORT}" | |
fi | |
# set new value for bind to vpn tunnel ip | |
# note this must come AFTER the port has been changed, otherwise the port change does not take effect | |
if rtxmlrpc network.bind_address.set '' "${vpn_ip}"; then | |
# set rtorrent ip to current vpn ip (used when checking for changes on next run) | |
rtorrent_ip="${vpn_ip}" | |
fi | |
# set new value for ip address sent to tracker | |
rtxmlrpc network.local_address.set '' "${external_ip}" | |
# set new value for dht port (same as incoming port) | |
rtxmlrpc dht.port.set '' "${VPN_INCOMING_PORT}" | |
else | |
echo "[info] Removing any rTorrent session lock files left over from the previous run..." | |
rm -f /config/rtorrent/session/*.lock | |
echo "[info] Attempting to start rTorrent..." | |
if [[ "${VPN_ENABLED}" == "yes" ]]; then | |
if [[ "${VPN_PROV}" == "pia" && -n "${VPN_INCOMING_PORT}" ]]; then | |
# run tmux attached to rTorrent (daemonized, non-blocking), specifying listening interface and port | |
/usr/bin/script /home/nobody/typescript --command "/usr/bin/tmux new-session -d -s rt -n rtorrent /usr/bin/rtorrent -b ${vpn_ip} -p ${VPN_INCOMING_PORT}-${VPN_INCOMING_PORT} -o ip=${external_ip} -o dht_port=${VPN_INCOMING_PORT}" | |
else | |
# run tmux attached to rTorrent (daemonized, non-blocking), specifying listening interface | |
/usr/bin/script /home/nobody/typescript --command "/usr/bin/tmux new-session -d -s rt -n rtorrent /usr/bin/rtorrent -b ${vpn_ip} -o ip=${external_ip}" | |
fi | |
else | |
# run tmux attached to rTorrent (daemonized, non-blocking) | |
/usr/bin/script /home/nobody/typescript --command "/usr/bin/tmux new-session -d -s rt -n rtorrent /usr/bin/rtorrent" | |
fi | |
# make sure process rtorrent DOES exist | |
retry_count=30 | |
while true; do | |
if ! pgrep -x "rtorrent main" > /dev/null; then | |
retry_count=$((retry_count-1)) | |
if [ "${retry_count}" -eq "0" ]; then | |
echo "[warn] Wait for rTorrent process to start aborted, too many retries" ; return 1 | |
else | |
if [[ "${DEBUG}" == "true" ]]; then | |
echo "[debug] Waiting for rTorrent process to start..." | |
fi | |
sleep 1s | |
fi | |
else | |
echo "[info] rTorrent process started" | |
break | |
fi | |
done | |
echo "[info] Waiting for rTorrent process to start listening on port 5000..." | |
while [[ $(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".5000"') == "" ]]; do | |
sleep 0.1 | |
done | |
echo "[info] rTorrent process listening on port 5000" | |
fi | |
# set rtorrent port to current vpn port (used when checking for changes on next run) | |
rtorrent_port="${VPN_INCOMING_PORT}" | |
# set rtorrent ip to current vpn ip (used when checking for changes on next run) | |
rtorrent_ip="${vpn_ip}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment