[iyunv@localhost yum.repos.d]# cat /server/scripts/auto_install_yum_source.sh
#!/bin/bash
# create date of 2013-10-16
# author of cfwl
# Source function library
. /etc/rc.d/init.d/functions
# User custom variable
YUM_BACK_DIR=/etc/yum.repos.d/backup/
YUM_DIR=/etc/yum.repos.d/
MOUNT_DIR=/mnt/cdrom/
# User custom function
LOCAL_YUM_SOURCE(){
# Judge YUM_BACK_DIR directory if exist
[ ! -d ${YUM_BACK_DIR} ] && mkdir ${YUM_BACK_DIR}
cd ${YUM_DIR}
find . -type f -name "*.repo" | xargs mv -t ${YUM_BACK_DIR}
RETVAL=0
[ $? = ${RETVAL} ] && mv ${YUM_BACK_DIR}/CentOS-Media.repo ${YUM_DIR} && action "File mv is successfully." /bin/true &&
cp -a CentOS-Media.repo CentOS-Media.repo.save
sed -i 's/baseurl=file:\/\/\/media\/CentOS\//baseurl=file:\/\/\/mnt\/cdrom\//g'CentOS-Media.repo
sed -i 's/file:\/\/\/media\/cdrom\///g' CentOS-Media.repo
sed -i 's/file:\/\/\/media\/cdrecorder\///g' CentOS-Media.repo
sed -i 's/enabled=0/enabled=1/g' CentOS-Media.repo
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-*
sleep 2
# Judge mount directory if exsit
[ ! -d ${MOUNT_DIR} ] && mkdir ${MOUNT_DIR} && printf "\033[33mdirectory ${MOUNT_DIR} yet by create.\n\033[0m"
[ $? = 0 ] && mount /dev/cdrom ${MOUNT_DIR} && printf "\033[33mmount mirrors is successfully.\n\033[0m"
sleep 2
#yum cache
yum makecache
}
NETWORK_YUM_SOURCE(){
# Judge YUM_BACK_DIR directory if exist
[ ! -d ${YUM_BACK_DIR} ] && mkdir ${YUM_BACK_DIR}
cd ${YUM_DIR}
find . -type f -name "*.repo" | xargs mv -t ${YUM_BACK_DIR}
RETVAL=0
[ $? = ${RETVAL} ] && printf "\033[32m
1 Inland 163 yum source
2 Inland sohu yum source
please input install 163 or sohu yum source:\033[0m" str
read str
case "$str" in
163)
RETVAL=0
[ $? = ${RETVAL} ] && printf "\033[35m yum source is download successfully of 163 mirrors.\n\033[0m"
sleep 2
yum makecache
;;
sohu)
RETVAL=0
[ $? = ${RETVAL} ] && printf "\033[35m yum source is download successfully of sohu mirrors.\n\033[0m"
sleep 2
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-*
yum makecache
;;
*)
echo -e "\033[31m Error: plase you input 163 or sohu.\033[0m"
esac
}
# Select auto install list of print
printf "\033[32m
1 Local Yum Source
2 Network Yum Source
please input auto install de mode(local or network):\033[0m" str
read str
case "$str" in
local)
LOCAL_YUM_SOURCE
;;
network)
NETWORK_YUM_SOURCE
;;
*)
echo -e "\033[31m Error: please input local or network. \033[0m"
esac
2、安装网络YUM源