提交镜像
This commit is contained in:
parent
fc436be55f
commit
86f86789b6
42
Linux/Shell/auto_mirror.sh
Normal file
42
Linux/Shell/auto_mirror.sh
Normal file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 定义阿里云软件源URL
|
||||
ALIYUN_UBUNTU_REPO="http://mirrors.aliyun.com/ubuntu/"
|
||||
ALIYUN_CENTOS_REPO="http://mirrors.aliyun.com CentOS-"
|
||||
|
||||
# 检测操作系统类型
|
||||
OS=$(cat /etc/os-release | grep ^ID= | cut -d '=' -f2)
|
||||
VERSION=$(cat /etc/os-release | grep ^VERSION_ID= | cut -d '=' -f2)
|
||||
|
||||
# 根据操作系统类型切换软件源
|
||||
case "$OS" in
|
||||
"ubuntu" | "debian")
|
||||
# 备份原软件源文件
|
||||
cp /etc/apt/sources.list /etc/apt/sources.list.bak
|
||||
# 替换为阿里云软件源
|
||||
sed -i "s/^\(deb\s\+http:\/\/archive\.ubuntu\.com\/ubuntu\)\s\+${VERSION}\s\+main$/\1 ${VERSION} main restricted/" /etc/apt/sources.list
|
||||
sed -i "s/^\(deb\s\+http:\/\/security\.ubuntu\.com\/ubuntu\)\s\+${VERSION}\s\+security$/\1 ${VERSION}-security main restricted/" /etc/apt/sources.list
|
||||
sed -i "s/http:\/\/archive\.ubuntu\.com\/ubuntu\//${ALIYUN_UBUNTU_REPO}/g" /etc/apt/sources.list
|
||||
sed -i "s/http:\/\/security\.ubuntu\.com\/ubuntu\//${ALIYUN_UBUNTU_REPO}/g" /etc/apt/sources.list
|
||||
# 更新软件包列表
|
||||
apt update
|
||||
;;
|
||||
"centos" | "rhel")
|
||||
# 备份原软件源文件
|
||||
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
|
||||
# 替换为阿里云软件源
|
||||
sed -i "s/mirrorlist=/#mirrorlist=/g" /etc/yum.repos.d/CentOS-Base.repo
|
||||
sed -i "s/^#baseurl=/baseurl=/g" /etc/yum.repos.d/CentOS-Base.repo
|
||||
sed -i "s/http:\/\/mirror\.centos\.org\/centos\//${ALIYUN_CENTOS_REPO}/g" /etc/yum.repos.d/CentOS-Base.repo
|
||||
# 清除缓存并生成新的缓存
|
||||
yum clean all
|
||||
yum makecache
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported OS: $OS"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Software source has been switched to Aliyun mirror for $OS."
|
||||
|
Loading…
x
Reference in New Issue
Block a user