搭建yum源的shell script

#!/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 meshell

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATHui

if [ $UID -ne 0 ]
then
  echo "Run as root"
  exit 1
fiurl

pack=/mnt/Packages
pack1=/mnt/CentOS
CD=$(mount | gawk '/\/dev\/sr0/ {print $1}')
odir=$(mount | gawk '/\/dev\/sr0/ {print $3}')unix

#mount CDROMxml

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"
figet

if [ -d $pack ]||[ -d $pack1 ]
then
 read -t 25 -p "Please input a Dir-name for yum_pack [/yum]:" yum_pathinput

 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
 it

#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
 fiio

 cd /etc/yum.repos.d/
 rm -rf /etc/yum.repos.d/*awk

#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

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}

相關文章
相關標籤/搜索