1+ #! /bin/bash
2+ # From https://github.com/oneclickvirt/pingtest
3+ # 2024.06.29
4+
5+ rm -rf /usr/bin/pt
6+ rm -rf pt
7+ os=$( uname -s)
8+ arch=$( uname -m)
9+
10+ check_cdn () {
11+ local o_url=$1
12+ for cdn_url in " ${cdn_urls[@]} " ; do
13+ if curl -sL -k " $cdn_url$o_url " --max-time 6 | grep -q " success" > /dev/null 2>&1 ; then
14+ export cdn_success_url=" $cdn_url "
15+ return
16+ fi
17+ sleep 0.5
18+ done
19+ export cdn_success_url=" "
20+ }
21+
22+ check_cdn_file () {
23+ check_cdn " https://raw.githubusercontent.com/spiritLHLS/ecs/main/back/test"
24+ if [ -n " $cdn_success_url " ]; then
25+ echo " CDN available, using CDN"
26+ else
27+ echo " No CDN available, no use CDN"
28+ fi
29+ }
30+
31+ cdn_urls=(" https://cdn0.spiritlhl.top/" " http://cdn3.spiritlhl.net/" " http://cdn1.spiritlhl.net/" " http://cdn2.spiritlhl.net/" )
32+ check_cdn_file
33+
34+ case $os in
35+ Linux)
36+ case $arch in
37+ " x86_64" | " x86" | " amd64" | " x64" )
38+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-linux-amd64"
39+ ;;
40+ " i386" | " i686" )
41+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-linux-386"
42+ ;;
43+ " armv7l" | " armv8" | " armv8l" | " aarch64" | " arm64" )
44+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-linux-arm64"
45+ ;;
46+ * )
47+ echo " Unsupported architecture: $arch "
48+ exit 1
49+ ;;
50+ esac
51+ ;;
52+ Darwin)
53+ case $arch in
54+ " x86_64" | " x86" | " amd64" | " x64" )
55+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-darwin-amd64"
56+ ;;
57+ " i386" | " i686" )
58+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-darwin-386"
59+ ;;
60+ " armv7l" | " armv8" | " armv8l" | " aarch64" | " arm64" )
61+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-darwin-arm64"
62+ ;;
63+ * )
64+ echo " Unsupported architecture: $arch "
65+ exit 1
66+ ;;
67+ esac
68+ ;;
69+ FreeBSD)
70+ case $arch in
71+ amd64)
72+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-freebsd-amd64"
73+ ;;
74+ " i386" | " i686" )
75+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-freebsd-386"
76+ ;;
77+ " armv7l" | " armv8" | " armv8l" | " aarch64" | " arm64" )
78+ wget -O pt " ${cdn_success_url} https://github.com/oneclickvirt/pingtest/releases/download/output/pingtest-freebsd-arm64"
79+ ;;
80+ * )
81+ echo " Unsupported architecture: $arch "
82+ exit 1
83+ ;;
84+ esac
85+ ;;
86+ * )
87+ echo " Unsupported operating system: $os "
88+ exit 1
89+ ;;
90+ esac
91+
92+ chmod 777 pt
93+ cp pt /usr/bin/pt
0 commit comments