CentOS更新源的shell脚本

本文介绍了一个用于更新 CentOS 系统中 Yum 工具的 Bash 脚本,并详细展示了如何下载并安装新的 Yum 组件,以及如何配置使用网易 163 镜像源的方法。
#!/bin/bash
 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
 export PATH
 
 # Check if user is root
 if [ $(id -u) != "0" ]; then
     echo "Error: You must be root to run this script"
     exit 1
 fi
 clear
 echo "========================================================================="
 echo "CentOS Yum and Repos"
 echo "========================================================================="
  
 # update yum
 echo "Update Yum......"
 rpm -qa|grep yum|xargs rpm -e --nodeps
 # delete old rpm
 echo "Clean old cache......"
 rm -rf python-iniparse-0.3.1-2.1.el6.noarch.rpm
 rm -rf yum-metadata-parser-1.1.2-14.1.el6.i686.rpm
 rm -rf yum-3.2.27-14.el6.centos.noarch.rpm
 rm -rf yum-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm
 # download CentOS Yum
 echo "Download Python-iniparse......"
 wget http://mirrors.163.com/centos/6.2/os/i386/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
 echo "Download yum-metadata-parse......"
 wget http://mirrors.163.com/centos/6.2/os/i386/Packages/yum-metadata-parser-1.1.2-16.el6.i686.rpm
 echo "Download yum......"
 wget http://mirrors.163.com/centos/6.2/os/i386/Packages/yum-3.2.29-22.el6.centos.noarch.rpm
 echo "Download yum fastmirror......"
 wget http://mirrors.163.com/centos/6.2/os/i386/Packages/yum-plugin-fastestmirror-1.1.30-10.el6.noarch.rpm
 # install CentOS Yum
 echo "Installing......"
 rpm -ivh  python-iniparse-0.3.1-2.1.el6.noarch.rpm
 rpm -ivh  yum-metadata-parser-1.1.2-16.el6.i686.rpm
 rpm -ivh  yum-3.2.29-22.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-10.el6.noarch.rpm
 # replace repos
 rm -rf /etc/yum.repos.d/CentOS6-Base-163.repo
 echo "[base]
 name=CentOS-6.2 - Base - 163.com
 baseurl=http://mirrors.163.com/centos/6.2/os/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=6.2&arch=$basearch&repo=os
 gpgcheck=1
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
 
 #released updates 
 [updates]
 name=CentOS-6.2 - Updates - 163.com
 baseurl=http://mirrors.163.com/centos/6.2/updates/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=6.2&arch=$basearch&repo=updates
 gpgcheck=1
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
 
 #additional packages that may be useful
 [extras]
 name=CentOS-6.2 - Extras - 163.com
 baseurl=http://mirrors.163.com/centos/6.2/extras/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=6.2&arch=$basearch&repo=extras
 gpgcheck=1
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
 
 #additional packages that extend functionality of existing packages
 [centosplus]
 name=CentOS-6.2 - Plus - 163.com
 baseurl=http://mirrors.163.com/centos/6.2/centosplus/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=6.2&arch=$basearch&repo=centosplus
 gpgcheck=1
 enabled=0
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
 
 #contrib - packages by Centos Users
 [contrib]
 name=CentOS-6.2 - Contrib - 163.com
 baseurl=http://mirrors.163.com/centos/6.2/contrib/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=6.2&arch=$basearch&repo=contrib
 gpgcheck=1
 enabled=0
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6" >> /etc/yum.repos.d/CentOS6-Base-163.repo
 
 #####
 yum clean all
 yum makecache
 yum update
 
 echo "=========================================================================="
 echo "You have successfully created CentOS yum and repos"
 echo "=========================================================================="

转载于:https://my.oschina.net/mickelfeng/blog/99594

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值