-
Notifications
You must be signed in to change notification settings - Fork 4
/
install_soga.sh
93 lines (76 loc) · 2.83 KB
/
install_soga.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Reference: https://github.com/vaxilu/soga/blob/master/install.sh
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
cur_dir=$(pwd)
arch=$(arch)
if [[ $arch == "x86_64" || $arch == "x64" || $arch == "amd64" ]]; then
arch="amd64"
elif [[ $arch == "aarch64" || $arch == "arm64" ]]; then
arch="arm64"
else
arch="amd64"
echo -e "${red}检测架构失败,使用默认架构: ${arch}${plain}"
fi
echo "架构: ${arch}"
if [ "$(getconf WORD_BIT)" != '32' ] && [ "$(getconf LONG_BIT)" != '64' ] ; then
echo "本软件不支持 32 位系统(x86),请使用 64 位系统(x86_64),如果检测有误,请联系作者"
exit 2
fi
install_base() {
apk update
apk add --no-cache wget curl tar socat
}
install_soga() {
cd /usr/local/
if [[ -e /usr/local/soga/ ]]; then
rm /usr/local/soga/ -rf
fi
if [ $# == 0 ] ;then
last_version=$(curl -Ls "https://api.github.com/repos/vaxilu/soga/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [[ ! -n "$last_version" ]]; then
echo -e "${red}检测 soga 版本失败,可能是超出 Github API 限制,请稍后再试,或手动指定 soga 版本安装${plain}"
exit 1
fi
echo -e "检测到 soga 最新版本:${last_version},开始安装"
wget -N --no-check-certificate -O /usr/local/soga.tar.gz https://github.com/vaxilu/soga/releases/download/${last_version}/soga-linux-${arch}.tar.gz
if [[ $? -ne 0 ]]; then
echo -e "${red}下载 soga 失败,请确保你的服务器能够下载 Github 的文件${plain}"
exit 1
fi
else
last_version=$1
url="https://github.com/vaxilu/soga/releases/download/${last_version}/soga-linux-${arch}.tar.gz"
echo -e "开始安装 soga v$1"
wget -N --no-check-certificate -O /usr/local/soga.tar.gz ${url}
if [[ $? -ne 0 ]]; then
echo -e "${red}下载 soga v$1 失败,请确保此版本存在${plain}"
exit 1
fi
fi
tar zxvf soga.tar.gz
rm soga.tar.gz -f
cd soga
chmod +x soga
mkdir /etc/soga/ -p
echo -e "${green}soga v${last_version}${plain} 安装完成"
cp soga.conf /etc/soga/
if [[ ! -f /etc/soga/blockList ]]; then
cp blockList /etc/soga/
fi
if [[ ! -f /etc/soga/dns.yml ]]; then
cp dns.yml /etc/soga/
fi
if [[ ! -f /etc/soga/routes.toml ]]; then
cp routes.toml /etc/soga/
fi
curl -o /usr/bin/soga -Ls https://raw.githubusercontent.com/vaxilu/soga/master/soga.sh
chmod +x /usr/bin/soga
curl -o /usr/bin/soga-tool -Ls https://raw.githubusercontent.com/vaxilu/soga/master/soga-tool-${arch}
chmod +x /usr/bin/soga-tool
}
echo -e "${green}开始安装 soga${plain}"
install_base
install_soga $1
echo -e "${green}安装结束 soga${plain}"