diff --git a/update_tracker.py b/update_tracker.py index 91fed7e..eb51510 100755 --- a/update_tracker.py +++ b/update_tracker.py @@ -30,7 +30,7 @@ Examples: """ import json -import shutil +import subprocess import tempfile from pathlib import Path @@ -78,16 +78,23 @@ if __name__ == "__main__": # Create a NamedTemporaryFile and write all infohashes to it, one per line console.log("Creating temporary file to write infohashes to.") + with tempfile.NamedTemporaryFile() as ntf: with open(ntf.name, "w") as tf: tf.writelines(format_infohashes) - # Use shutil.copy to copy the infohashes file to the torrent tracker's config + # Use `sudo cp -f` to copy the infohashes file to the torrent tracker's config # directory, overwriting the whitelist.txt file. console.log( "Copying the temporary infohashes file to the torrent tracker's whitelist." ) - shutil.copy(ntf.name, "/etc/opentracker/whitelist.txt") + subprocess.run( + ["sudo", "cp", "-f", ntf.name, "/etc/opentracker/whitelist.txt"] + ) + + # Run `sudo systemctl restart opentracker.service` + console.log("Restarting opentracker.service") + subprocess.run(["sudo", "systemctl", "restart", "opentracker.service"]) # Reannounce all torrents in each qBittorrent instance to their trackers console.log("Reannouncing all torrents to their trackers.")