-
Notifications
You must be signed in to change notification settings - Fork 12
/
goFile.sh
74 lines (63 loc) · 1.95 KB
/
goFile.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# 检查是否以sudo权限运行
if [ "$EUID" -ne 0 ]; then
echo -e "\033[31m请使用sudo权限运行此脚本\033[0m"
exit 1
fi
# 检查是否安装了 gzip
if ! command -v gzip &> /dev/null; then
echo "gzip is not installed. Installing gzip..."
if [[ "$(uname -s)" == "Linux" ]]; then
if [[ -f /etc/redhat-release ]]; then
yum install -y gzip
elif [[ -f /etc/debian_version ]]; then
apt-get update
apt-get install -y gzip
else
echo "Unsupported Linux distribution"
exit 1
fi
elif [[ "$(uname -s)" == "Darwin" ]]; then
brew install gzip
else
echo "Unsupported platform: $(uname -s)"
exit 1
fi
fi
# 根据操作系统和处理器架构选择下载的文件名
if [[ "$(uname -s)" == "Linux" ]]; then
if [[ "$(uname -m)" == "x86_64" ]]; then
file_name="goFile-linux-amd64.tar.gz"
else
file_name="goFile-linux-arm64.tar.gz"
fi
elif [[ "$(uname -s)" == "Darwin" ]]; then
if [[ "$(uname -m)" == "x86_64" ]]; then
file_name="goFile-darwin-amd64.tar.gz"
else
file_name="goFile-darwin-arm64.tar.gz"
fi
else
echo "Unsupported platform: $(uname -s) $(uname -m)"
exit 1
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/goFile/releases/latest/download/${file_name}"
else
echo "服务器位于国外,不使用代理下载"
url="https://github.com/csznet/goFile/releases/latest/download/${file_name}"
fi
# 下载文件并解压
curl -L -O $url
tar xf $file_name
# 清理
rm $file_name
# 添加执行权限并移动到 bin 目录
chmod +x goFile
mv goFile /usr/local/bin/
# 提示用户
echo -e "\033[34m在想调用出 goFile 管理的目录下直接执行 goFile 命令即可\033[0m"