Last active
May 20, 2018 15:51
-
-
Save jfeilbach/811b73e790c8072fc8c38fba7da3b10e to your computer and use it in GitHub Desktop.
replace_tracker.sh update transmission client torrents matching tracker string with new tracker URL
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 | |
# Borrowed from https://gist.github.com/Adadov/e352c05cf2f90031e5b9b623509a02da | |
GNU='/usr/local/bin/gsed' | |
if [ "$(uname)" == "Darwin" ]; then | |
echo "macOS detected. Using GNU sed instead of built-in." | |
if [[ -f "$GNU" ]]; then | |
echo "GNU sed found at $GNU." | |
SED=${GNU} | |
echo "sed is now set to $GNU" | |
else | |
echo "GNU sed not found. Exiting." | |
exit 1 | |
fi | |
else | |
echo "Not running macOS. We have a real sed." | |
SED=$(command -v sed) | |
fi | |
# Announce key | |
KEY="" | |
# Transmission daemon host | |
HOST="localhost:9091" | |
# Authentication to transmission-daemon (1 = True ; 0 = False) | |
AUTH=1 | |
TDUSER="admin" | |
TDPASS="secret" | |
if [ ${AUTH} -eq 1 ]; then | |
OPTS="${HOST} -n ${TDUSER}:${TDPASS}" | |
else | |
OPTS="${HOST}" | |
fi | |
# Tracker to replace | |
OLD="old.example.com" | |
# New tracker URL https:// | |
NEW="https://new.example.com" | |
if [ -z ${KEY+x} ]; then | |
echo "KEY is unset"; | |
exit 1 | |
else | |
echo "KEY is set to '$KEY'" | |
fi | |
# Get all torrents ID | |
LISTID=$(transmission-remote ${OPTS} -l | awk '{print $1}' | grep -E '^[0-9]+' | $SED -r -e 's/^([0-9]*).*$/\1/') | |
for id in ${LISTID}; do | |
echo "=========================" | |
TRACKS=$(transmission-remote ${OPTS} -t ${id} -it | grep -E 'Tracker [0-9]+') # Get all trackers | |
TRTEST=$(echo "${TRACKS}" | grep ${OLD}) # Is there the tracker to replace ? | |
if [ $? -eq 0 ]; then | |
TRKID=$(echo "${TRACKS}" | grep ${OLD} | $SED -r -e 's/Tracker ([0-9]+).*/\1/') # Get tracker ID | |
transmission-remote ${OPTS} -t ${id} -tr ${TRKID} | |
transmission-remote ${OPTS} -t ${id} -td "${NEW}/${KEY}/announce" | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment