forked from berlin493/github4shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathali_mirrors.sh
247 lines (218 loc) · 7.32 KB
/
ali_mirrors.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
#!/bin/bash
centos_mirrors='mirrors.aliyun.com'
epel_mirrors='mirrors.aliyun.com'
debian_mirrors='mirrors.aliyun.com'
cache_server='cache.mirrors.local'
#set DNS
grep 'cache.mirrors.local' /etc/hosts >/dev/null 2>&1 ||\
echo '10.211.16.250 cache.mirrors.local' >> /etc/hosts
alias_yum () {
profile_dir='/etc/profile.d'
[ -d "${profile_dir}" ] &&\
yum_para='yum --skip-broken --nogpgcheck'
echo "alias yum='${yum_para}'" > ${profile_dir}/yum_alias.sh
alias yum="${yum_para}"
}
backup_local_repo_file () {
local my_date=`date -d "now" +"%F"`
if [ -d "${SOURCE_DIR}" ];then
find ${SOURCE_DIR} -type f -name "*.repo"|grep -Ev 'CENTOS.*-lan.repo|RHEL.*-lan.repo'|\
while read source_file
do
mv "${source_file}" "${source_file}.${my_date}.$$"
done
fi
}
backup_source_list () {
local source_file="${SOURCE_DIR}/sources.list"
if [ -e ${source_file} ];then
local my_date=`date -d "now" +"%F"`
mv "${source_file}" "${source_file}.${my_date}.$$"
else
echo "Can not find ${source_file},please check!" 1>&2
fi
}
mirrors_for_centos () {
local redhat_version=`grep -oP '\d' /etc/redhat-release|head -n1`
local repo_file="${SOURCE_DIR}/base.mirrors.repo"
echo "[base]
name=CentOS-${redhat_version} - Base - ${centos_mirrors}
failovermethod=priority
baseurl=http://${centos_mirrors}/centos/${redhat_version}/os/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=\$basearch&repo=os
gpgcheck=1
gpgkey=http://${centos_mirrors}/centos/RPM-GPG-KEY-CentOS-${redhat_version}
#released updates
[updates]
name=CentOS-${redhat_version} - Updates - ${centos_mirrors}
failovermethod=priority
baseurl=http://${centos_mirrors}/centos/${redhat_version}/updates/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=\$basearch&repo=updates
gpgcheck=1
gpgkey=http://${centos_mirrors}/centos/RPM-GPG-KEY-CentOS-${redhat_version}
#additional packages that may be useful
[extras]
name=CentOS-${redhat_version} - Extras - ${centos_mirrors}
failovermethod=priority
baseurl=http://${centos_mirrors}/centos/${redhat_version}/extras/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=\$basearch&repo=extras
gpgcheck=1
gpgkey=http://${centos_mirrors}/centos/RPM-GPG-KEY-CentOS-${redhat_version}
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-${redhat_version} - Plus - ${centos_mirrors}
failovermethod=priority
baseurl=http://${centos_mirrors}/centos/${redhat_version}/centosplus/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=\$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://${centos_mirrors}/centos/RPM-GPG-KEY-CentOS-${redhat_version}
#contrib - packages by Centos Users
[contrib]
name=CentOS-${redhat_version} - Contrib - ${centos_mirrors}
failovermethod=priority
baseurl=http://${centos_mirrors}/centos/${redhat_version}/contrib/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=\$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://${centos_mirrors}/centos/RPM-GPG-KEY-CentOS-${redhat_version}" > ${repo_file}
}
mirrors_for_epel () {
local repo_file="${SOURCE_DIR}/epel.mirrors.repo"
echo "[epel]
name=Extra Packages for Enterprise Linux \$releasever - \$basearch
baseurl=http://${epel_mirrors}/epel/\$releasever/\$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=http://${epel_mirrors}/epel/RPM-GPG-KEY-EPEL
[epel-debuginfo]
name=Extra Packages for Enterprise Linux \$releasever - \$basearch - Debug
baseurl=http://${epel_mirrors}/epel/\$releasever/\$basearch/debug
failovermethod=priority
enabled=0
gpgkey=http://${epel_mirrors}/epel/RPM-GPG-KEY-EPEL
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux \$releasever - \$basearch - Source
baseurl=http://${epel_mirrors}/epel/\$releasever/SRPMS
failovermethod=priority
enabled=0
gpgkey=http://${epel_mirrors}/epel/RPM-GPG-KEY-EPEL
gpgcheck=1
[epel-testing]
name=Extra Packages for Enterprise Linux \$releasever - Testing - \$basearch
baseurl=http://${epel_mirrors}/epel/testing/\$releasever/\$basearch
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=http://${epel_mirrors}/epel/RPM-GPG-KEY-EPEL
[epel-testing-debuginfo]
name=Extra Packages for Enterprise Linux \$releasever - Testing - \$basearch - Debug
baseurl=http://${epel_mirrors}/epel/testing/\$releasever/\$basearch
failovermethod=priority
enabled=0
gpgkey=http://${epel_mirrors}/epel/RPM-GPG-KEY-EPEL
gpgcheck=1
[epel-testing-source]
name=Extra Packages for Enterprise Linux \$releasever - Testing - \$basearch - Source
baseurl=http://${epel_mirrors}/epel/testing/\$releasever/SRPMS
failovermethod=priority
enabled=0
gpgkey=http://${epel_mirrors}/epel/RPM-GPG-KEY-EPEL
gpgcheck=1" > ${repo_file}
}
mirrors_for_debian () {
local source_file="${SOURCE_DIR}/sources.list"
debian_release=`grep -oP '\d' /etc/debian_version |head -n1`
case "${debian_release}" in
8)
DEBIAN_VERSION='jessie'
DEBIAN_ISSUE='8'
;;
7)
DEBIAN_VERSION='wheezy'
DEBIAN_ISSUE='7'
;;
6)
DEBIAN_VERSION='squeeze'
DEBIAN_ISSUE='6'
;;
*)
echo "This script not support ${SYSTEM_INFO}" 1>&2
exit 1
;;
esac
backup_source_list
echo "deb http://${debian_mirrors}/debian/ ${DEBIAN_VERSION} main non-free contrib
deb http://${debian_mirrors}/debian/ ${DEBIAN_VERSION}-proposed-updates main non-free contrib
deb-src http://${debian_mirrors}/debian/ ${DEBIAN_VERSION} main non-free contrib
deb-src http://${debian_mirrors}/debian/ ${DEBIAN_VERSION}-proposed-updates main non-free contrib" > ${source_file}
apt_path='/etc/apt/sources.list.d'
if [ "${DEBIAN_VERSION}" == 'wheezy' ];then
test -d ${apt_path} &&\
echo "deb http://debian.saltstack.com/debian wheezy-saltstack main" > ${apt_path}/salt.list
fi
if [ "${DEBIAN_VERSION}" == 'squeeze' ];then
test -d ${apt_path} &&\
echo "deb http://debian.saltstack.com/debian squeeze-saltstack main
deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free" > ${apt_path}/salt.list
fi
local apt_conf_d='/etc/apt/apt.conf.d'
local apt_conf="${apt_conf_d}/00trustlocal"
test -d ${apt_conf_d} || mkdir -p ${apt_conf_d}
echo 'Aptitude::Cmdline::ignore-trust-violations "true";' > ${apt_conf}
}
set_proxy_for_debian () {
local apt_conf_d='/etc/apt/apt.conf.d'
local proxy_conf="${apt_conf_d}/02proxy"
test -d ${apt_conf_d} &&\
echo 'Acquire::http { Proxy "http://'${cache_server}':3142"; };' > ${proxy_conf}
}
set_proxy_for_redhat () {
local yum_conf='/etc/yum.conf'
if [ -f "${yum_conf}" ];then
sed -i '/^proxy/d' ${yum_conf}
echo "proxy=http://${cache_server}:3142" >> ${yum_conf}
fi
}
set_for_redhat () {
backup_local_repo_file
mirrors_for_centos
mirrors_for_epel
set_proxy_for_redhat
alias_yum
yum clean all
}
alias_apt () {
local apt_conf_d='/etc/apt/apt.conf.d'
local apt_conf="${apt_conf_d}/00trustlocal"
test -d ${apt_conf_d} || mkdir -p ${apt_conf_d}
echo 'Aptitude::Cmdline::ignore-trust-violations "true";' > ${apt_conf}
#aptitude update
}
main () {
ls /etc/debian_version >/dev/null 2>&1 && OS='debian'
ls /etc/redhat-release >/dev/null 2>&1 && OS='redhat'
case "${OS}" in
redhat)
SYSTEM='rhel'
SOURCE_DIR='/etc/yum.repos.d'
set_for_redhat
;;
debian)
SYSTEM='debian'
SOURCE_DIR='/etc/apt'
mirrors_for_debian
alias_apt
set_proxy_for_debian
aptitude update
;;
*)
SYSTEM='unknown'
echo "This script not support ${SYSTEM_INFO}"1>&2
exit 1
;;
esac
}
main