#!/bin/bash
#date:2020-08-16
#name:yum.sh
iso=/dev/cdrom
folder="/etc/yum.repos.d/yum_bak"
if [ ! -d "$folder" ]; then
mkdir "$folder"
fi
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/yum_bak
read -p "请输入要创建的yum名称:" yum
if [[ -z "$yum" ]];then
#echo -e "\033[33m没有任何输入,请输入\033[0m"
read -p "请输入要创建的yum名称:" yum
[[ -z "$yum" ]] && echo -e "\033[31m没有输入,请重试!\033[0m" && exit
fi
mkdir -p /mnt/cdrom
mount $iso /mnt/cdrom &> /dev/null
if [[ $? -ne 0 ]];then
echo -e "\033[31m镜像没有连接,请先连接\033[0m"
exit
fi
#echo "mount $iso /mnt/cdrom" >>/etc/rc.local
tee >> /etc/yum.repos.d/"$yum".repo<<-eof
[$yum]
name=$yum
baseurl=file:///mnt/cdrom
gpgcheck=0
enable=1
eof
yum clean all &> /dev/null
echo -e "\033[32m本地yum源配置成功\033[0m"
yum clean all
yum makecache