45 lines
1.1 KiB
Bash
45 lines
1.1 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
aria2_conf="${1:-/config/aria2.conf}"
|
|
tracker_url="${CUSTOM_TRACKER_URL:-https://trackerslist.com/all_aria2.txt}"
|
|
tmp_file="$(mktemp)"
|
|
|
|
cleanup() {
|
|
rm -f "${tmp_file}" "${tmp_file}.conf"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
echo "[INFO] Updating BT trackers from ${tracker_url}"
|
|
|
|
if ! curl -fsSL --connect-timeout 10 --max-time 20 "${tracker_url}" -o "${tmp_file}"; then
|
|
echo "[WARN] Failed to download tracker list from ${tracker_url}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
trackers="$(
|
|
sed 's/\r$//' "${tmp_file}" |
|
|
awk 'NF {print}' |
|
|
paste -sd, -
|
|
)"
|
|
|
|
if [ -z "${trackers}" ]; then
|
|
echo "[WARN] Tracker list is empty" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if grep -q '^bt-tracker=' "${aria2_conf}"; then
|
|
awk -v value="bt-tracker=${trackers}" '
|
|
BEGIN { replaced = 0 }
|
|
/^bt-tracker=/ { print value; replaced = 1; next }
|
|
{ print }
|
|
END { if (!replaced) print value }
|
|
' "${aria2_conf}" > "${tmp_file}.conf"
|
|
else
|
|
cp "${aria2_conf}" "${tmp_file}.conf"
|
|
printf '\nbt-tracker=%s\n' "${trackers}" >> "${tmp_file}.conf"
|
|
fi
|
|
|
|
cat "${tmp_file}.conf" > "${aria2_conf}"
|
|
echo "[INFO] Tracker file updated."
|