Shell脚本手动配置阿里云源
#!/bin/bash
#author:wz
#功能:配置aliyun源
#ping阿里云镜像源网站测试连通性
ping -c 5 mirrors.aliyun.com
if [[ $? -eq 0 ]];then
echo "成功访问阿里云镜像源网站,继续执行"
else
echo "访问阿里云镜像源网站失败,检查网络连通性,退出!"
exit
fi
#用户输入备份地址
read -p "请输入备份地址:" bkpath
mv /etc/yum.repos.d/* ${bkpath}
if [[ $? -eq 0 ]];then
echo "备份成功,继续执行"
else
echo "备份失败,检查备份目标目录,退出!"
exit
fi
#用户输入BaseOs仓库地址
read -p "请输入仓库地址(BaseOs):" baseurl
cat > aliyun.repo << EOF
[BaseOs]
name=Aliyun Rocky Linux \$releasever - BaseOS
baseurl=${baseurl}
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-9
[AppStream]
name=Aliyun Rocky Linux \$releasever - AppStream
baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/AppStream/\$basearch/os/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-9
[Extras]
name=Aliyun Rocky Linux \$releasever - Extras
baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/extras/\$basearch/os/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-9
EOF
dnf clean all
dnf makecache
dnf repolist
#/!bin/bash
#author:wz
#功能:回滚aliyun源配置
rm -f /etc/yum.repos.d/*.repo
if [[ $? -eq 0 ]];then
echo "repo文件已删除"
else
echo "repo文件删除失败,退出!"
exit
fi
read -p "输入备份源地址:" bkpath
mv ${bkpath}/* /etc/yum.repos.d/
if [[ $? -eq 0 ]];then
echo "备份文件已恢复"
else
echo "备份文件恢复失败,检查源目录,退出!"
exit
fi
dnf clean all
dnf makecache
dnf repolist
许可协议:
CC BY 4.0