agon-Archive for March, 2013

Archive for March, 2013

centos6自动添加与设置第三方源脚本

March 3rd, 2013, Posted by: agon   

centos安装第三方源的文章已经很多,但是看着要去一堆网站,一个个下载安装,再导入,设置优先级,实在很繁琐无聊,所以写了个脚本,自动下载、安装和设置,安装的源有EPEL,RPMForge,Remi和rpmfusion。

本机操作系统:
LSB Version:core-4.0-ia32:core-4.0-noarch:
Distributor ID: CentOS
Description: CentOS release 6.3 (Final)
Release: 6.3
Codename: Final

!!!注意,请务必知道下面的东东是干什么的,或者在虚拟机里试过再用。
源码下载地址

#!/bin/sh
##auto-install third repo for centos6.3
##2013-03-01
##########################################
#安装CentOS yum源优先级插件
yes | yum install yum-priorities

##########################################
#设置默认yum源
#备份
if
[[ ! -f "/etc/yum.repos.d/CentOS-Base.repo.bak" ]]; then  
	cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
else
	cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.yourbak
fi
#删除旧的优先级,如果有的话
sed '/priority=.*/d' /etc/yum.repos.d/CentOS-Base.repo
#设置[base]、[updates]、[extras]优先级为priority=1【1】
sed -i "s/\[updates\]/priority=1\n[updates]/g" /etc/yum.repos.d/CentOS-Base.repo #【2】
sed -i "s/\[extras\]/priority=1\n[extras]/g" /etc/yum.repos.d/CentOS-Base.repo
sed -i "s/\[centosplus\]/priority=1\n[centosplus]/g" /etc/yum.repos.d/CentOS-Base.repo
#设置[centosplus]、[contrib]优先级为priority=2
sed -i "s/\[contrib\]/priority=2\n[contrib]/g" /etc/yum.repos.d/CentOS-Base.repo
sed -i '$a priority=2' /etc/yum.repos.d/CentOS-Base.repo

##########################################
#下面安装第三方源 【3】
##########################################

# 安装EPEL源 
# 1、到 EPELwiki下载你系统的版本
wget http://mirrors.sohu.com/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-*.noarch.rpm

#2、导入GPGkey
sleep 5
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

#3、设置优先级为11
sed -i "s/\[epel-debuginfo\]/priority=11\n[epel-debuginfo]/g" /etc/yum.repos.d/epel.repo 



##########################################
# 安装RPMForge源【4】

#1、在repoforge.org,找你系统需要的rpm包,替换下面的地址
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

#2、导入GPGkey
sleep 5
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
#如果报'error message like the following the key has already been importedh'执行以下命令:
if (( $? )); then 
rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm
fi

#3、安装rpmforge包
rpm -ivh rpmforge-release-0.5.2-2.el6.rf.*.rpm
#4、设置优先级为12
sed -i 's/\[rpmforge-extras\]/priority=12\n[rpmforge-extras]/g' /etc/yum.repos.d/rpmforge.repo


##########################################
# 安装Remi设置源

#1、在rpms.famillecollet.com,找你系统需要的rpm包,替换下面的地址
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

#2、安装Remi包
rpm -ivh remi-release-6.rpm

#3、导入GPGkey
sleep 5
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi

#4、启用Remi,及设置优先级
sed -i '1,8s/enabled=0/enabled=1\npriority=13/g' /etc/yum.repos.d/remi.repo


##########################################
# 安装RPMFusion源

#1、在rpmfusion.org/Configuration,找你系统需要的rpm包,替换下面的地址
wget http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm

#2、安装Remi包
rpm -ivh rpmfusion-free-release-6-*.noarch.rpm

#3、启用rpmfution,设置优先级
sed -i '1,8s/enabled=0/enabled=1\npriority=14/g' /etc/yum.repos.d/rpmfusion-free-updates-testing.repo



##########################################
#更新yum软件包
yum check-update
#查看已经安装的软件源
yum repolist
Page 1 of 11