自动化脚本

关于yum

#!/bin/bash
#自动配置大全
echo -e "\033[31mxiaozhen的自动脚本,版本:3.0\033[0m"
echo -e "\033[31m作者联系方式QQ2491267482\033[0m"
# 获取一系列配置前置
banb=`cat /etc/redhat-release |awk '{print $4}' | awk -F. '{print $1}'`
awget=`rpm -qa | grep wget|awk -F- '{print $1}'`

##下面该脚本的函数库
YUM()
{

#yum原始文件备份
yumbf()
{
read -p "原始yum配置文件是否保存?(y/n)" yumpz
	
if [ $yumpz = n ];then 
	cd /etc/yum.repos.d
	rm -rf *
		
elif [ $yumpz = y ];then
	cd /etc/yum.repos.d
	mkdir bf
	mv *.repo bf	
fi
}

#yumCD/DVD连接函数
yumCD/DVD()
{
read -p "您使用的CD/DVD是第一个吗?(y/n)" CDa
echo -e "\033[31m请确保CD/DVD镜像已连接\033[0m"
if [ $CDa = y ];then
	mount /dev/sr0 /mnt
	cd /etc/yum.repos.d
	echo "[yum]
name=yum
baseurl=file:///mnt
gpgcheck=0
enabled=1" > yum.repo
	yum clean all
	yum makecache
							
elif [ $CDa = n ];then 
	echo -e "\033[31m暂时只支持第一个连接\033[0m"							
fi
}

#yumcentos
yumcentos()
{
yumbf
echo -e "\033[31m----------------------------------------------------------------------\033[0m"
find / -name '*.iso' |grep Cen
echo -e "\033[31m----------------------------------------------------------------------\033[0m"
				
read -p "您使用的镜像是那个?(1或2):" isolx
isoname4=`find / -name '*.iso' |sed ''$isolx'd'`
umount $isoname4
read -p "请提供挂载点位置,(例:/mnt):" isoname2
mkdir $isoname2/cenos
mount $isoname4 $isoname2/cenos
cd /etc/yum.repos.d
echo "[centos]
name=yum
baseurl=file://$isoname2/cenos
gpgcheck=0
enabled=1" > centos.repo
yum clean all
yum makecache
}


#本地yum配置主函数
bdiyum()
{
read -p "您是使用CD/DVD连接的镜像吗?(y/n)" CD
if [ $CD = y ];then 
	yumCD/DVD
elif [ $CD = n ];then 	
			yumcentos		
fi																													
}

#网络yum配置函数
wlyum()
{
	read -p "原始yum配置文件是否保存?(y/n)" yumpz
	
	if [ $yumpz = n ];then 
		cd /etc/yum.repos.d
		rm -rf *
		
	elif [ $yumpz = y ];then
		cd /etc/yum.repos.d
		mkdir bf
		mv *.repo bf	
	fi
	
	if [ $banb = 6 ];then
		if [ $awget = wget ];then
			read -p "你需要那个版本的网络yum,1:网易源 2:阿里源 " yumy
				if [$yumy = 2 ];then
					echo "站点升级维护中,自动选择网易源"
					#cd /etc/yum.repos.d
					#wget 
					#yum clean all
					#yum makecache
					yumy=1
				elif [ $yumy = 1 ];then
					cd /etc/yum.repos.d
					wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
					yum clean all
					yum makecache														
				fi
		else
			echo -e "\033[31m找不到下载命令(wget),请先配置本地yum,安装wget后,在创建网络yum\033[0m"
		fi
	elif [ $banb = 7 ];then 
		if [ $awget = wget ];then
			read -p "你需要那个版本的网络yum,1:网易源 2:阿里源 " yumy
				if [$yumy = 2 ];then
					echo "站点升级维护中,自动选择网易源"
					#cd /etc/yum.repos.d
					#wget 
					#yum clean all
					#yum makecache
					cd /etc/yum.repos.d
					wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
					yum clean all
					yum makecache	
				elif [ $yumy = 1 ];then
					cd /etc/yum.repos.d
					wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
					yum clean all
					yum makecache														
				fi
					
		else
			echo -e "\033[31m找不到下载命令(wget),请先配置本地yum,安装wget后,在创建网络yum\033[0m"
		fi
	fi
}


#yum配置启动主程序
hansyum()
{
	read -p "选择yum方式(1:本地yum;2:网络yum)" yuma
	
	if [ $yuma = 1 ];then
		bdiyum
	elif [ $yuma = 2 ];then
		wlyum
	fi
}

#启动yum配置主程序
hansyum

echo -e "\033[31myum配置已完成\033[0m"
}


IP()
{
echo -e "\033[31m暂时不支持IP配置,如有需要请联系作者\033[0m"
}


## 脚本启动主语句
read -p "目的1:yum 2:ip配置:" lx
if [ $lx = 1 ];then
	echo -e "\033[31m你选择的是yum配置脚本\033[0m"
	YUM
elif [ $lx = 2 ];then
	echo -e "\033[31m你选择的是IP配置脚本\033[0m"
	IP
fi


上一篇:使用wget下载KITTI数据集


下一篇:【腾讯云】一、搭建宝塔面板