forked from 07031218/normal-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertex.sh
235 lines (235 loc) · 6.79 KB
/
vertex.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
#!/bin/bash
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
if [[ $EUID -ne 0 ]]; then
echo -e "${red}本脚本必须root账号运行,请切换root用户后再执行本脚本!${plain}"
exit 1
fi
check_docker(){
if test -z "$(which docker)"; then
echo -e "${yellow}检测到系统未安装docker,开始安装docker${plain}"
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
if [[ "$#" -eq 0 ]]; then
echo -e "${green}docker安装成功······${plain}"
else
echo -e "${red}docker安装失败······${plain}"
exit 1
fi
fi
if test -z `which docker-compose`;then
echo -e "${yellow}检测到系统未安装docker-compose,开始安装docker-compose${plain}"
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.4.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose && ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
if [[ "$#" -eq 0 ]]; then
echo -e "${green}docker-compose安装成功······${plain}"
else
echo -e "${red}docker-compose安装失败······${plain}"
exit 1
fi
fi
}
install_vertex(){
check_docker
local_ip=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E '\ 1(92|0|72|00|1)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
baseip=$(curl -s http3.ooo) > /dev/null
if [[ `docker ps |grep vertex` == "" ]]; then
mkdir -p /root/vertex && chmod 777 /root/vertex
cd /root
cat >/root/docker-compose.yml <<EOF
version: "2.0"
services:
vertex:
image: lswl/vertex:stable
container_name: vertex
restart: always
tty: true
network_mode: bridge
hostname: vertex
volumes:
- /root/vertex:/vertex
environment:
- TZ=Asia/Shanghai
ports:
- 3000:3000
vertex-base:
image: lswl/vertex-base:latest
EOF
docker-compose up -d
sleep 5s
password=`cat /root/vertex/data/password`
echo -e "${green}Vertex安装完毕,面板访问地址:http://${baseip}:3000 或 http://${local_ip}:3000\n用户名:admin\n密 码:${plain} ${red}${password}${plain}${green}\n进入vertex面板后通过${plain} ${red}全局设置${plain} ${green}修改密码 ${plain}"
else
echo -ne "${red}检测到系统已安装过vertex,是否重装vertex? [Y/n]:${plain}"
read yynn
if [[ $yynn == "y" ]]||[[ $yynn == "Y" ]]; then
docker-compose down
docker rmi lswl/vertex:latest
docker rmi containrrr/watchtower:latest
cat >/root/docker-compose.yml <<EOF
version: "2.0"
services:
vertex:
image: lswl/vertex:stable
container_name: vertex
restart: always
tty: true
network_mode: bridge
hostname: vertex
volumes:
- /root/vertex:/vertex
environment:
- TZ=Asia/Shanghai
ports:
- 3000:3000
vertex-base:
image: lswl/vertex-base:latest
EOF
docker-compose up -d
echo -e "${green}Vertex重装完毕···${plain}"
exit 0
else
exit 0
fi
fi
}
install_qBittorrent(){
check_docker
echo -ne "${yellow}请输入qBittorrent下载文件存放目录的绝对路径:${plain}"
read down_dir
cat>/root/qBittorrent.yml<<EOF
version: "2.1"
services:
qbittorrent:
image: lscr.io/linuxserver/qbittorrent:latest
container_name: qbittorrent
network_mode: "host"
environment:
- PUID=1000
- PGID=1000
- TZ=Aisa/Shanghai
- WEBUI_PORT=8080
volumes:
- /root/qbittorrent/config:/config
- ${down_dir}:/downloads
ports:
- 8080:8080
- 6881:6881
- 6881:6881/udp
restart: unless-stopped
EOF
cd /root
docker-compose -f qBittorrent.yml up -d
if [[ "$#" -eq 0 ]]; then
echo -e "${green}qBittorrent安装成功······\n下载文件存放路径:${down_dir}${plain}"
echo -e "${green}默认用户名:admin\n默认密码:adminadmin\n请登录面板后及时修改默认密码${plain}"
else
echo -e "${red}qBittorrent安装失败······${plain}"
exit 1
fi
}
restore_rule(){
cd /root/vertex/data
if test -z `which unzip`; then
echo -e "${yellow}检测到系统未安装unzip,开始安装unzip······${plain}"
apt install unzip -y||yum install unzip -y
if [[ "$#" -eq 0 ]]; then
echo -e "${green}unzip安装成功,开始导入刷流所需相关规则······${plain}"
else
echo -e "${red}出错了,unzip安装失败,程序退出······${plain}"
exit 1
fi
fi
wget https://ghproxy.20120714.xyz/https://github.com/07031218/normal-shell/raw/main/vertex_ruler/rule.zip -O rule.zip
unzip -o rule.zip
if [[ "$#" -eq 0 ]]; then
echo -e "${green}刷流相关规则导入成功······${plain}"
else
echo -e "${red}出错了,刷流相关规则导入失败,程序退出······${plain}"
exit 1
fi
}
uninstall_vertex(){
cd /root
docker-compose down
echo -ne "${yellow}是否删除vertex映射目录和相关本地镜像[Yy/Nn]${plain}"
read yn
if [[ $yn == "Y" ]]||[[ $yn == "y" ]]; then
rm -rf /root/vertex
rm /root/docker-compose.yml
docker rmi lswl/vertex:latest
docker rmi lswl/vertex-base:latest
docker rmi containrrr/watchtower:latest
echo -e "${yellow}vertex映射目录和相关本地镜像已删除${plain}"
else
rm /root/docker-compose.yml
docker rmi lswl/vertex:latest
docker rmi lswl/vertex-base:latest
docker rmi containrrr/watchtower:latest
echo -e "${yellow}按照您的选择,vertex映射目录给予保留,程序自动退出${plain}"
fi
}
menu_go_on(){
echo
echo -e "${red}是否继续执行脚本?${plain}"
read -n1 -p "Y继续执行,N退出脚本[Y/n]" res
echo
case "$res" in
Y |y)
;;
N | n)
exit 1;;
*)
echo "输入错误"
menu_go_on;;
esac
}
copyright(){
clear
echo -e "
${green}###########################################################${plain}
${green}# #${plain}
${green}# Vertex 一键部署脚本 #${plain}
${green}# Powered by 翔翎 #${plain}
${green}# #${plain}
${green}###########################################################${plain}"
}
main(){
echo -e "
${red}0.${plain} 退出脚本
${green}1.${plain} 安装、重装vertex
${green}2.${plain} 安装qBittorrent
${green}3.${plain} 导入vertex刷流相关规则
${green}4.${plain} 卸载vertex
"
read -p "请输入数字 :" num
case "$num" in
0)
exit 0
;;
1)
install_vertex
;;
2)
install_qBittorrent
;;
3)
restore_rule
;;
4)
uninstall_vertex
;;
*)
clear
echo -e "${Error}:请输入正确数字 [0-4]"
sleep 3s
main
;;
esac
menu_go_on
clear
copyright
main
}
copyright
main