-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdateLinuxSourceCN.sh
206 lines (175 loc) · 4.48 KB
/
UpdateLinuxSourceCN.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
#!/bin/bash
author=rami
# github=https://github.com/elliot-bia/Linux_tools.git
echo "author=$author"
MirrorsList(){
echo "选择对应的源"
echo "1. 清华(默认)"
echo "2. 阿里"
echo "3. 腾讯"
echo "4. 163"
echo "5. 华为"
echo "6. 中科大"
read -r -p "请选择对应的源(默认可以直接回车): " MirrorsOption </dev/tty
# 根据不同的输入选择对应的变量
case $MirrorsOption in
"")
MirrorsSites="mirrors.tuna.tsinghua.edu.cn"
;;
1)
MirrorsSites="mirrors.tuna.tsinghua.edu.cn"
;;
2)
MirrorsSites="mirrors.aliyun.com"
;;
3)
MirrorsSites="mirrors.cloud.tencent.com"
;;
4)
MirrorsSites="mirrors.163.com"
;;
5)
MirrorsSites="repo.huaweicloud.com"
;;
6)
MirrorsSites="mirrors.ustc.edu.cn"
;;
*)
echo "选择出错!."
echo "操作被中断."
exit 1
;;
esac
echo "选择的镜像源值为: $MirrorsSites"
}
UbuntuAptSource(){
# Ubuntu 操作系统
echo -e "This is Ubuntu.\nUpdating source"
MirrorsList
sudo sed -e "s#//.*archive.ubuntu.com#//$MirrorsSites#g" \
-e "s#//.*security.ubuntu.com#//$MirrorsSites#g" \
-i.bak \
/etc/apt/sources.list
sudo apt-get clean all;\
sudo apt-get update
}
CentOS7YumSource(){
# CentOS 7 操作系统
echo "CentOS 7, updating source"
MirrorsList
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://$MirrorsSites/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-Base.repo
yum clean all;\
yum makecache
}
DebianAptSource(){
# Ubuntu 操作系统
echo -e "This is Debian\nUpdating source"
MirrorsList
sudo apt-get install apt-transport-https ca-certificates -y
sudo sed -e "s@http://.*debian.org@https://$MirrorsSites@g" \
-i.bak \
/etc/apt/sources.list
sudo apt-get clean all;\
sudo apt-get update
}
KaliAptSource(){
# Ubuntu 操作系统
echo -e "This is Kali.\nUpdating source"
MirrorsList
sudo apt-get install apt-transport-https ca-certificates -y
sudo sed -e "s#http://http.kali.org/kali#https://$MirrorsSites/kali#g" \
-i.bak \
/etc/apt/sources.list
sudo apt-get clean all;\
sudo apt-get update
}
get_system_info() {
if [[ $(cat /etc/os-release) == *"Ubuntu"* ]]; then
system_info="Ubuntu"
elif [[ $(cat /etc/os-release) == *"CentOS"* && $(cat /etc/centos-release) == *"7."* ]]; then
system_info="CentOS 7"
elif [[ $(cat /etc/os-release) == *"kali"* ]]; then
system_info="Kali"
elif [[ $(cat /etc/os-release) == *"debian"* ]]; then
system_info="Debian"
else
# 其他操作系统
system_info="Other OS"
fi
}
# 主函数
main() {
get_system_info
# 根据系统信息设置选项值
case $system_info in
"Ubuntu")
OPTION=1
;;
"CentOS 7")
OPTION=2
;;
"Kali")
OPTION=3
;;
"Debian")
OPTION=4
;;
*)
echo "未知的系统."
;;
esac
# 选项菜单
echo -e "\n检测到Linux系统为: $system_info\n"
echo "如果有其他系统,可以选择对应的数字"
echo "1. Ubuntu"
echo "2. CentOS 7"
echo "3. Kali"
echo "4. Debian"
read -r -p "当前系统为: $system_info, 请问是否正确?(y/n): " choice </dev/tty
if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then
case $OPTION in
1)
UbuntuAptSource
;;
2)
CentOS7YumSource
;;
3)
KaliAptSource
;;
4)
DebianAptSource
;;
*)
echo "无效的选项."
echo "操作被中断."
exit 1
;;
esac
else
case $choice in
1)
UbuntuAptSource
;;
2)
CentOS7YumSource
;;
3)
KaliAptSource
;;
4)
DebianAptSource
;;
*)
echo "无效的选项."
echo "操作被中断."
exit 1
;;
esac
fi
}
# 执行主函数
main