forked from oooldking/script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
superupdate.sh
217 lines (193 loc) · 7.38 KB
/
superupdate.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
#!/usr/bin/env bash
#
# Description: Choose a faster mirror for Linux script
#
# Copyright (C) 2017 - 2018 Oldking <[email protected]>
#
# URL: https://www.oldking.net/697.html
#
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
SKYBLUE='\033[0;36m'
PLAIN='\033[0m'
getAbout() {
echo ""
echo " ========================================================= "
echo " \ SuperUpdate.sh Script / "
echo " \ Choose a faster mirror for Linux / "
echo " \ Created by Oldking / "
echo " ========================================================= "
echo ""
echo " Intro: https://www.oldking.net/697.html"
echo " Copyright (C) 2018 Oldking [email protected]"
echo -e " Version: ${GREEN}1.0.3${PLAIN} (2 Nov 2018)"
echo " Usage: wget -qO- git.io/superupdate.sh | bash"
echo ""
}
getHelp(){
echo " $( bash superupdate.sh )"
ehco " - set sources from cdn-fastly "
echo " $( bash superupdate.sh cn ) "
echo " - set sources from USTC "
echo " $( bash superupdate.sh 163 ) "
echo " - set sources from 163.com "
echo " $( bash superupdate.sh aliyun ) "
echo " - set sources from aliyun.com "
echo " $( bash superupdate.sh aws ) "
echo " - set sources from cdn-aws "
echo " $( bash superupdate.sh restore ) "
echo " - restore sources from backup file "
}
updateInit(){
[[ $EUID -ne 0 ]] && echo -e " ${RED}Error:${PLAIN} This script must be run as root!" && exit 1
if [ -f /etc/redhat-release ]; then
release="centos"
elif cat /etc/issue | grep -Eqi "debian"; then
release="debian"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -Eqi "debian"; then
release="debian"
elif cat /proc/version | grep -Eqi "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
release="centos"
fi
if [ $release == "debian" ]; then
debianVersion=$(awk -F'[= "]' '/VERSION_ID/{print $3}' /etc/os-release)
elif [ $release == "ubuntu" ]; then
ubuntuVersion=$(awk -F'[= "]' '/VERSION_ID/{print $3}' /etc/os-release)
elif [ $release == "centos" ]; then
os_release=$(grep "CentOS" /etc/redhat-release 2>/dev/null)
if echo "$os_release"|grep "release 5" >/dev/null 2>&1
then
centosVersion=5
elif echo "$os_release"|grep "release 6" >/dev/null 2>&1
then
centosVersion=6
elif echo "$os_release"|grep "release 7" >/dev/null 2>&1
then
centosVersion=7
else
centosVersion=""
fi
else
echo -e " ${RED}Error:${PLAIN} This script can not be run in your system now!" && exit 1
fi
}
setDebian(){
if [[ -f /etc/apt/sources.list.bak ]]; then
echo -e " ${GREEN}sources.list.bak exists${PLAIN}"
else
mv /etc/apt/sources.list{,.bak}
fi
[ -f /etc/apt/sources.list ] && rm /etc/apt/sources.list
echo "deb http://cdn-fastly.deb.debian.org/debian/ jessie main non-free contrib" >>/etc/apt/sources.list
echo "deb http://cdn-fastly.deb.debian.org/debian/ jessie-updates main non-free contrib" >>/etc/apt/sources.list
echo "deb http://cdn-fastly.deb.debian.org/debian/ jessie-backports main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://cdn-fastly.deb.debian.org/debian/ jessie main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://cdn-fastly.deb.debian.org/debian/ jessie-updates main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://cdn-fastly.deb.debian.org/debian/ jessie-backports main non-free contrib" >>/etc/apt/sources.list
echo "deb http://cdn-fastly.deb.debian.org/debian-security/ jessie/updates main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://cdn-fastly.deb.debian.org/debian-security/ jessie/updates main non-free contrib" >>/etc/apt/sources.list
[ "$debianVersion" == '7' ] && sed -i 's/jessie/wheezy/'g /etc/apt/sources.list
[ "$debianVersion" == '8' ] && echo -n ""
[ "$debianVersion" == '9' ] && sed -i 's/jessie/stretch/'g /etc/apt/sources.list
}
setUbuntu(){
if [[ -f /etc/apt/sources.list.bak ]]; then
echo -e " ${GREEN}sources.list.bak exists${PLAIN}"
else
mv /etc/apt/sources.list{,.bak}
fi
[ -f /etc/apt/sources.list ] && rm /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list
[ "$ubuntuVersion" == '14.04' ] && sed -i 's/xenial/trusty/'g /etc/apt/sources.list
[ "$ubuntuVersion" == '16.06' ] && echo -n ""
[ "$ubuntuVersion" == '18.04' ] && sed -i 's/xenial/bionic/'g /etc/apt/sources.list
}
setCentos(){
if [ -f /etc/yum.repos.d/CentOS-Base.repo.bak ]; then
echo -e " ${GREEN}CentOS-Base.repo.bak exists${PLAIN}"
else
mv /etc/yum.repos.d/CentOS-Base.repo{,.bak}
fi
[ -f /etc/yum.repos.d/CentOS-Base.repo ] && rm /etc/yum.repos.d/CentOS-Base.repo
[ "$centosVersion" == '5' ] && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
[ "$centosVersion" == '6' ] && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[ "$centosVersion" == '7' ] && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
}
setAWS(){
sed -i 's/cdn-fastly.deb.debian.org/cdn-aws.deb.debian.org/'g /etc/apt/sources.list
}
setCn(){
sed -i 's/cdn-fastly.deb.debian.org/mirrors.ustc.edu.cn/'g /etc/apt/sources.list
}
set163(){
sed -i 's/cdn-fastly.deb.debian.org/mirrors.163.com/'g /etc/apt/sources.list
}
setAliyun(){
sed -i 's/cdn-fastly.deb.debian.org/mirrors.aliyun.com/'g /etc/apt/sources.list
}
restore(){
if [ -f /etc/apt/sources.list.bak ]; then
rm /etc/apt/sources.list
mv /etc/apt/sources.list.bak /etc/apt/sources.list
elif [ -f /etc/yum.repos.d/CentOS-Base.repo.bak ]; then
rm /etc/yum.repos.d/CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo.bak /etc/yum.repos.d/CentOS-Base.repo
fi
}
setSources(){
getAbout
updateInit
case "$release" in
debian)
case $para in
'fastly'|'-fastly'|'--fastly' )
setDebian;;
'cn'|'-cn'|'--cn' )
setDebian;setCn;;
'163'|'-163'|'--163' )
setDebian;set163;;
'aliyun'|'-aliyun'|'--aliyun' )
setDebian;setAliyun;;
'aws'|'-aws'|'--aws' )
setDebian;setAWS;;
'restore'|'-restore'|'--restore' )
restore;;
*)
setDebian;;
esac
apt-get update;;
ubuntu)
case $para in
'restore'|'-restore'|'--restore' )
restore;;
*)
setUbuntu;
esac
apt-get update;;
centos)
case $para in
'restore'|'-restore'|'--restore' )
restore;;
*)
setCentos;
esac
yum makecache;;
esac
}
para=$1
setSources
echo -e "${GREEN}Done${PLAIN}"