#!/bin/bash # # This is a wrapper script # # The script expects a number of options, and with them it will first call # 'create-boot-floppy' and next 'adapt-ks-template' # Self=$(basename $0) SelfCommandLine="$(echo ${0} ${@} | sed -e 's/ /;:;/g')" function print_usage { echo "usage: $Self " } function print_help { cat < This is a wrapper for two scripts: adapt-ks-template adapts a kickstart template create-boot-floppy creates a bootable floppy image Because the ipxe config and the kickstart config need many of the same options, it's simpler to call a wrapper with *all* options, and have it call the individual scripts. The results of both scripts will be moved to a directory, which is (assumed to be) published by a webservice, thus making them available for download. The combination of boot-floppy and kickstart config will be able to bootstrap a (CentOS 7) instance up to, and possibly including, cosmos+puppet bootstrap Options: -D, --domain domain, to complete FQDN -G, --gateway Gateway of target system -H, --host hostname of the target system -I, --ip IP address of target system -K, --kserver Kickstart server -M, --netmask Netmask of target system -N, --nameserver Nameserver of target system -P, --publish-path Path where results will be stored -S, --cosmos-hash Hash used by cosmos to verify stuff --boot-dev device to install bootloader on --root-dev device to use for system --cosmos-tag Tag in ndn-sysconf to reference --template Template to use. This is a relative path, plus the name of the template file. Example: supermicro/SYS-5018D-FN8T/dtn-10g.ks dell/R7425/100g-dtn.ks --inst-cmdline add stuff to the install system kernel command line --krnl-cmdline add stuff to the destination system kernel command line --sec-ip IP of secondary interface --sec-nm Netmask of secondary interface --sec-gw Gateway of secondary interface -h, --help this If --cosmos-hash is set to 'disabled', the kickstart stage should skip cosmos bootstrapping, and leave the system unmanaged. If -N, -K, -S options are not given, default values are provided. To avoid shell interpretation of whitespace in --inst-cmdline and --krnl-cmdline use escaped semicolon: To achieve this: console=tty1 console=ttyS0,115200n8 write this: console=tty1\;console=ttyS0,115200n8 EOF } function parse_commadline { while [ "$#" -gt 0 ] ; do case "$1" in -h|--help) print_help exit 0 ;; -D|--domain) Domain="$2" shift ;; -G|--gateway) GW="$2" shift ;; -H|--host) Host="$2" shift ;; -I|--ip) IP="$2" shift ;; -K|--kserver) Kserver="$2" shift ;; -M|--netmask) NM="$2" shift ;; -N|--nameserver) NS="$2" shift ;; -P|--publish-path) PublishPath="$2" shift ;; -S|--cosmos-hash) CosmosHash="$2" shift ;; --boot-dev) BootDev="${2}" shift ;; --root-dev) RootDev="${2}" shift ;; --cosmos-tag) CosmosTag="${2}" shift ;; --sec-ip) SecIP="${2}" shift ;; --sec-nm) SecNM="${2}" shift ;; --sec-gw) SecGW="${2}" shift ;; --template) TemplateOpt="--template ${2}" shift ;; --inst-cmdline) # hand over the argument unchanged, and let create-boot-floppy parse it #InstCmdLineOpt="--inst-cmdline $(echo ${2} | sed -e 's/;/ /g')" InstCmdLineOpt="--inst-cmdline ${2}" shift ;; --krnl-cmdline) # hand over the argument unchanged, and let adapt-ks-template parse it #KrnlCmdLineOpt="--krnl-cmdline $(echo ${2} | sed -e 's/;/ /g')" KrnlCmdLineOpt="--krnl-cmdline ${2}" shift ;; *) echo "what do you mean \"$1\"?" exit 1 ;; esac shift done } function check_options { # mandatory/needed if [ "x${Domain}" = "x" ] then echo "${Self}: --domain is mandatory" print_usage exit 1 fi if [ "x${GW}" = "x" ] then echo "${Self}: --gateway is mandatory" print_usage exit 1 fi if [ "x${Host}" = "x" ] then echo "${Self}: --host is mandatory" print_usage exit 1 fi if [ "x${IP}" = "x" ] then echo "${Self}: --ip is mandatory" print_usage exit 1 fi if [ "x${NM}" = "x" ] then echo "${Self}: --netmask is mandatory" print_usage exit 1 fi if [ "x${CosmosHash}" = "x" ] then CosmosHash="2ea14b0b958fdc70ad37e3cb9b4185b3648137b8" fi # optional/defaults: if [ "x${BootDev}" = "x" ] then BootDev="sda" fi if [ "x${RootDev}" = "x" ] then RootDev="sda" fi if [ ! "x${CosmosTag}" = "x" ] then CosmosTagOpt="--cosmos-tag ${CosmosTag}" fi if [ "x${Kserver}" = "x" ] then Kserver="109.105.122.84" fi if [ "x${NS}" = "x" ] then NS="109.105.96.141" fi if [ "x${PublishPath}" = "x" ] then PublishPath="/var/www/html/install" fi } parse_commadline ${@} check_options TmpDir=$(mktemp -d) # expect to find the other scripts in the same folder this script is in: #echo $0 ScriptPath=$(echo $0 | sed -e "s#/${Self}##") #echo $ScriptPath # only add 'secondary interface' options, if they're all there: if [ -z ${SecIP} ] || [ -z ${SecNM} ] || [ -z ${SecGW} ] then SecIfOpts="" else SecIfOpts="--sec-ip ${SecIP} --sec-nm ${SecNM} --sec-gw ${SecGW}" fi ${ScriptPath}/create-boot-floppy -D ${Domain} -G ${GW} -H ${Host} \ -I ${IP} -M ${NM} -T ${TmpDir} -P ${PublishPath} ${InstCmdLineOpt} \ --gen-cmd ${SelfCommandLine} ${ScriptPath}/adapt-ks-template -D ${Domain} -G ${GW} -H ${Host} \ -I ${IP} -M ${NM} -T ${TmpDir} -P ${PublishPath} ${SecIfOpts} \ ${TemplateOpt} ${KrnlCmdLineOpt} ${CosmosTagOpt} \ --gen-cmd ${SelfCommandLine} --boot-dev "${BootDev}" \ --root-dev "${RootDev}" # When this script calls the other two, PublishPath *is* set, so expect # everything of value to be evacuated, and just clean up: rm -rf ${TmpDir}