本博客是我自制的两个yum配置脚本,一个是用户交互版本,用户可以在脚本运行过程中指定各种配置细节;另一种是将各种配置已经预定义好了,适合大规模配置,下面我来看脚本吧,其实有Linux shell基础的通知应该闭着眼睛都能看懂的。
yum源配置脚本用户交互版
#!/bin/bash
echo '*********************************************************'
echo '* *'
echo '* Welcome to yum sources configration *'
echo '* *'
echo '*********************************************************'
echo -e '\n'
read -p 'please confirm to empty the directory /etc/yum.repo.d/(yes/no): ' choice
if [ $choice = 'yes' ] || [ $choice = 'Y' ] || [ $choice = 'y' ]
then
rm -rf /etc/yum.repos.d/*
echo 'Directory cleaned!'
elif [ $choice = 'no' ] || [ $choice = 'N' ] || [ $choice = 'n' ]
then
echo 'You chose to reserver files in /etc/yum.repo.d/ !'
else
echo 'Unmatched input, next command will be conducted!'
fi
read -p 'Please specify your repo file name(eg:myrepo.repo): ' repoName
fullPath=/etc/yum.repos.d/${repoName}
if [ -e $fullPath ]
then
echo 'File exists!'
else
touch /etc/yum.repos.d/${repoName}
echo 'File not exists, script has create it!'
fi
read -p 'Please input your yum source name(eg:[halo]): ' sourceName
echo -e '\n'
echo [$sourceName] >>/etc/yum.repos.d/${repoName}
read -p 'Please input your yum source description: ' sourceDesc
echo 'name='$sourceDesc >>/etc/yum.repos.d/${repoName}
echo 'Please input your yum source baseurl: '
echo -e '\n'
echo ' eg1(for http):http://172.25.254.36/iso/'
echo ' eg2(for ftp):ftp://172.25.254.36/iso/'
echo ' eg3(for file):file:///var/www/html/rhel7.1'
read baseurl
echo 'baseurl='$baseurl>>/etc/yum.repos.d/${repoName}
read -p 'Please input your gpgcheck number(0|1): ' gpgcheck
echo 'gpgcheck='${gpgcheck} >>/etc/yum.repos.d/${repoName}
echo 'Config OK!'
yum clean all
yum源配置脚本预定义配置版
#!/bin/bash
rm -rf /etc/yum.repos.d/*
cat >> /etc/yum.repos.d/yum.repo <<end
[yum-configured-by-lockey]
name=rhel7.2 iso
baseurl=http://172.25.254.36/iso
gpgcheck=0
end
yum clean all
脚本虽然简单,但毕竟算个脚本,总比手动一个个输入强很多啊!!! |