This repository has been archived by the owner on Aug 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdnsproxy-setup.sh
57 lines (57 loc) · 1.92 KB
/
dnsproxy-setup.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/sh
REPO="https://github.com/AdguardTeam/dnsproxy"
DIR="/opt/adguard"
TMP_DIR=$(mktemp -d)
test() {
local TEST="aria2c xh curl wget"
for cmd in $TEST; do
command -v $cmd 2>&0
done
}
CMDS=$(test)
url() {
case "$CMDS" in
*xh*) xh HEAD $1 --no-check-status -h;;
*curl*) curl -ISs $1;;
*wget*) wget --max-redirect=0 $1 2>&1;;
esac
}
LATEST=$(url "${REPO}/releases/latest" | grep -i ^location: | sed 's/.*\/\([v0-9.]\+\).*/\1/')
download() {
local FILE="dnsproxy-${1}-${LATEST}.tar.gz"
local URL="${REPO}/releases/download/${LATEST}/${FILE}"
case "$CMDS" in
*aria2c*)
aria2c $URL -d "$TMP_DIR" -o "$FILE" -j5 -x10 -s8 -k1M --optimize-concurrent-downloads --header="Accept-Encoding: zstd, br, gzip, deflate";;
*xh*)
xh -Fd $URL -o "$TMP_DIR/$FILE" Accept-Encoding:'zstd, br, gzip, deflate';;
*curl*)
curl -L $URL -o "$TMP_DIR/$FILE" --compressed -H "Accept-Encoding: zstd, br, gzip, deflate";;
*wget*)
wget $URL -O "$TMP_DIR/$FILE" --header="Accept-Encoding: zstd, br, gzip, deflate";;
esac
local TPATH=$(tar -ztf $TMP_DIR/$FILE | grep dnsproxy$)
local RDIR=$(echo $TPATH | sed 's/^\.\///;s/dnsproxy$//')
tar -C $TMP_DIR -zxf $TMP_DIR/$FILE $TPATH
mv -f $TMP_DIR/${RDIR}dnsproxy $TMP_DIR/dnsproxy && chown root:root $TMP_DIR/dnsproxy
}
sysctlfn() {
local SERVICE="adguard-dnsproxy.service"
if [ $(systemctl list-unit-files "$SERVICE" | wc -l) -gt 3 ]; then
systemctl $1 $SERVICE
fi
}
[ -d "$DIR" ] || mkdir $DIR
if [ -f "$DIR/dnsproxy" ]; then
VERSION=$($DIR/dnsproxy --version | awk '{print $NF}')
OUTPUT=$(printf "$VERSION\n$LATEST" | sed '/^$/d' | sort -Vr | head -1)
if [ "$VERSION" != "$OUTPUT" ]; then
download "${1}"
sysctlfn stop
[ -f "$TMP_DIR/dnsproxy" ] && mv -f $TMP_DIR/dnsproxy $DIR/dnsproxy && rm -rf $TMP_DIR
sysctlfn start
fi
else
download "${1}"
[ -f "$TMP_DIR/dnsproxy" ] && mv -f $TMP_DIR/dnsproxy $DIR/dnsproxy && rm -rf $TMP_DIR
fi