镜像制作

技术文章 1年前 (2020) 完美者
1,687 0

标签:$?   script   info   pat   rem   _id   test   done   gre   

#!/bin/bash
#use mk-ks.sh os_name to create ks iso images
#set -x
s_pr_no=$#
s_os_name=$1
s_os_versio=$2
s_date=date +%F-%H-%M-%S
s_log=/kvm/kstool/log/mkks-${s_os_name}-${s_date}.log
echo $s_log
case ${s_os_name} in
olinux76)
s_lable="OL-7.6 Server.x86_64"
s_os_release=olinux
;;
olinux78)
s_lable="OL-7.8 Server.x86_64"
s_os_release=olinux
;;
rhel80)
s_lable="RHEL-8-0-0-BaseOS-x86_64"
s_os_release=rhel
;;
rhel76)
s_lable="RHEL-7.6 Server.x86_64"
s_os_release=rhel
;;
rhel75)
s_lable="RHEL-7.5 Server.x86_64"
s_os_release=rhel
;;
rhel744)
s_lable="RHEL-7.4 Server.x86_64"
s_os_release=rhel
;;
neokylin-sever-Hygon-x86)
s_lable="neokylin-sever-Hygon-x86_64"
s_os_release=kylin
;;
rhel72-800-900g)
s_lable="RHEL-7.2 Server.x86_64"
s_os_release=rhel
;;
rhel72)
s_lable="RHEL-7.2 Server.x86_64"
s_os_release=rhel
;;
olinux74)
s_lable="OL-7.4 Server.x86_64"
s_os_release=olinux
;;
rhel69)
s_lable="RHEL-6.9 Server.x86_64"
s_os_release=rhel
;;
rhel610|hygon-rhel610)
s_lable="RHEL-6.10 Server.x86_64"
s_os_release=rhel
;;
rhel67)
s_lable="RHEL-6.7 Server.x86_64"
s_os_release=rhel
;;
rhel66)
s_lable="RHEL-6.6 Server.x86_64"
s_os_release=rhel
;;
olinux610)
s_lable="OL-6.10 Server.x86_64"
s_os_release=olinux
;;
olinux69)
s_lable="OL-6.9 Server.x86_64"
s_os_release=olinux
;;
olinux66|olinux67)
s_lable="OL-6 Server.x86_64"
s_os_release=olinux
;;
centos71|centos74|centos76|centos75|centos78)
s_lable="CentOS 7 x86_64"
s_os_release=centos
;;
centos69)
s_lable="CentOS 6 x86_64"
s_os_release=centos
;;
centos82)
s_lable="CentOS 8 x86_64"
s_os_release=centos
;;
*)
echo "pls add new lable in script"
exit 1
;;
esac

check_pr()
{
if [ ${s_pr_no} != 2 ]
then
echo "pls use $0 os_name(rhel76) os_versio(6/7) ";
exit 1
fi
}

check_rt()
{
if [ $? == 0 ] ;then echo "====succ";else echo "====fail" ;exit 1;fi
}

modify_db()
{
file_no=cat ${s_log} | grep remote_filename |grep -v ‘big.iso$‘ |wc -l
if [ ${file_no} != 1 ] ;
then
echo "====file Number is ${file_no} no 1";exit 1;
else
echo "====file Number is ${file_no} is 1" ;
fi
file_path=cat ${s_log} | grep remote_filename |grep -v ‘big.iso$‘ |awk -F "=" ‘{print $3}‘

echo ‘insert into io_file_upload‘
echo ‘(name, trace, create_by, create_time, status, dltimes, parent_id)‘
echo ‘values‘

case ${s_os_release} in
rhel)
echo "(‘${s_os_name}-ks.iso‘, ‘http://io.paic.com.cn/group1/${file_path}‘, ‘XUJINTAO726‘, now(), ‘1‘, 0, ‘99‘);"
;;
olinux)
echo "(‘${s_os_name}-ks.iso‘, ‘http://io.paic.com.cn/group1/${file_path}‘, ‘XUJINTAO726‘, now(), ‘1‘, 0, ‘98‘);"
;;
centos)
echo "(‘${s_os_name}-ks.iso‘, ‘http://io.paic.com.cn/group1/${file_path}‘, ‘XUJINTAO726‘, now(), ‘1‘, 0, ‘92‘);"
;;
kylin)
echo "(‘${s_os_name}-ks.iso‘, ‘http://io.paic.com.cn/group1/${file_path}‘, ‘XUJINTAO726‘, now(), ‘1‘, 0, ‘101‘);"
;;
*)
echo "faild pls check os release"
exit 1
;;
esac

}

main()
{
cd /kvm/kstool/
if [ -d /kvm/iso-temp/${s_os_name}/mnt/tools/ ]
then
echo "remove old tools"
echo "rm -rf /kvm/iso-temp/${s_os_name}/mnt/tools/"
rm -rf /kvm/iso-temp/${s_os_name}/mnt/tools/

check_rt
else
echo "/kvm/iso-temp/${s_os_name}/mnt/tools/ done exist"
exit
fi

echo "copy new tools"
cp /kvm/kstool/tools/* /kvm/iso-temp/${s_os_name}/mnt/tools/
check_rt

case ${s_os_versio} in
6)
echo "copy ks sysinit"
echo "rm -f /kvm/iso-temp/${s_os_name}/mnt/tools/sysinitel7.x86_64.rpm"
rm -f /kvm/iso-temp/${s_os_name}/mnt/tools/sysinit
el7.x86_64.rpm
cp /kvm/kstool/6ks.cfg /kvm/iso-temp/${s_os_name}/mnt/tools/ks.cfg
check_rt
;;
7)
echo "copy ks sysinit"
echo "rm -f /kvm/iso-temp/${s_os_name}/mnt/tools/sysinitel6.x86_64.rpm"
rm -f /kvm/iso-temp/${s_os_name}/mnt/tools/sysinit
el6.x86_64.rpm
cp /kvm/kstool/7ks.cfg /kvm/iso-temp/${s_os_name}/mnt/tools/ks.cfg
check_rt
;;
8)
echo "copy ks sysinit"
echo "rm -f /kvm/iso-temp/${s_os_name}/mnt/tools/sysinitel6.x86_64.rpm"
rm -f /kvm/iso-temp/${s_os_name}/mnt/tools/sysinit
el6.x86_64.rpm
cp /kvm/kstool/8ks.cfg /kvm/iso-temp/${s_os_name}/mnt/tools/ks.cfg
check_rt
;;
*)
echo "wrong os_verion : ${s_os_versio} "
exit
esac

echo "copy osinit"
cp /kvm/kstool/osinit/linux/root/* /kvm/iso-temp/${s_os_name}/mnt/tools/ -r
check_rt

echo "create iso"
cd /kvm/iso-temp/${s_os_name}/mnt/
echo mkisofs
echo "mkisofs -relaxed-filenames -R -J -V "${s_lable}" -o /kvm/iso-ks/${s_os_name}-ks.iso -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -b images/efiboot.img -no-emul-boot /kvm/iso-temp/${s_os_name}/mnt"
mkisofs -relaxed-filenames -R -J -V "${s_lable}" -o /kvm/iso-ks/${s_os_name}-ks.iso \
-c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 \
-boot-info-table -eltorito-alt-boot -b images/efiboot.img -no-emul-boot /kvm/iso-temp/${s_os_name}/mnt
check_rt

echo "upload file"
cd /kvm/iso-ks/
echo upload
echo "/usr/bin/fdfs_test /etc/fdfs/client.conf upload /kvm/iso-ks/${s_os_name}-ks.iso"
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /kvm/iso-ks/${s_os_name}-ks.iso
check_rt
modify_db
}

check_pr
main >> ${s_log} 2>&1
#main

镜像制作

标签:$?   script   info   pat   rem   _id   test   done   gre   

原文地址:https://blog.51cto.com/12768454/2547413

版权声明:完美者 发表于 2020-11-07 16:54:06。
转载请注明:镜像制作 | 完美导航

暂无评论

暂无评论...