-
Notifications
You must be signed in to change notification settings - Fork 0
/
ENV.sh
284 lines (257 loc) · 6.9 KB
/
ENV.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
#!/usr/bin/env /bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/home
DIR="/home"
DIR_Service="/etc/systemd/system"
DY="sleep 1"
LINE="---------------------------------------"
OS=""
OS_Ver=""
OS_Bit=""
INS=""
UNS=""
Domain=""
Domain_Main=""
Port=""
Password=""
TAG=""
GET="curl -L"
Bak(){
mkdir ${DIR}/bak
cp -f ${DIR}/caddyfile ${DIR}/bak/caddyfile
cp -f ${DIR}/${EXE2}.json ${DIR}/bak/${EXE2}.json
}
Res(){
cp -f ${DIR}/bak/caddyfile ${DIR}/caddyfile
cp -f ${DIR}/bak/${EXE2}.json ${DIR}/${EXE2}.json
}
Check_Root(){
[[ `whoami` != 'root' ]] && echo -e "请使用root权限运行" && exit 1
}
Check_NotRoot(){
[[ `whoami` = 'root' ]] && echo -e "请不要使用root权限运行" && exit 1
}
Check_OS(){
if [[ -s /etc/redhat-release ]]; then
OS_Ver=`grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1`
else
OS_Ver=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1`
fi
OS_Bit=`uname -m`
if [[ ${OS_Bit} = "x86_64" ]]; then
OS_Bit="x64"
else
OS_Bit="x32"
fi
echo ${LINE}
if cat /etc/issue | grep -q -E -i "debian"; then
OS="debian"
INS="apt -y"
UNS="purge"
echo "当前系统为 ${OS} ${OS_Ver} ${OS_Bit}"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
OS="ubuntu"
INS="apt -y"
UNS="purge"
echo "当前系统为 ${OS} ${OS_Ver} ${OS_Bit}"
else
echo "不支持的系统"
fi
}
Check_BBR(){ #检查安装BBR的系统要求
if [[ "${OS}" == "debian" ]]; then
if [[ ${OS_Ver} -ge "8" ]]; then
Menu_Main
else
echo -e "BBR内核不支持当前系统 ${OS} ${OS_Ver} ${OS_Bit} !" && exit 1
fi
elif [[ "${OS}" == "ubuntu" ]]; then
if [[ ${OS_Ver} -ge "14" ]]; then
Menu_Main
else
echo -e "BBR内核不支持当前系统 ${OS} ${OS_Ver} ${OS_Bit} !" && exit 1
fi
else
echo -e "BBR内核不支持当前系统 ${OS} ${OS_Ver} ${OS_Bit} !" && exit 1
fi
}
Check_BBR(){
Kernel_Ver=`uname -r | awk -F "-" '{print $1}'`
if [[ `echo ${Kernel_Ver} | awk -F'.' '{print $1}'` == "4" ]] && [[ `echo ${Kernel_Ver} | awk -F'.' '{print $2}'` -ge 9 ]] || [[ `echo ${Kernel_Ver} | awk -F'.' '{print $1}'` == "5" ]]; then
Kernel_Status="BBR"
else
Kernel_Status="noinstall"
fi
if [[ ${Kernel_Status} == "BBR" ]]; then
BBR=$(sysctl net.ipv4.tcp_congestion_control | awk '{print $3}')
if [[ "$BBR" == "bbr" ]]; then
BBR="BBR已开启"
else
BBR="BBR未开启"
fi
fi
}
CH(){ #设置权限
chmod -R 777 ${DIR} >/dev/null 2>&1
chmod -R 777 ${DIR_Service} >/dev/null 2>&1
}
TMP(){ #临时目录
TMP=${DIR}/tmp
rm -fr ${TMP}
mkdir ${TMP}
echo -e "设置临时目录:${TMP}"
}
Domain_Check(){ #检查域名变量
if [ ${Domain} ] ;then
echo "域名已设置为:${Domain}"
else
Domain_Set
fi
}
Domain_Set(){ #输入域名
echo -e "请输入您的域名: "
stty erase '^H' && read -e -p "请输入:" Domain
[[ -z ${Domain} ]] && Domain="none"
if [ "${Domain}" = "none" ] ;then
echo -e "请正确输入域名"
Domain_Set
else
echo -e "域名设置成功"
Tls="${DIR}/${Domain}"
# F参数定义分隔符(默认空格),NR第1行,substr第2列,1-3个字符,$NF为最后列
Domain_Main=$(echo "${Domain}" | awk -F '.' 'NR<=1 {print $(NF-1)"."$NF}')
fi
}
Port_Check(){ #检查密码变量
if [ ${Port} ] ;then
echo "端口已设置为:${Port}"
else
Port_Set
fi
}
Port_Set(){ #设置端口
echo -e "请设置端口"
stty erase '^H' && read -e -p "请输入:" Port
[[ -z ${Port} ]] && Port="none"
if [ "${Port}" = "none" ] ;then
echo -e "请正确输入端口"
Port_Set
else
echo -e "端口设置成功"
fi
}
Password_Check(){ #检查密码变量
if [ ${Password} ] ;then
echo "密码已设置为:${Password}"
else
Password_Set
fi
}
Password_Set(){ #设置密码
echo -e "请设置密码"
stty erase '^H' && read -e -p "请输入:" Password
[[ -z ${Password} ]] && Password="none"
if [ "${Password}" = "none" ] ;then
echo -e "请正确输入密码"
Password_Set
else
echo -e "密码设置成功"
fi
}
Install_Pre(){ #安装依赖
clear
${INS} update
${INS} upgrade
${INS} install curl iptables iptables-persistent jq nano net-tools netcat ntpdate screen socat unzip wget xz-utils
${INS} --fix-broken install
${INS} ${UNS} *vim* *apache*
${INS} autoremove
File=/etc/ssh/sshd_config && sed -i '\#PermitRootLogin #cPermitRootLogin yes' $File && sed -i '\#Port #cPort 22' $File && sed -i '\#ClientAliveInterval #cClientAliveInterval 30' $File && sed -i '\#ClientAliveCountMax #cClientAliveCountMax 60' $File && service ssh restart #修改SSH端口和ROOT登录
export EDITOR=nano #修改默认编辑器
}
Clean(){
echo -e "清理残留中..."
rm -f ${DIR}/${EXE}* >/dev/null 2>&1
rm -f ${DIR}/${EXE2}* >/dev/null 2>&1
rm -fr ${DIR_Service}/${EXE}* ${EXE}*.service >/dev/null 2>&1
rm -fr ${DIR_Service}/${EXE2}* ${EXE2}.service >/dev/null 2>&1
rm -fr /var/log/${EXE} /etc/init.d/${EXE} /usr/local/etc/${EXE} >/dev/null 2>&1
rm -fr /var/log/${EXE2} /etc/init.d/${EXE2} /usr/local/etc/${EXE2} >/dev/null 2>&1
echo -e "清理完成"
}
Time_Sync(){ #同步服务器时间
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #修改时区
systemctl stop ntp &>/dev/null
echo -e "正在进行时间同步"
ntpdate pool.ntp.org
if [[ $? -eq 0 ]];then
echo -e "时间同步成功,当前系统时间 `date -R`"
else
echo -e "时间同步失败,请检查 NTPdate 服务是否正常工作"
fi
}
Service_On(){ #重载服务
systemctl daemon-reload
systemctl enable ${EXE2}.service
systemctl restart ${EXE2}
DY
systemctl --no-pager status ${EXE2}
}
Service_Off(){ #禁用服务
systemctl stop ${EXE2} >/dev/null 2>&1
systemctl disable ${EXE2} >/dev/null 2>&1
systemctl daemon-reload
}
Show_Status(){ #显示信息
echo -e "您设置的域名为:${Domain},主域名为:${Domain_Main}"
echo -e "您设置的端口为:${Port}"
if [ ${Password} ] ;then
echo -e "您设置的密码为:${Password}"
else
echo -e ""
fi
}
Menu_M(){ #主菜单
bash <(${GET} http://raw.githubusercontent.com/ddvcx/sh/m/c.sh)
}
Get_Tag(){ #获取版本号
TAG=$(${GET} https://api.github.com/repos/$REPO/releases | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g;s/v//g')
#TAG=$(curl -sL https://api.github.com/repos/XXX/XXX/releases/latest | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g;s/v//g') && echo ${TAG}
echo "准备安装${EXE2}-${TAG} "
}
UnInstall_Server(){
echo -e "卸载服务中... "
Service_Off
killall -9 ${EXE2} >/dev/null 2>&1
Clean
echo -e "Server 卸载完成"
}
Install_Server(){
clear
Domain_Check
Port_Check
Password_Check
UnInstall_Server
Download
Service_Set
Service_On
Clean
echo -e "安装完成"
Show_Status
}
Update_Server(){
EXE_File="${DIR}/${EXE2}"
${EXE_File} --version
if [ ! -f ${EXE_File} ]; then
echo -e "${EXE2} 没有安装,开始安装"
Install_Server
else
echo -e "正在更新${EXE2}"
Bak
UnInstall_Server
Download
Service_Set
Res
Service_On
echo -e "更新完成"
fi
}