写一个脚本,完成以下功能:
说明:此脚本能于同一个repo文件中创建多个yum源指向;
1、接收一个文件名作为参数,此文件存放至/etc/yum.repos.d目录中,且文件名以.repo为后缀;
要求,此文件不能实现存在,否则,报错
2、在脚本中,提醒用户输入repo id;如果为quit,则退出脚本;否则,继续完成下面的步骤;
3、repo name以及baseurl的路径,而后以repo文件的格式将其保存至指定的文件中;
4、enabled默认为1,而gpgcheck默认设定为0;
5、此脚本会循环执行多次,除非用户为repo id指定为quit;
vim repos.d.sh
#!/bin/bash
#
REPOFILE=/etc/yum.repos.d/$1
if [ -e $1 ]; then
echo " $1 is exist"
exit 3
fi
read -p "Repostory ID:" REPOID
until [ $REPOID == ‘quit‘ ]; do
echo "[$REPOID]" >> $REPOFILE
read -p "Repostory name:" REPONAME
echo "name=$REPONAME" >> $REPOFILE
read -p "Repostory Baseurl:" BASEURL
echo "baseusr=$BASEURL" >> $REPOFILE
echo -e "gpgcheck=0\nenabled=1" >> $REPOFILE
read -p "Repostory ID:" REPOID
done
[[email protected] test]# ./repos.d.sh create.repo
Repostory ID:hello
Repostory name:hello world
Repostory Baseurl:ftp://10.109.134.247
Repostory ID:quit
[[email protected] test]# cat /etc/yum.repos.d/create.repo
[hello]
name=hello world
baseusr=ftp://10.109.134.247
gpgcheck=0
enabled=1