shell script自动搭建简单的yum
2013-03-04 17:23
295 查看
#!/bin/sh
#Shell name:config_yum.sh
#Program
# config for yum-pack
#
#Author:pero
#Email: perofu.com@gmail.com
#History
# 2012/07/15
#Usage:vi config_yum.sh ; :set ff=unix
#
#If you have any opinion please contact me
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH
if [ $UID -ne 0 ]
then
echo "Run as root"
exit 1
fi
pack=/mnt/Packages
pack1=/mnt/CentOS
CD=$(mount | gawk '/\/dev\/sr0/ {print $1}')
odir=$(mount | gawk '/\/dev\/sr0/ {print $3}')
#mount CDROM
if [ -n $CD ]&&[ -n $odir ]
then
umount /mnt &> /dev/null
echo "now,mounting IOS to the /mnt"
mount /dev/cdrom /mnt &> /dev/null
echo "mount is ok"
else
mount /dev/cdrom /mnt &> /dev/null
echo "mount is ok"
fi
if [ -d $pack ]||[ -d $pack1 ]
then
read -t 25 -p "Please input a Dir-name for yum_pack [/yum]:" yum_path
if [ -n $yum_path ] #create dir
then
mkdir -p $yum_path &> /dev/null
echo "dir is created"
else
yum_path=/yum
mkdir -p $yum_path &> /dev/null
echo "dir is created"
fi
#cp CD to dir
if [ -d $yum_path ]
then
echo "please wait a min"
cp -a /mnt/* $yum_path
echo "cp is ok"
else
echo "$yum_path is not exist"
exit 77 #if dir is not exist ,quit the shell
fi
cd /etc/yum.repos.d/
rm -rf /etc/yum.repos.d/*
#create yum config file
read -t 30 -p "Please input a name for yum-config-file [dvd.repo],do not use 'red hat' :" filename
if [ -n $filename ]
then
touch $filename.repo
echo "file was created"
else
filename=dvd
touch $filename.repo
echo "file was created"
fi
echo "[rhel-source]" >> $filename.repo
echo "name=Red Hat" >> $filename.repo
echo "baseurl=file://$yum_path" >> $filename.repo
echo "enabled=1" >> $filename.repo
echo "gpgcheck=0" >> $filename.repo
echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" >> $filename.repo
echo "yum-config-file was fanish"
else
echo "Please input a CD-ROM and try again or connect the writer!!!"
fi
#new added
yum install createrepo -y &> /dev/null
if [ $? -ne "0" ]
then
exit 77
fi
xml=$(ls ${yum_path}/repodata/ |grep comp |grep -v gz)
cp ${yum_path}/repodata/${xml} /tmp/
rm -rf ${yum_path}/repodata/
createrepo -g /tmp/${xml} ${yum_path}
if [ $? -eq 0 ]
then
echo "all of yum is ok..."
else
echo "please check again..."
fi
rm -rf /tmp/${xml}
本文出自 “无咎” 博客,请务必保留此出处http://perofu.blog.51cto.com/6061242/1144588
#Shell name:config_yum.sh
#Program
# config for yum-pack
#
#Author:pero
#Email: perofu.com@gmail.com
#History
# 2012/07/15
#Usage:vi config_yum.sh ; :set ff=unix
#
#If you have any opinion please contact me
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH
if [ $UID -ne 0 ]
then
echo "Run as root"
exit 1
fi
pack=/mnt/Packages
pack1=/mnt/CentOS
CD=$(mount | gawk '/\/dev\/sr0/ {print $1}')
odir=$(mount | gawk '/\/dev\/sr0/ {print $3}')
#mount CDROM
if [ -n $CD ]&&[ -n $odir ]
then
umount /mnt &> /dev/null
echo "now,mounting IOS to the /mnt"
mount /dev/cdrom /mnt &> /dev/null
echo "mount is ok"
else
mount /dev/cdrom /mnt &> /dev/null
echo "mount is ok"
fi
if [ -d $pack ]||[ -d $pack1 ]
then
read -t 25 -p "Please input a Dir-name for yum_pack [/yum]:" yum_path
if [ -n $yum_path ] #create dir
then
mkdir -p $yum_path &> /dev/null
echo "dir is created"
else
yum_path=/yum
mkdir -p $yum_path &> /dev/null
echo "dir is created"
fi
#cp CD to dir
if [ -d $yum_path ]
then
echo "please wait a min"
cp -a /mnt/* $yum_path
echo "cp is ok"
else
echo "$yum_path is not exist"
exit 77 #if dir is not exist ,quit the shell
fi
cd /etc/yum.repos.d/
rm -rf /etc/yum.repos.d/*
#create yum config file
read -t 30 -p "Please input a name for yum-config-file [dvd.repo],do not use 'red hat' :" filename
if [ -n $filename ]
then
touch $filename.repo
echo "file was created"
else
filename=dvd
touch $filename.repo
echo "file was created"
fi
echo "[rhel-source]" >> $filename.repo
echo "name=Red Hat" >> $filename.repo
echo "baseurl=file://$yum_path" >> $filename.repo
echo "enabled=1" >> $filename.repo
echo "gpgcheck=0" >> $filename.repo
echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" >> $filename.repo
echo "yum-config-file was fanish"
else
echo "Please input a CD-ROM and try again or connect the writer!!!"
fi
#new added
yum install createrepo -y &> /dev/null
if [ $? -ne "0" ]
then
exit 77
fi
xml=$(ls ${yum_path}/repodata/ |grep comp |grep -v gz)
cp ${yum_path}/repodata/${xml} /tmp/
rm -rf ${yum_path}/repodata/
createrepo -g /tmp/${xml} ${yum_path}
if [ $? -eq 0 ]
then
echo "all of yum is ok..."
else
echo "please check again..."
fi
rm -rf /tmp/${xml}
本文出自 “无咎” 博客,请务必保留此出处http://perofu.blog.51cto.com/6061242/1144588
相关文章推荐
- shell script自动搭建简单的nfs服务器
- shell script自动搭建简单的pxe服务器
- shell script自动搭建简单的cacti监控
- shell script自动搭建简单的mail服务器(postfix+dovecot)
- shell script自动搭建简单的双机ssh认证
- shell script自动搭建简单的mysql主从(replication)
- Centos (简单)自动yum安装apache+php+mysql Shell脚本
- CentOS 下搭建LAMP(超简单yum版)
- shell脚本:自动搭建yum(升级版)
- CentOS7安全设置 yum-cron系统自动更新,firewalld防火墙简单使用
- shell script自动搭建简单的quota(磁盘配额)
- shell脚本:自动搭建yum
- 超简单YUM仓库 搭建安装 MFS 服务
- Linux环境下建立yum仓库及简单搭建httpd服务器
- yum 最简单的LAMP(linux+apache+mysql+php)环境搭建
- shell script自动搭建简单的linux系统初始化脚本
- shell script自动搭建简单的lamp环境
- 用光盘简单搭建本地yum库(RHEL5,6通用)
- 复习:搭建本地yum和利用yum搭建简单的samba
- yum的安装的使用搭建简单的apache服务器