-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker
executable file
·49 lines (43 loc) · 1.3 KB
/
tracker
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
#!/bin/env bash
# Some code copied from https://gist.github.com/cdown/1163649
urlencode() {
old_lang=$LANG
LANG=C
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
# urlencode <string>
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf %s "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LANG=$old_lang
LC_COLLATE=$old_lc_collate
}
urldecode() {
# urldecode <string>
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
urlencodecurl() {
if [[ $# != 1 ]]; then
echo "Usage: $0 string-to-urlencode"
return 1
fi
local data="$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$1" "")"
if [[ $? == 0 ]]; then
echo "${data##/?}"
fi
return 0
}
trackerlistgit=$(curl https://ngosang.github.io/trackerslist/trackers_all_ip.txt https://cdn.staticaly.com/gh/XIU2/TrackersListCollection/master/all.txt)
# This variable doesn't work,
# trackerencoder=${${"$(urlencodecurl "$trackerlistgit")"//\%0A/\&tr=}//\&tr=\&tr=/\&tr=}
aa="$(urlencodecurl "$trackerlistgit")"
bb="$(sed s'/\%0A/\&tr=/g' <<< "$aa")"
trackerencoder="$(sed s'/\&tr=\&tr=/\\\&tr=/g' <<< "$bb")"
# echo $trackerencoder
sed -i "s/tracker=\".*\"/tracker=\"\&tr=${trackerencoder}\"/g" config