From 16636d9c8c8dfc5f56dd91e83ae3ca388be3bf6b Mon Sep 17 00:00:00 2001 From: Eric MacDonald Date: Mon, 6 Jun 2022 23:05:05 +0000 Subject: [PATCH] Debian: add controller-0 pxeboot grub menu setup utility This update adds a new pxeboot_setup.sh script that can be used to tailor the controller-0 BIOS and UEFI install grub menus for for a specific lab's controller-0 target server installation. Some controller-0 installation UEFI and BIOS grub menus' variable replacement labels have been added to and others slightly modified to better serve the new setup utility. Features: - Updating both BIOS and EFI grub files - Preserves the command used to create tailored grub files - Preserves replaced grub files as . - Supported variable replacements are xxxFEEDxxx - path between http server base and mounted iso xxxSYSTEMxxx - menu entry selection index ; default 2 (AIO) xxxINSTDEVxxx - install device name ; default /dev/sda xxxPXEBOOTxxx - /pxeboot offset path to bzImage/initrd xxxBASE_URLxxx - pxeboot server URL Tool Usage: The caller specifies an --input argument to the debian controller-0 installer grub file templates which contain the above variable replacement labels. The --output argument is used to specify where to create the variable replaced system specific grub files. A --system argument specififying the default menu entry index to use. The remaining arguments are used to specify various paths and optionally the install device. Refer to the pxeboot_setup.sh script header, code comment or full --help for more details. Utility Arguments: --input --output --feed --pxeboot --url --device --system <0..3> Example Usage: pxeboot_setup.sh --input /path/to/grub/template/dir --output /path/to/target/iso/mount --pxeboot pxeboot/offset/to/bzImage_initrd --feed pxeboot/offset/to/target_feed --url http://###.###.###.### --instdev /dev/sde --system 3 Test Plan: for both BIOS and UEFI servers PASS: Verify End-To-End user experience using the script and menus from a mounted iso or feed to setup the grub install menus. Script: PASS: Verify grub menu selection by number and by string (default) PASS: Verify system type install selection of all menu paths PASS: Verify argument and option success path handling PASS: Verify argument and option failure path handling PASS: Verify shellcheck script static analysis PASS: Verify saving of replaced menus as '.' files PASS: Verify creation of command file in menus target dir PASS: Verify default device and override handling PASS: Verify exit 0 on success and exit 1 on failure. PASS: Verify script usage help screen PASS: Verify ttyS0 override to ttySx where x=0..3 Install: PASS: Verify system install of all menu entries PASS: Verify menu selection handling without numbered prefixes PASS: Verify graphical and console submenu of each main menu PASS: Verify graphical logging vs console logging Story: 2009301 Task: 45547 Signed-off-by: Eric MacDonald Change-Id: I1faf3ea305557d990ed7b03418c45804b71878b7 --- .../debian/deb_folder/rules | 5 + .../efi-pxeboot.cfg.debian | 50 ++- .../pxe-network-installer/pxeboot.cfg.debian | 63 ++-- .../pxe-network-installer/pxeboot_setup.sh | 313 ++++++++++++++++++ 4 files changed, 397 insertions(+), 34 deletions(-) create mode 100755 installer/pxe-network-installer/pxe-network-installer/pxeboot_setup.sh diff --git a/installer/pxe-network-installer/debian/deb_folder/rules b/installer/pxe-network-installer/debian/deb_folder/rules index db905f3e..77217da8 100644 --- a/installer/pxe-network-installer/debian/deb_folder/rules +++ b/installer/pxe-network-installer/debian/deb_folder/rules @@ -29,6 +29,11 @@ override_dh_install: install -v -m 644 pxe-grub.cfg.static $(ROOT)/var/pxeboot/pxelinux.cfg.files/grub.cfg.static install -p -D -m 700 pxeboot-update.sh $(ROOT)/usr/sbin/pxeboot-update-${platform_release}.sh + # Add controller-0 pxeboot install grub menus and setup utility + install -p -D -m 644 pxeboot.cfg.debian $(ROOT)/var/pxeboot/pxelinux.cfg.files/pxeboot.cfg.debian + install -p -D -m 644 efi-pxeboot.cfg.debian $(ROOT)/var/pxeboot/pxelinux.cfg.files/efi-pxeboot.cfg.debian + install -p -D -m 755 pxeboot_setup.sh $(ROOT)/usr/sbin/pxeboot_setup.sh + # Legacy BIOS System Node Install grub menus install -p -D -m 700 debian-pxe-controller-install $(ROOT)/var/pxeboot/pxelinux.cfg.files/pxe-controller-install-${platform_release} install -p -D -m 700 debian-pxe-smallsystem-install $(ROOT)/var/pxeboot/pxelinux.cfg.files/pxe-smallsystem-install-${platform_release} diff --git a/installer/pxe-network-installer/pxe-network-installer/efi-pxeboot.cfg.debian b/installer/pxe-network-installer/pxe-network-installer/efi-pxeboot.cfg.debian index 44e90d64..49d5d764 100644 --- a/installer/pxe-network-installer/pxe-network-installer/efi-pxeboot.cfg.debian +++ b/installer/pxe-network-installer/pxe-network-installer/efi-pxeboot.cfg.debian @@ -1,31 +1,53 @@ +# default 20 second timeout timeout=20 -default=2 +default='xxxSYSTEMxxx' GRUB_HIDDEN_TIMEOUT=0 GRUB_TIMEOUT_STYLE='countdown' menuentry 'StarlingX Debian LAT / Kickstart Boot Menu' { - echo " " - } -menuentry '1) UEFI Boot from hard drive' { + +# Create a space in the menu +menuentry ' ' { + echo " " +} + +menuentry 'UEFI Boot from hard drive' --id=disk { search --set=root --label otaefi configfile /EFI/BOOT/grub.cfg } -menuentry '2) UEFI Debian Controller Install' { - linuxefi xxxLAB_PXExxx/bzImage-std rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller BOOTIF=$net_default_mac instdev=/dev/sda ks=xxxBASE_URLxxx/xxxLAB_FEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxLAB_FEEDxxx/ostree_repo console=ttyS0,115200 console=tty1 biosdevname=0 biosplusefi=1 - initrdefi xxxLAB_PXExxx/initrd +submenu 'UEFI Debian Controller Install' --id=standard { + menuentry 'Serial Console' --id=serial { + linuxefi xxxPXEBOOTxxx/bzImage-std rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller BOOTIF=$net_default_mac instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=ttyS0,115200 biosdevname=0 biosplusefi=1 + initrdefi xxxPXEBOOTxxx/initrd + } + menuentry 'Graphical Console' --id=graphical { + linuxefi xxxPXEBOOTxxx/bzImage-std rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller BOOTIF=$net_default_mac instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=tty1 biosdevname=0 biosplusefi=1 + initrdefi xxxPXEBOOTxxx/initrd + } } -menuentry '3) UEFI Debian All-in-one Install' { - linuxefi xxxLAB_PXExxx/bzImage-std rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker BOOTIF=$net_default_mac instdev=/dev/sda ks=xxxBASE_URLxxx/xxxLAB_FEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxLAB_FEEDxxx/ostree_repo console=ttyS0,115200 console=tty1 biosdevname=0 biosplusefi=1 - initrdefi xxxLAB_PXExxx/initrd +submenu 'UEFI Debian All-in-one Install' --id=aio { + menuentry 'Serial Console' --id=serial { + linuxefi xxxPXEBOOTxxx/bzImage-std rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker BOOTIF=$net_default_mac instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=ttyS0,115200 biosdevname=0 biosplusefi=1 + initrdefi xxxPXEBOOTxxx/initrd + } + menuentry 'Graphical Console' --id=graphical { + linuxefi xxxPXEBOOTxxx/bzImage-std rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker BOOTIF=$net_default_mac instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=tty1 biosdevname=0 biosplusefi=1 + initrdefi xxxPXEBOOTxxx/initrd + } } -menuentry '4) UEFI Debian All-in-one (lowlatency) Install' { - linuxefi xxxLAB_PXExxx/bzImage-rt rdinit=/install defaultkernel=vmlinuz-*-rt-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker,lowlatency efi=runtime BOOTIF=$net_default_mac instdev=/dev/sda ks=xxxBASE_URLxxx/xxxLAB_FEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxLAB_FEEDxxx/ostree_repo console=ttyS0,115200 console=tty1 biosdevname=0 biosplusefi=1 - initrdefi xxxLAB_PXExxx/initrd +submenu 'UEFI Debian All-in-one (lowlatency) Install' --id=aio-lowlat { + menuentry 'Serial Console' --id=serial { + linuxefi xxxPXEBOOTxxx/bzImage-rt rdinit=/install defaultkernel=vmlinuz-*-rt-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker,lowlatency efi=runtime BOOTIF=$net_default_mac instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=ttyS0,115200 biosdevname=0 biosplusefi=1 + initrdefi xxxPXEBOOTxxx/initrd + } + menuentry 'Graphical Console' --id=graphical { + linuxefi xxxPXEBOOTxxx/bzImage-rt rdinit=/install defaultkernel=vmlinuz-*-rt-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker,lowlatency efi=runtime BOOTIF=$net_default_mac instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=tty1 biosdevname=0 biosplusefi=1 + initrdefi xxxPXEBOOTxxx/initrd + } } - diff --git a/installer/pxe-network-installer/pxe-network-installer/pxeboot.cfg.debian b/installer/pxe-network-installer/pxe-network-installer/pxeboot.cfg.debian index 816d0c52..f5794834 100644 --- a/installer/pxe-network-installer/pxe-network-installer/pxeboot.cfg.debian +++ b/installer/pxe-network-installer/pxe-network-installer/pxeboot.cfg.debian @@ -1,6 +1,7 @@ +# default 20 second timout +timeout 200 serial 0 115200 -timeout 50 -default 4 +default xxxSYSTEMxxx # Menu Configuration MENU WIDTH 80 @@ -15,26 +16,48 @@ MENU TIMEOUTROW 20 MENU TITLE StarlingX Debian LAT / Kickstart Boot Menu label 0 - menu label ^0) Boot from hard drive - menu default + menu label Boot from hard drive COM32 chain.c32 APPEND hd0 -label 1 - menu label ^1) Debian Controller Install - kernel xxxLAB_PXExxx/bzImage-std - append initrd=xxxLAB_PXExxx/initrd rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller instdev=/dev/sda ks=xxxBASE_URLxxx/xxxLAB_FEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxLAB_FEEDxxx/ostree_repo console=ttyS0,115200 console=tty1 biosdevname=0 biosplusefi=1 - ipappend 2 +menu begin + menu title Debian Controller Install + label 1 + menu label Serial Console + kernel xxxPXEBOOTxxx/bzImage-std + append initrd=xxxPXEBOOTxxx/initrd rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=ttyS0,115200 biosdevname=0 biosplusefi=1 + ipappend 2 + label 2 + menu label Graphical Console + kernel xxxPXEBOOTxxx/bzImage-std + append initrd=xxxPXEBOOTxxx/initrd rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=tty1 biosdevname=0 biosplusefi=1 + ipappend 2 +menu end -label 2 - menu label ^2) Debian All-in-one Install - kernel xxxLAB_PXExxx/bzImage-std - append initrd=xxxLAB_PXExxx/initrd rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker instdev=/dev/sda ks=xxxBASE_URLxxx/xxxLAB_FEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxLAB_FEEDxxx/ostree_repo console=ttyS0,115200 console=tty1 biosdevname=0 biosplusefi=1 - ipappend 2 - -label 3 - menu label ^2) Debian All-in-one (lowlatency) Install - kernel xxxLAB_PXExxx/bzImage-rt - append initrd=xxxLAB_PXExxx/initrd rdinit=/install defaultkernel=vmlinuz-*-rt-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker,lowlatency instdev=/dev/sda ks=xxxBASE_URLxxx/xxxLAB_FEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxLAB_FEEDxxx/ostree_repo console=ttyS0,115200 console=tty1 biosdevname=0 biosplusefi=1 - ipappend 2 +menu begin + menu title Debian All-in-one Install + label 3 + menu label Serial Console + kernel xxxPXEBOOTxxx/bzImage-std + append initrd=xxxPXEBOOTxxx/initrd rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=ttyS0,115200 biosdevname=0 biosplusefi=1 + ipappend 2 + label 4 + menu label Graphical Console + kernel xxxPXEBOOTxxx/bzImage-std + append initrd=xxxPXEBOOTxxx/initrd rdinit=/install defaultkernel=vmlinuz-*[!t]-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=tty1 biosdevname=0 biosplusefi=1 + ipappend 2 +menu end +menu begin + menu title Debian All-in-one (lowlatency) Install + label 5 + menu label Serial Console + kernel xxxPXEBOOTxxx/bzImage-rt + append initrd=xxxPXEBOOTxxx/initrd rdinit=/install defaultkernel=vmlinuz-*-rt-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker,lowlatency instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=ttyS0,115200 biosdevname=0 biosplusefi=1 + ipappend 2 + label 6 + menu label Graphical Console + kernel xxxPXEBOOTxxx/bzImage-rt + append initrd=xxxPXEBOOTxxx/initrd rdinit=/install defaultkernel=vmlinuz-*-rt-amd64 instname=debian instbr=starlingx instab=0 traits=controller,worker,lowlatency instdev=xxxINSTDEVxxx ks=xxxBASE_URLxxx/xxxFEEDxxx/kickstart/kickstart.cfg insturl=xxxBASE_URLxxx/xxxFEEDxxx/ostree_repo console=tty1 biosdevname=0 biosplusefi=1 + ipappend 2 +menu end diff --git a/installer/pxe-network-installer/pxe-network-installer/pxeboot_setup.sh b/installer/pxe-network-installer/pxe-network-installer/pxeboot_setup.sh new file mode 100755 index 00000000..173df46a --- /dev/null +++ b/installer/pxe-network-installer/pxe-network-installer/pxeboot_setup.sh @@ -0,0 +1,313 @@ +#!/bin/bash +# +# Copyright (c) 2016-2022 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +############################################################################ +# +# This script is used to create lab specific controller-0 install grub menus. +# from template files through the following variable replacements. +# +# xxxPXEBOOTxxx : Replaces this string with the filesystem path between +# /pxeboot and where the kernel/initrd files are stored. +# +# example : --pxeboot vlm-boards/some_system_name/feed +# +# Will then replace all instances in template files of ... +# +# 'xxxPXEBOOTxxx' with 'vlm-boards/some_system_name/feed' +# +# xxxFEEDxxx : replace with pxeboot path to server's install feed +# +# example : --feed umalab/some_server_name_feed +# +# Will then replace all instances in template files of ... +# +# 'xxxFEEDxxx' with 'umalab/some_server_name_feed' +# +# xxxBASE_URLxxx : replace with url path to server's install feed +# +# example : --url http://###.###.###.### +# +# Will then replace all instances in template files of ... +# +# xxxBASE_URLxxx with http://###.###.###.### +# +# Optional Settings +# +# xxxINSTDEVxxx : set the install device ; defaults to /dev/sda if missing +# example : --device /dev/sde +# +# xxxSYSTEMxxx : specify the install system type ; default is AIO '2' +# example : --system 2 +# +# system type values +# +# 0 - disk boot +# 1 - controller +# 2 - All-in-one (standard) +# 3 - All-in-one (lowlatency) +# +# Refer to usage function for option details. +# +############################################################################ + +trap ctrl_c INT +function ctrl_c { + echo "Exiting ..." + exit 1 +} + +# Debian Legacy BIOS and UEFI controller-0 install grub file names constants +BIOS_PXEBOOT_GRUB_FILE='pxeboot.cfg.debian' +UEFI_PXEBOOT_GRUB_FILE='efi-pxeboot.cfg.debian' + +# User specified path to the menu templates directory ; default empty +MENUS_PATH="" + +# server specific values +BASE_URL="" # the port based URL +FEED_PATH="" # path to the feed directory ; the mounted iso +PXE_PATH="" # offset path between /pxeboot and feed +GRUB_PATH="" # where to put the created grub files + +# Optional Settings with default +INSTDEV="/dev/sda" # default install device to sda + +TTY=0 # default of ttyS0 + +SYSTEM="" # default to menu +BIOS_SYSTEM=menu.c32 # Display the install menu by default +UEFI_SYSTEM=menu.c32 # Display the install menu by default + +# The index of this array maps to the system install types specified +# by the --system option. See below. +UEFI_SYSTEM_TYPES_str=('disk' \ + 'standard>serial' \ + 'standard>graphical' \ + 'aio>serial' \ + 'aio>graphical' \ + 'aio-lowlat>serial' \ + 'aio-lowlat>graphical') + +BACKUP=false + +echo "" + +function usage { + RC=0 + [ ! -z "${1}" ] && RC="${1}" + echo "" + echo "Usage: $0 [Arguments Options]" + echo "" + echo "Arguments:" + echo "" + echo " -i | --input : Path to ${BIOS_PXEBOOT_GRUB_FILE} and ${UEFI_PXEBOOT_GRUB_FILE} grub template files" + echo " -o | --output : Path to created ${BIOS_PXEBOOT_GRUB_FILE} and ${UEFI_PXEBOOT_GRUB_FILE} grub files" + echo " -p | --pxeboot : Offset path between /pxeboot and bzImage/initrd" + echo " -f | --feed : Offset path between http server base and mounted iso" + echo " -u | --url : The pxeboot server's URL" + echo "" + echo "Options:" + echo "" + echo " -h | --help : Print this help info" + echo " -b | --backup : Create backup of updated grub files as .named files" + echo " -d | --device : Install device path ; default: /dev/sda" + echo " -s | --system : System install type ; default: 3" + echo " -t | --tty : Override ttyS0 with port number 0..3 ; default 0 " + echo "" + echo " 0 = Disk Boot" + echo " 1 = Controller Install - Serial Console" + echo " 2 = Controller Install - Graphical Console" + echo " 3 = All-in-one Install - Serial Console (default)" + echo " 4 = All-in-one Install - Graphical Console" + echo " 5 = All-in-one (lowlatency) Install - Serial Console" + echo " 6 = All-in-one (lowlatency) Install - Graphical Console" + echo "" + echo "" + echo "Example:" + echo "" + echo "pxeboot_setup.sh -i /path/to/grub/template/dir" + echo " -o /path/to/target/iso/mount" + echo " -p pxeboot/offset/to/bzImage_initrd" + echo " -f pxeboot/offset/to/target_feed" + echo " -u http://###.###.###.###" + echo " -d /dev/sde" + echo " -s 5" + + exit "${RC}" +} + +[ "${*}" == "" ] && usage + +# Process input options +script=$(basename "$0") +OPTS=$(getopt -o bd:f:hi:o:p:s:t:u: \ + --long backup,device:,feed:,help,input:,output:,pxeboot:,system:,tty:,url: \ + -n "${script}" -- "$@") +if [ $? != 0 ]; then + echo "Failed parsing options." >&2 + usage 1 +fi +eval set -- "$OPTS" +while true; do + case "$1" in + + -b|--backup) + BACKUP=true + shift + ;; + -d|--device) + INSTDEV="${2}" + shift 2 + ;; + -f|--feed) + FEED_PATH="${2}" + shift 2 + ;; + -h|--help) + usage 0 + shift + ;; + -i|--input) + MENUS_PATH="${2}" + shift 2 + ;; + -o|--output) + GRUB_PATH="${2}" + shift 2 + ;; + -p|--pxeboot) + PXE_PATH="${2}" + shift 2 + ;; + -t|--tty) + if echo "${2}" | grep -q -x '[0-9]\+' && [ ${2} -ge 0 ] && [ ${2} -le 3 ]; then + TTY="${2}" + else + echo "Error: ttySx where x=${2} is out of range [0..3]" + usage 1 + fi + shift 2 + ;; + + -s|--system) + if echo "${2}" | grep -q -x '[0-9]\+' && [ ${2} -ge 0 ] && [ ${2} -le 6 ]; then + SYSTEM=${2} + # UEFI: Translate the incoming system type to a string that + # specifies the 'default' menu path to be taken. + UEFI_SYSTEM="${UEFI_SYSTEM_TYPES_str[${2}]}" + + # BIOS menu uses the system type number directly. + BIOS_SYSTEM="${2}" + else + echo "Error: system install type '${2}' is out of range [0..6]" + usage 1 + fi + shift 2 + ;; + -u|--url) + BASE_URL="${2}" + shift 2 + ;; + --) + shift + break + ;; + esac +done + +if [ -z "${MENUS_PATH}" ] ; then + echo "Error: Grub file templates dir path is required: -i " + usage 1 +elif [ ! -d "${MENUS_PATH}" ] ; then + echo "Error: Grub file templates dir ${MENUS_PATH} is not present." + usage 1 +elif [ ! -e "${MENUS_PATH}/${BIOS_PXEBOOT_GRUB_FILE}" ] ; then + echo "Error: BIOS grub template file ${MENUS_PATH}/${BIOS_PXEBOOT_GRUB_FILE} is not present." + usage 1 +elif [ ! -e "${MENUS_PATH}/${UEFI_PXEBOOT_GRUB_FILE}" ] ; then + echo "Error: UEFI grub template file ${MENUS_PATH}/${UEFI_PXEBOOT_GRUB_FILE} is not present." + usage 1 +elif [ -z "${BASE_URL}" ]; then + echo "Error: HTTP Base pxeboot server URL is required: -u " + usage 1 +elif [ -z "${PXE_PATH}" ]; then + echo "Error: PXE boot path is required: -u " + usage 1 +elif [ -z "${FEED_PATH}" ]; then + echo "Error: Target specific feed path is required: -f " + usage 1 +elif [ -z "${GRUB_PATH}" ]; then + echo "Error: Target specific grub path is required: -o " + usage 1 +elif [ ! -d "${GRUB_PATH}" ]; then + echo "Error: Target specific grub path is missing: ${GRUB_PATH}" + usage 1 +fi + +cmd_file="" +if [ "${BACKUP}" = true ] ; then + # Save the command used to create these menus + # Needs to be done before the escape sequence below. + if [ -d "${GRUB_PATH}" ] ; then + cmd_file=${GRUB_PATH}/pxeboot_setup_cmd.sh + echo "${0} \\" > "${cmd_file}" + echo "-i ${MENUS_PATH} \\" >> "${cmd_file}" + echo "-o ${GRUB_PATH} \\" >> "${cmd_file}" + echo "-p ${PXE_PATH} \\" >> "${cmd_file}" + echo "-f ${FEED_PATH} \\" >> "${cmd_file}" + echo "-u ${BASE_URL} \\" >> "${cmd_file}" + if [ "${SYSTEM}" != "" ] ; then + echo "-d ${INSTDEV} \\" >> "${cmd_file}" + echo "-s ${SYSTEM}" >> "${cmd_file}" + else + echo "-d ${INSTDEV}" >> "${cmd_file}" + fi + fi + chmod 777 "${cmd_file}" +fi + +#Escape paths for sed +PXE_PATH="${PXE_PATH//\//\\/}" +BASE_URL="${BASE_URL//\//\\/}" +FEED_PATH="${FEED_PATH//\//\\/}" + +#Variable replacement +cp "${MENUS_PATH}"/"${BIOS_PXEBOOT_GRUB_FILE}" "${GRUB_PATH}" +sed -i "s#xxxBASE_URLxxx#${BASE_URL}#g; + s#xxxPXEBOOTxxx#${PXE_PATH}#g; + s#xxxFEEDxxx#${FEED_PATH}#g; + s#xxxINSTDEVxxx#${INSTDEV}#g; + s#xxxSYSTEMxxx#${BIOS_SYSTEM}#g; + s#ttyS0#ttyS${TTY}#g" \ + "${GRUB_PATH}/${BIOS_PXEBOOT_GRUB_FILE}" +cp "${MENUS_PATH}"/"${UEFI_PXEBOOT_GRUB_FILE}" "${GRUB_PATH}" +sed -i "s#xxxBASE_URLxxx#${BASE_URL}#g; + s#xxxPXEBOOTxxx#${PXE_PATH}#g; + s#xxxFEEDxxx#${FEED_PATH}#g; + s#xxxINSTDEVxxx#${INSTDEV}#g; + s#xxxSYSTEMxxx#${UEFI_SYSTEM}#g; + s#ttyS0#ttyS${TTY}#g" \ + "${GRUB_PATH}/${UEFI_PXEBOOT_GRUB_FILE}" + +# leave these grub files as read/write for owner and group, read only world +chmod 664 "${GRUB_PATH}/${BIOS_PXEBOOT_GRUB_FILE}" +chmod 664 "${GRUB_PATH}/${UEFI_PXEBOOT_GRUB_FILE}" + +if [ "${BACKUP}" = true ] ; then + # Save a backup of these created files + if [ -e "${GRUB_PATH}"/"${BIOS_PXEBOOT_GRUB_FILE}" ] ; then + cp -f "${GRUB_PATH}"/"${BIOS_PXEBOOT_GRUB_FILE}" "${GRUB_PATH}/.${BIOS_PXEBOOT_GRUB_FILE}" + cp -f "${GRUB_PATH}"/"${UEFI_PXEBOOT_GRUB_FILE}" "${GRUB_PATH}/.${UEFI_PXEBOOT_GRUB_FILE}" + fi +fi + +tmp="The setup is complete" +if [ "${cmd_file}" != "" ] ; then + echo "${tmp} ; cmd saved to ${cmd_file}" +else + echo "${tmp}" +fi +exit 0