SHELL脚本:PXE自动更新版本号

#!/bin/bash

iso_version=$1

iso_files=$2

iso_version_files=/yab/www/yunxiazi/${iso_version}

iso_url=http://192.168.88.1/yunxiazi/${iso_version}

ks_path=/yab/www/yunxiazi/${iso_version}/isolinux/ks.cfg

tfboot_ks_cfg=/tftpboot/pxelinux.cfg/default

if [ $# -ne 2 ]

then

echo -e "\033[31m The first parameter is the version number, and the second parameter is the mirror file location.\033[0m"

exit 0

fi

#判断版本号文件是否创建成功

if [ ! -d "${iso_version_files}" ]

then

mkdir ${iso_version_files}

echo "${iso_version_files} successfully created"

else

echo "${iso_version_files} has been existed"

rm -rf ${iso_version_files}

if [ $? -eq 0 ]

then

echo "Deleted ${iso_version_files} successfully"

fi

exit 1

fi

#判断版本号是否存在

is_version=$(cat ${tfboot_ks_cfg} | grep yunxiazi${iso_version} | head -n 1 |awk -F " " '{print $2}')

if [ -n "${is_version}" ]

then

echo "${is_version} is not empty"

echo -e "Version \033[31m${is_version}\033[0m already exists in ${tfboot_ks_cfg}."

exit 2

fi

mount ${iso_files} /mnt/

cp -af /mnt/* ${iso_version_files}/

if [ $? -eq 0 ]

then

echo "${iso_version_files} copy completed"

umount /mnt/ > /dev/null

fi

echo ${ks_path}

if [ -f "${ks_path}" ]

then

sed -i "/text/a\\\url --url=${iso_url}" ${ks_path}

echo "Modify ${ks_path} successfully"

fi

cat >> ${tfboot_ks_cfg} << EOF

label yunxiazi${iso_version}

menu label ^Install OS

kernel vmlinuz

append initrd=initrd.img ks=${iso_url}/isolinux/ks.cfg

EOF

sed -i "1c default yunxiazi${iso_version}" ${tfboot_ks_cfg}

systemctl restart xinetd


分享到:


相關文章: