案例七:shell实现开机自动挂载本地YUM仓库程序

shell实现开机自动挂载本地YUM仓库自动化程序,可以在没有网络的情况下也可以使用yum安装程序。Linux就该这么学

#!/bin/bash
#自动搭建yum本地仓库
#
cdrom () {
mount /dev/cdrom /media/cdrom &> /dev/null
[ $? -eq 0 ] && echo "挂载成功"
}
 
[ -d /media/cdrom ] || mkdir /media/cdrom
mount | grep -q /dev/sr0
if [ $? -eq 0 ]
then
umount /dev/sr0
cdrom
else
cdrom
fi

[ -d /etc/yum.repos.d/bak ] || mkdir /etc/yum.repos.d/bak
ls -l /etc/yum.repos.d/ | grep *repo > /dev/null
if [ $? -ne 0 ]
then
echo "正在移动文件到目录下"
mv /etc/yum.repos.d/*repo bak
else
echo "文件已经移动目录!"
fi
[ -e /etc/yum.repos.d/centos-media.repo ] || echo "[media]
name=CentOS-$releasever - Media
baseurl=file:///media/cdrom/
gpgcheck=0
enabled=1" > /etc/yum.repos.d/centos-media.repo
 
echo "清除yum缓存"
yum clean all &> /dev/null
echo "YUM已经搭建完成"
echo -n  "共有软件包:" 
yum repolist | tail -1 | awk -F':' '{print $2}' 
 
cat /etc/fstab | grep /dev/sr0 &> /dev/null
if [ $? -ne 0 ]
then
echo "正在写入开机自动挂载光盘"
echo "
/dev/sr0     /media/cdrom       iso9660 defaults 0 0
">> /etc/fstab
fi

你可能感兴趣的:(案例七:shell实现开机自动挂载本地YUM仓库程序)