自动部署yum

#!/bin/bash
#author:dcc
#date:2018/05/25
#version:v1
#description:auto config yum.repo,you must provide a url of the yum.repo

#define log path
log_path="/var/log/define_yum.log"
dirname="/etc/yum.repos.d/"

#clead unusable yum.repo
if [ -z $1 ];then
	echo "`date`:error_code:2;url is not exist!" >> $log_path
	echo "Usage:$0 baseurl,you must provides a url!"
	exit 2
fi

#check yum.repo whether exist?
url=`echo "$1" | sed -n 's!.*:[/]*!!;s![/]!_!;p'`
if [ -f "${dirname}${url}.repo" ];then
	echo "`date`:warning:${url}.repo is exist;it will backup" >> $log_path
	mv $dirname${url}.repo $dirname${url}.bk
fi

#check parameter and config yum.repo
echo "
[$url]
name=$url
baseurl=$1
enabled=1
gpgcheck=0
" > $dirname${url}.repo

#check yum.repo whether can use
yum clean all >> $log_path
test01=`yum repolist | awk -v x=$url '/x/{print $3}'`
if [ ! "$test01" == "0" ];then
	echo "`date`:${url}.repo config success" >> $log_path
	exit 0
else
	echo "`date`:${url}.repo config failed;the url is not available" >> $log_path
	rm -rf $dirname${url}.repo
	exit 3
fi

  

posted @ 2018-05-25 16:17  JamesMI  阅读(78)  评论(0编辑  收藏  举报