Skip to content

Instantly share code, notes, and snippets.

@fpGHwd
Created November 22, 2020 15:09
Show Gist options
  • Save fpGHwd/30f7b4931c4f5dbc7362ec497841de31 to your computer and use it in GitHub Desktop.
Save fpGHwd/30f7b4931c4f5dbc7362ec497841de31 to your computer and use it in GitHub Desktop.
automatically modified aria2.conf’s bt-tracker value with "https://cdn.jsdelivr.net/gh/ngosang/trackerslist/trackers_best.txt" when startup (sleep several seconds for internet connection, recomended)
#!/usr/bin/env bash
# set -euo pipefail
# aria2
# aria2c --conf-path=/home/wd/.aria2/aria2.conf -D
# update tracker list
# last_run_timestamp=Fri Nov 20 09:25:58 PM CST 2020
tracker_lists=`curl https://cdn.jsdelivr.net/gh/ngosang/trackerslist/trackers_best.txt | grep -v '^\s*$' | sed ":a;N;s/\n/,/g;$!ba"`
# echo $tracker_lists
if [ -n "$tracker_lists" ]; then
echo $tracker_lists
sed -i "/^bt-tracker=*/cbt-tracker=$tracker_lists" /home/wd/.aria2/aria2.conf
sed -i "/^# last_run_timestamp*/c# last_run_timestamp=`date`" /home/wd/.aria2/aria2.conf
sed -i "/^# last_run_timestamp*/c# last_run_timestamp=`date`" /home/wd/.config/autostart-scripts/aria2.sh
fi
# if process aria2c exist, then kill it
is_aria2c_exist=`ps -ef | grep -m 1 aria2 | grep -v "grep" | wc -l`
if [ "$is_aria2c_exist" != "0" ]; then
pid=`ps -ef | grep -m 1 aria2c | awk '{print $2}'`
kill $pid
# killall aria2c
fi
sleep 0.5
aria2c --conf-path=/home/wd/.aria2/aria2.conf -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment