1、文件目录结构
[root@dg1 rhel-7-server-rpms]# tree -L 2
.
├── 9d69672f86f4d058e1c2e7fd690c3e5fbf7a46e3-updateinfo.xml.gz
├── c76c2299-12f3-4f9c-b7bd-03bacee2c363
├── comps.xml
├── Packages
│ ├── 3
│ ├── a
│ ├── b
│ ├── c
│ ├── d
│ ├── e
│ ├── f
│ ├── g
│ ├── h
│ ├── i
│ ├── j
│ ├── k
│ ├── l
│ ├── m
│ ├── n
│ ├── o
│ ├── p
│ ├── q
│ ├── r
│ ├── s
│ ├── t
│ ├── u
│ ├── v
│ ├── w
│ ├── x
│ ├── y
│ └── z
└── upgrade.sh
2、脚本内容
cat upgrade.sh
#! /bin/bash
home_path=`pwd`
makedir(){
echo "please input the path:"
read folder
if [ ! -d "$folder" ]; then
mkdir -p $folder
else
echo "the folder $folder is already exists"
makedir
fi
echo "makedir done!"
}
installpackages(){
echo "==============install required software ================="
sleep 2
rpm -ivh $home_path/Packages/d/deltarpm*.rpm
rpm -ivh $home_path/Packages/p/python-deltarpm*.rpm
rpm -ivh $home_path/Packages/c/createrepo*.rpm
echo "install required rpm done!"
}
copyfile(){
echo "==============copy file to the created path=============="
sleep 2
cp -r $home_path/* $folder
echo "copy file done!"
}
createrepofile(){
echo "===============create repo file==========================="
sleep 2
cat > /etc/yum.repos.d/update.repo << EOF
[update]
name=update
baseurl=file://$folder
gpgcheck=0
enabled=1
EOF
echo "create repo file done!"
}
create_repo(){
echo "=============== start create repo======================== "
sleep 2
createrepo $folder
echo "create repo done"
}
#============main========================
makedir
installpackages
copyfile
createrepofile
create_repo
echo ""
echo "done!"
#====================================
yum clean all
yum makecache
标签:home,离线,echo,yum,path,红帽,folder,Packages,rpm
From: https://www.cnblogs.com/likaifei/p/16709143.html