forked from P3TERX/aria2.conf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.sh
57 lines (52 loc) · 1.91 KB
/
tracker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#=================================================
# https://github.com/P3TERX/aria2.conf
# File name:tracker.sh
# Description: Get trackers and add to aria2.conf
# Lisence: MIT
# Version: 1.3
# Author: P3TERX
# Blog: https://p3terx.com
#=================================================
INFO="[\033[32mINFO\033[0m]"
ERROR="[\033[31mERROR\033[0m]"
ARIA2_CONF=${1:-aria2.conf}
echo && echo -e "$INFO Check downloader ..."
if [ `command -v curl` ]; then
DOWNLOADER='curl -fsSL'
elif [ `command -v wget` ]; then
DOWNLOADER='wget -qO-'
else
echo -e "$ERROR curl or wget is not installed."
fi
# BT tracker is provided by the following project.
# https://github.com/ngosang/trackerslist
# https://github.com/XIU2/TrackersListCollection
# Alternative link provided by jsDelivr.
# https://www.jsdelivr.com
echo && echo -e "$INFO Get trackers ..."
TRACKER=$(
${DOWNLOADER} https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/all_aria2.txt || \
${DOWNLOADER} https://cdn.jsdelivr.net/gh/XIU2/TrackersListCollection/all_aria2.txt || \
{
${DOWNLOADER} https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt || \
${DOWNLOADER} https://cdn.jsdelivr.net/gh/ngosang/trackerslist/trackers_all.txt
} \
| awk NF | sed ":a;N;s/\n/,/g;ta"
)
[ -z $TRACKER ] && echo -e "
$ERROR Unable to get trackers, network failure or invalid links." && exit 1
echo -e "
--------------------[TRACKERS]--------------------
${TRACKER}
--------------------[TRACKERS]--------------------
"
[ ${ARIA2_CONF} == "cat" ] && exit 0
echo -e "$INFO Adding trackers to '${ARIA2_CONF}' ..." && echo
if [ ! -f ${ARIA2_CONF} ]; then
echo -e "$ERROR '${ARIA2_CONF}' does not exist."
exit 1
else
[ -z $(grep "bt-tracker=" ${ARIA2_CONF}) ] && echo "bt-tracker=" >>${ARIA2_CONF}
sed -i "s@^\(bt-tracker=\).*@\1${TRACKER}@" ${ARIA2_CONF} && echo -e "$INFO Trackers added successfully!"
fi