-
Notifications
You must be signed in to change notification settings - Fork 45
/
get.sh
58 lines (47 loc) · 1.61 KB
/
get.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
58
#!/bin/bash
ARCH=$(uname -m)
if [ "$ARCH" == "x86_64" ]; then
FILE="goForward.zip"
elif [ "$ARCH" == "arm64" ]; then
FILE="goForward_arm64.zip"
else
echo -e "\033[41mError\033[0m: Unsupported architecture: $ARCH"
exit 1
fi
# Check if unzip is installed
if ! command -v unzip &> /dev/null; then
echo -e "\033[41mError\033[0m: unzip is not installed. Installing..."
# Install unzip based on the package manager
if command -v apt-get &> /dev/null; then
sudo apt-get install -y unzip
elif command -v yum &> /dev/null; then
sudo yum install -y unzip
else
echo -e "\033[41mError\033[0m: Unsupported package manager. Please install unzip manually."
exit 1
fi
fi
# 获取百度的平均延迟(ping 5次并取平均值)
ping_result=$(ping -c 5 -q baidu.com | awk -F'/' 'END{print $5}')
# 判断延迟是否在100以内
if awk -v ping="$ping_result" 'BEGIN{exit !(ping < 100)}'; then
echo "服务器位于中国国内,使用代理下载"
url="https://mirror.ghproxy.com/https://github.com/csznet/goForward/releases/latest/download/${FILE}"
else
echo "服务器位于国外,不使用代理下载"
url="https://github.com/csznet/goForward/releases/latest/download/${FILE}"
fi
# Download and unzip
if ! curl -L -O $url; then
echo -e "\033[41mError\033[0m: Failed to download $FILE. Please check your internet connection or try again later."
exit 1
fi
if ! unzip "$FILE"; then
echo -e "\033[41mError\033[0m: Failed to unzip $FILE."
exit 1
fi
rm "$FILE"
# Set permissions
chmod +x goForward
# Output success message
echo -e "\033[44mSuccess\033[0m The 'goForward' executable is ready for use."