前面写过关于自动搭建yum的脚本,感觉不够完善。下面这个脚本在前面的基础上加上判断,如果yum已经搭建好,那么不安装;没有搭建则安装。
1[[email protected] ~]# vim testyum.sh
Script Content
#!/bin/bash
n=yum repolist | grep ‘repolist‘| awk ‘{print $2}‘
If [$ (N))-GT 0]; Then
echo "Yum source already Installed"
Exit
elif [$ ((N))-eq 0];then
rm-rf/etc/yum.repos.d/*
echo "[+] //Note from the start of this line to Gpgcheck=0 to write the head, if not, then the Yum file will produce a malformed
name=110
Baseurl=http://192.168.4.254/rhel7
Enabled=1
Gpgcheck=0 ">/etc/yum.repos.d/110.repo
Yum Clean all &>/dev/null
echo "Yum has been built"
echo "Shared packages:"
Yum Repolist | Tail-1
Fi
[Email protected] ~]# chmod +x/root/testyum.sh
2 Testing
Already built the test
[Email protected] ~]#./testyum.sh
Yum Source is already installed
No test setup.
[Email protected] ~]# rm-rf/etc/yum.repos.d/*
[Email protected] ~]#./testyum.sh
Yum has been built to complete
Total Packages:
repolist:4,620
Shell script: auto-build Yum (upgrade version)