|
#!/bin/bash
# Author:soy sauce
# Date:2015-11-30 20:00
# Description:repo file
# Version 1.0
[ $# -lt 1 ] && echo "Usage: `basename $0` repofile_name" && exit 3
RepoFile=/etc/yum.repos.d/$1
[ -e $RepoFile ] && echo "$RepoFile exists." && exit 4
while true; do
read -p "Please input the repo id: " RepoID
[ $RepoID == 'quit' ] && exit 5
read -p "Please input the repo name: " RepoName
read -p "Please input the baseurl: " BaseUrl
echo -e "[$RepoID]\nname=${RopoName}\nbaseurl=${BaseUrl}\nenabled=1\ngpgcheck=0" >> $RepoFile
continue # 此处提前结束本轮循环,而后进入下一循环
done
[root@soysauce scripts]# ./mkrepo.sh test.repo
Please input the repo id: testyum
Please input the repo name: testyum
Please input the baseurl: file:///root/test/testyum
Please input the repo id: quit
[root@soysauce scripts]# cat /etc/yum.repos.d/test.repo # repo文件已然生成
[testyum]
name=
baseurl=file:///root/test/testyum
enabled=1
gpgcheck=0
[root@soysauce scripts]# yum repolist # 可以看到testyum已然生效
Loaded plugins: fastestmirror
Repository 'testyum' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
* epel: mirror01.idc.hinet.net
testyum | 2.9 kB 00:00 ...
testyum/primary_db | 90 kB 00:00 ...
repo id repo name status
base CentOS-6 - Base - 163.com 6,575
epel Extra Packages for Enterprise Linux 6 - x86_64 11,886
extras CentOS-6 - Extras - 163.com 45
testyum testyum 147
updates CentOS-6 - Updates - 163.com 670
repolist: 19,323
|
|
|