Skip to content

Instantly share code, notes, and snippets.

@sarkrui
Created February 6, 2022 08:36
Show Gist options
  • Save sarkrui/fd0f585e47077f2c314802c62e26ba78 to your computer and use it in GitHub Desktop.
Save sarkrui/fd0f585e47077f2c314802c62e26ba78 to your computer and use it in GitHub Desktop.
更换 Centos 服务器 yum & epel 源
#! /bin/bash
# Author:Nahsoagoac
# 更换centos服务器yum源和epel源
if [ ! -f /etc/redhat-release ]; then
OS='ubuntu'
else
CENTOS_VER=$(rpm -q centos-release|cut -d- -f3)
fi
msgbox()
{
case $1 in
text ) color="\e[34;1m"
;;
alert ) color="\e[31;1m"
;;
result ) color="\e[33;1m"
;;
jump ) color="\e[35;1m"
;;
pam ) color="\e[32;1m"
esac
echo -e "${color}${2}\e[0m\c"
}
yanshi()
{
for (( i = 0; i < ${1}; i++ )); do
sleep 0.3
msgbox "alert" "."
done
}
if [[ $OS = 'ubuntu' ]]; then
msgbox "alert" "检测到目前系统为ubuntu,脚本不适用,退出。";echo
else
msgbox "text" "+===================================+";echo
msgbox "text" "| 检测到当前系统版本为";msgbox "pam" "centos$CENTOS_VER";msgbox "text" " |";echo
msgbox "text" "| 脚本功能:更改系统yum源和epel源 |";echo
msgbox "text" "+===================================+";echo
yanshi "5";echo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
msgbox "result" "已备份原有yum源文件为/etc/yum.repos.d/CentOS-Base.repo.backup";echo
yanshi "5";echo
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
msgbox "result" "已备份原有epel源文件为/etc/yum.repos.d/epel.repo.backup";echo
yanshi "5";echo
case $CENTOS_VER in
5 ) wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo
;;
6 ) wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
;;
7 ) wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
;;
* )
;;
esac
yum clean all
yum makecache
msgbox "result" "已更新yum源和epel源";echo
fi
@sarkrui
Copy link
Author

sarkrui commented Feb 6, 2022

bash <(curl -s -L https://gist.githubusercontent.com/sarkrui/fd0f585e47077f2c314802c62e26ba78/raw/75d74f1d5572fcf2ba774279c2534e35c397afe4/chgyumepel.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment