-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpt_install.sh
More file actions
143 lines (133 loc) · 4.17 KB
/
Copy pathpt_install.sh
File metadata and controls
143 lines (133 loc) · 4.17 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
#From https://github.com/oneclickvirt/pingtest
#2024.06.29
rm -rf /usr/bin/pt
rm -rf pt
os=$(uname -s)
arch=$(uname -m)
# Bootstrap Cloudflare DoH with fixed public addresses when this host is online
# but cannot use its configured system resolver. Normal curl and wget paths stay
# first so existing installations keep their current behavior.
DOH_URL="https://cloudflare-dns.com/dns-query"
DOH_RESOLVE="cloudflare-dns.com:443:1.1.1.1,1.0.0.1"
curl_supports_doh() {
command -v curl >/dev/null 2>&1 && curl --help all 2>/dev/null | grep -q -- "--doh-url"
}
curl_fetch() {
if curl "$@"; then
return 0
fi
if curl_supports_doh; then
curl --doh-url "$DOH_URL" --resolve "$DOH_RESOLVE" "$@"
return $?
fi
return 1
}
download_file() {
local output=$1
local url=$2
if command -v wget >/dev/null 2>&1; then
if wget -O "$output" "$url"; then
return 0
fi
echo "wget download failed, falling back to curl"
fi
if command -v curl >/dev/null 2>&1 && curl_fetch -fL -o "$output" "$url"; then
return 0
fi
echo "Unable to download $url" >&2
return 1
}
check_cdn() {
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl_fetch -sL -k "$cdn_url$o_url" --max-time 6 2>/dev/null | grep -q "success" >/dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
}
check_cdn_file() {
check_cdn "https://raw.githubusercontent.com/spiritLHLS/ecs/main/back/test"
if [ -n "$cdn_success_url" ]; then
echo "CDN available, using CDN"
else
echo "No CDN available, no use CDN"
fi
}
cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn3.spiritlhl.net/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/")
check_cdn_file
case $os in
Linux)
case $arch in
"x86_64" | "x86" | "amd64" | "x64")
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-linux-amd64" || exit 1
;;
"i386" | "i686")
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-linux-386" || exit 1
;;
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-linux-arm64" || exit 1
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac
;;
Darwin)
case $arch in
"x86_64" | "x86" | "amd64" | "x64")
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-darwin-amd64" || exit 1
;;
"i386" | "i686")
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-darwin-386" || exit 1
;;
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-darwin-arm64" || exit 1
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac
;;
FreeBSD)
case $arch in
amd64)
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-freebsd-amd64" || exit 1
;;
"i386" | "i686")
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-freebsd-386" || exit 1
;;
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
download_file pt "${cdn_success_url}https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-freebsd-arm64" || exit 1
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac
;;
*)
echo "Unsupported operating system: $os"
exit 1
;;
esac
chmod 777 pt
PARAM="net.ipv4.ping_group_range"
NEW_VALUE="0 2147483647"
CURRENT_VALUE=$(sysctl -n "$PARAM" 2>/dev/null)
if [ -f /etc/sysctl.conf ] && [ "$CURRENT_VALUE" != "$NEW_VALUE" ]; then
if grep -q "^$PARAM" /etc/sysctl.conf; then
sudo sed -i "s/^$PARAM.*/$PARAM = $NEW_VALUE/" /etc/sysctl.conf
else
echo "$PARAM = $NEW_VALUE" | sudo tee -a /etc/sysctl.conf
fi
sudo sysctl -p
fi
setcap cap_net_raw=+ep pt
cp pt /usr/bin/pt
setcap cap_net_raw=+ep /usr/bin/pt