78 lines
2.7 KiB
Bash
Executable File
78 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
###############################################################################################
|
||
# 功能:搭建pxe服务器 定制和搭建的脚本运行时拷贝过来,执行后删除 dirname $0
|
||
# 用户交互数据保存在pxe_env.conf中
|
||
###############################################################################################
|
||
function showhelp
|
||
{
|
||
echo -e "Usage1: $0 config_file_path"
|
||
echo -e "Options:"
|
||
echo -e " config_file_path: json file path that contain customized config about os install"
|
||
echo -e " (json file format is as /etc/pxe_install/json_format/os.json)"
|
||
echo ""
|
||
echo -e "Usage2: $0 --help display this help and exit"
|
||
echo ""
|
||
}
|
||
|
||
function main_install
|
||
{
|
||
local CFG_FILE=$1
|
||
local WORKDIR=$2
|
||
|
||
#检查nfs服务器的文件夹是否存在
|
||
check_nfs_exports || { pxelog "[error]nfs server not correct installed, please reinstall !" "console"; return 1; }
|
||
|
||
#处理os安装的一些预处理工作:包括创建和目标机mac地址相关的文件夹,mount iso;拷贝ISO中的引导程序到根目录;拷贝ks文件、网口固化脚本文件
|
||
custom_pre_cfg ${CFG_FILE} ${WORKDIR} || return 1
|
||
|
||
#生成default文件
|
||
custom_default_cfg ${CFG_FILE} ${WORKDIR}
|
||
|
||
#生成以及配置ks文件
|
||
custom_ks_cfg ${CFG_FILE} || return 1
|
||
|
||
return 0
|
||
}
|
||
|
||
# ##############################################################################################
|
||
# 入口 #
|
||
# ##############################################################################################
|
||
#工作目录定义及检查
|
||
WORKDIR=/etc/pxe_install
|
||
[ ! -d ${WORKDIR} ] && { pxelog "[error]WORKDIR ${WORKDIR} not exist!" "console"; exit 1; }
|
||
|
||
source ${WORKDIR}/scripts/common.sh
|
||
source ${WORKDIR}/scripts/setup_func.sh
|
||
is_fail=0
|
||
|
||
pxelog "********************begin pxe os install********************" "console"
|
||
|
||
#显示帮助提示
|
||
if [[ `echo $* |grep -wi 'help'` != "" ]];then
|
||
showhelp
|
||
exit 0
|
||
fi
|
||
|
||
#入参检查
|
||
[ $# != 1 ] && { pxelog "[error]Param num fail, please input again" "console"; showhelp; exit 1; }
|
||
CFG_FILE=$1
|
||
[ ! -e ${CFG_FILE} ] && { pxelog "[error]file ${CFG_FILE} not exist!" "console"; exit 1; }
|
||
|
||
|
||
#开始安装
|
||
main_install ${CFG_FILE} ${WORKDIR} || is_fail=1
|
||
|
||
pxelog "********************end pxe os install********************\n" "console"
|
||
|
||
pxelog "************************************************************" "console"
|
||
if [ $is_fail -eq 0 ]; then
|
||
pxelog "good! pxe os install config has been finished!" "console"
|
||
pxelog "now you can enjoy installing os by pxe server" "console"
|
||
else
|
||
pxelog "failed! pxe os install config encounter error!" "console"
|
||
pxelog "please check and reinstall" "console"
|
||
fi
|
||
pxelog "************************************************************" "console"
|
||
|
||
exit $is_fail |