Last active
October 15, 2025 04:34
-
-
Save HaleTom/fe873dc2f3c5bd14f7418efefc2b91a8 to your computer and use it in GitHub Desktop.
Update aria2.conf with 20 "best" BitTorrent trackers
This file contains hidden or 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 | |
| # Update the bt-tracker= line in aria2.conf | |
| # Any bt-tracker= lines are removed and and a new one added at the bottom of the file | |
| # Updates at: https://gist.github.com/HaleTom/fe873dc2f3c5bd14f7418efefc2b91a8 | |
| # Inspiration: https://github.com/wuyuansushen/aria2c_TrackersList | |
| set -euo pipefail | |
| shopt -s failglob | |
| warn() { printf "%s: %s\n" "$0" "$*"; } | |
| die() { warn "$1"; exit 1; } | |
| conf=${XDG_CONFIG_HOME:-$HOME/.conifg}/aria2/aria2.conf | |
| url='https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt' | |
| tmp=$(mktemp -p /tmp) || die 'Cannot make temp file' | |
| cleanup() { rm -rf "$tmp"; } # Ensure tmp file is always removed, eg if we can't curl | |
| trap cleanup EXIT | |
| # Strip out any old bt-tracker= lines | |
| [ -e "$conf" ] || die "config file $conf does not exist" | |
| sed -E '/^[[:space:]]*bt-tracker/d' "$conf" >| "$tmp" | |
| trackers=$(curl --no-progress-meter "$url" | sed '/^$/d' | tr '\n' ',') \ | |
| || die "Couldn't get trackers list" >> "$tmp" | |
| printf 'bt-tracker=%s\n' "$trackers" >> "$tmp" | |
| mv "$tmp" "$conf" |
Does anyone have the
sed-fu to replace allbt-tracker=lines rather than delete and append?
yes. try using sed like this instead:
# Replace bt-tracker= lines
sed -i -E "/^[[:space:]]*bt-tracker=/c bt-tracker=$trackers" "$conf" >| $tmp || die "Failed to update $conf"There's a typo in line 14 (.conifg -> .config), thus breaking the script.
clearly this script hasn't even been tested if there's a typo in it.
#!/bin/bash
# Update the bt-tracker= line in aria2.conf
# Any bt-tracker= lines are removed and and a new one added at the bottom of the file
# Updates at: https://gist.github.com/HaleTom/fe873dc2f3c5bd14f7418efefc2b91a8
# Inspiration: https://github.com/wuyuansushen/aria2c_TrackersList
set -euo pipefail
shopt -s failglob
warn() { printf "%s: %s\n" "$0" "$*"; }
die() { warn "$1"; exit 1; }
# Replace this with the actual path to your aria2.conf file
conf=/etc/aria2/aria2.conf
url='https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt'
# tmp=$(mktemp -p /tmp) || die 'Cannot make temp file'
# cleanup() { rm -rf "$tmp"; } # Ensure tmp file is always removed, eg if we can't curl
# trap cleanup EXIT
# Strip out any old bt-tracker= lines
[ -e "$conf" ] || die "config file $conf does not exist"
trackers=$(curl --no-progress-meter "$url" | sed '/^$/d' | tr '\n' ',' | sed 's/,$//') \
|| die "Couldn't get trackers list"
cp "$conf" "$conf.bak" || die "Failed to backup $conf"
# If bt-tracker= line exists, replace it; otherwise, append a new line
if grep -q '^[[:space:]]*bt-tracker=' "$conf"; then
sed -i -E "/^[[:space:]]*bt-tracker=/c bt-tracker=$trackers" "$conf" || die "Failed to update $conf"
else
echo -e "\nbt-tracker=$trackers" >> "$conf" || die "Failed to append to $conf"
fiThis has been tested on my computer. Hope it helps.
@kitty314 thanks. ☺
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does anyone have the
sed-fu to replace allbt-tracker=lines rather than delete and append?