-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path50113.sh
189 lines (152 loc) · 4.53 KB
/
50113.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
#!/bin/bash
set -o errexit
download(){
# wget安装
if [[ ! `which wget` ]]; then
if check_sys sysRelease ubuntu;then
apt-get install -y wget
elif check_sys sysRelease centos;then
yum install -y wget
fi
fi
local url1=$1
local url2=$2
local filename=$3
speed1=`curl -m 5 -L -s -w '%{speed_download}' "$url1" -o /dev/null || true`
speed1=${speed1%%.*}
speed2=`curl -m 5 -L -s -w '%{speed_download}' "$url2" -o /dev/null || true`
speed2=${speed2%%.*}
echo "speed1:"$speed1
echo "speed2:"$speed2
url=$url1
if [[ $speed2 -gt $speed1 ]]; then
url=$url2
fi
echo "using url:"$url
wget "$url" -O $filename
}
#判断系统版本
check_sys(){
local checkType=$1
local value=$2
local release=''
local systemPackage=''
local packageSupport=''
if [[ "$release" == "" ]] || [[ "$systemPackage" == "" ]] || [[ "$packageSupport" == "" ]];then
if [[ -f /etc/redhat-release ]];then
release="centos"
systemPackage="yum"
packageSupport=true
elif cat /etc/issue | grep -q -E -i "debian";then
release="debian"
systemPackage="apt"
packageSupport=true
elif cat /etc/issue | grep -q -E -i "ubuntu";then
release="ubuntu"
systemPackage="apt"
packageSupport=true
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat";then
release="centos"
systemPackage="yum"
packageSupport=true
elif cat /proc/version | grep -q -E -i "debian";then
release="debian"
systemPackage="apt"
packageSupport=true
elif cat /proc/version | grep -q -E -i "ubuntu";then
release="ubuntu"
systemPackage="apt"
packageSupport=true
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat";then
release="centos"
systemPackage="yum"
packageSupport=true
else
release="other"
systemPackage="other"
packageSupport=false
fi
fi
echo -e "release=$release\nsystemPackage=$systemPackage\npackageSupport=$packageSupport\n" > /tmp/ezhttp_sys_check_result
if [[ $checkType == "sysRelease" ]]; then
if [ "$value" == "$release" ];then
return 0
else
return 1
fi
elif [[ $checkType == "packageManager" ]]; then
if [ "$value" == "$systemPackage" ];then
return 0
else
return 1
fi
elif [[ $checkType == "packageSupport" ]]; then
if $packageSupport;then
return 0
else
return 1
fi
fi
}
get_sys_ver() {
cat > /tmp/sys_ver.py <<EOF
import platform
import re
sys_ver = platform.platform()
sys_ver = re.sub(r'.*-with-(.*)-.*',"\g<1>",sys_ver)
if sys_ver.startswith("centos-7"):
sys_ver = "centos-7"
if sys_ver.startswith("centos-6"):
sys_ver = "centos-6"
print sys_ver
EOF
echo `python /tmp/sys_ver.py`
}
upgrade_db() {
echo
# 更新panel或conf
flist=''
for f in `echo $flist`;do
\cp -a /opt/$dir_name/$f /opt/cdnfly/$f
done
}
update_file() {
cd /opt/$dir_name/master/
for i in `find ./ | grep -vE "^./$|^./agent$|^./conf$|conf/config.py|conf/nginx_global.tpl|conf/supervisor_master.conf|conf/nginx_http_default.tpl|conf/nginx_http_vhost.tpl|conf/nginx_stream_vhost.tpl|conf/ssl.cert|conf/ssl.key|^./panel"`;do
\cp -aT $i /opt/cdnfly/master/$i
done
}
# 定义版本
version_name="v5.1.13"
version_num="50113"
dir_name="cdnfly-master-$version_name"
tar_gz_name="$dir_name-$(get_sys_ver).tar.gz"
# 下载安装包
cd /opt
echo "开始下载$tar_gz_name..."
download "https://raw.githubusercontent.com/freejbgo/cdnfly-kaixin/main/cdnfly/$tar_gz_name" "https://raw.githubusercontent.com/freejbgo/cdnfly-kaixin/main/cdnfly/$tar_gz_name" "$tar_gz_name"
echo "下载完成"
echo "开始解压..."
rm -rf $dir_name
tar xf $tar_gz_name
echo "解压完成"
cd /opt
echo "准备升级数据库..."
upgrade_db
echo "升级数据库完成"
echo "更新文件..."
update_file
echo "更新文件完成."
echo "修改config.py版本..."
sed -i "s/VERSION_NAME=.*/VERSION_NAME=\"$version_name\"/" /opt/cdnfly/master/conf/config.py
sed -i "s/VERSION_NUM=.*/VERSION_NUM=\"$version_num\"/" /opt/cdnfly/master/conf/config.py
echo "修改完成"
echo "开始重启主控..."
supervisorctl restart all
#supervisorctl reload
echo "重启完成"
echo "清理文件"
rm -rf /opt/$dir_name
rm -f /opt/$tar_gz_name
echo "清理完成"
echo "完成$version_name版本升级"