一键自安装ISO封装打包脚本

对于经常打包ISO的来说,每次都要运行那几行命令很没效率。于是就整理了一个自动封装打包ISO的脚本。

#!/bin/sh

workpath="/CentOS/7"
pack_dir="/CentOS/7/7.1"
version="7.1"
timestamp="`date +%Y%m%d-%H%M%S`"

##替换ks中的packages
##获取Packages文件夹里所有的包名称存放到pkg.info文件里
cd $pack_dir
for i in `ls Packages/`; do
echo ${i%%.rpm} ;
done > ../pkg.info

cd $workpath
sed -i '/%packages/,/%end/{//!d}' ./7.1/ks.cfg ##指定删除%packages和%end之间的包名称
sed -i '/%packages/r pkg.info' ./7.1/ks.cfg ##指定在%packages下添加pkg.info文件里的包名称
rm pkg.info -rf

##封装打包,生成的ISO存放在指定ISO目录下
if test -f ${workpath}/comps.xml ;then
createrepo -g ${workpath}/comps.xml ${workpath}/${version}/
if test -d /ISO; then
mkisofs -R -J -T -r -l -d -joliet-long -allow-multidot -allow-leading-dots -no-bak \
-o /ISO/CentOS-${version}_x86_64.$timestamp.iso -b isolinux/isolinux.bin -c isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table ${workpath}/${version}/
else
echo 'Directory: /ISO no exist!'
fi
else
echo 'File: ${workpath}/comps.xml'
fi

weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: