diff options
Diffstat (limited to 'adapt-ks-template')
| -rwxr-xr-x | adapt-ks-template | 191 |
1 files changed, 186 insertions, 5 deletions
diff --git a/adapt-ks-template b/adapt-ks-template index db8ce3a..f6573de 100755 --- a/adapt-ks-template +++ b/adapt-ks-template @@ -1,7 +1,188 @@ #!/bin/bash # -# This is just a placeholder for a script which will be called with some -# options, and create a kickstart config froma template using those options. -# -# The kickstart config will then be placed somewhere, where it can be pulled -# by the installer +# proof of concept script to pull a kickstart template and adapt it to +# a config for a specific host + +Self=$(basename $0) + +function print_usage { + echo "usage: $Self <options>" +} + +function print_help { +cat <<EOF +$Self <options> +This script pulls a kickstart template from somewhere and creates a +specific kickstart config for a specific host based on the options +passed to it. + +The kickstart config will then be placed somewhere, where it can be pulled +by the installer, which is probably the floppy image borne ipxe booted +CentOS7 install system. + +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 + -M, --netmask Netmask of target system + -N, --nameserver Nameserver of target system + -P, --publish-path Path where results will be stored + --sec-ip IP of secondary interface + --sec-nm Netmask of secondary interface + -h, --help this + + +EOF +} + +# Needed 'macro/substitutions: +# INSTALLSERVER +# PRIGATEWAY +# PRIIP +# PRINETMASK +# PRINAMESERVERS +# SECIP +# SECNETMASK +# HOSTNAME +# DOMAIN + +function parse_commadline { + while [ "$#" -gt 0 ] ; do + case "$1" in + -h|--help) + print_help + exit 0 + ;; + -H|--host) + Host="$2" + shift + ;; + -D|--domain) + Domain="$2" + shift + ;; + -I|--ip) + IP="$2" + shift + ;; + -M|--netmask) + NM="$2" + shift + ;; + -G|--gateway) + GW="$2" + shift + ;; + -N|--nameserver) + NS="$2" + shift + ;; + -P|--publish-path) + PublishPath="$2" + shift + ;; + -K|--kserver) + Kserver="$2" + shift + ;; + --sec-ip) + SecIP="${2}" + shift + ;; + --sec-nm) + SecNM="${2}" + shift + ;; + -T|--tmp-dir) + TmpDir="${2}" + shift + ;; + *) + echo "what do you mean \"$1\"?" + exit 1 + ;; + esac + shift + done + if [ "x${Host}" = "x" ] + then + echo "${Self}: --host is mandatory" + print_usage + exit 1 + elif [ "x${Domain}" = "x" ] + then + echo "${Self}: --domain is mandatory" + print_usage + exit 1 + elif [ "x${IP}" = "x" ] + then + echo "${Self}: --ip is mandatory" + print_usage + exit 1 + elif [ "x${NM}" = "x" ] + then + echo "${Self}: --netmask is mandatory" + print_usage + exit 1 + elif [ "x${GW}" = "x" ] + then + echo "${Self}: --gateway is mandatory" + print_usage + exit 1 + elif [ "x${SecIP}" = "x" ] + then + echo "${Self}: --sec-ip is mandatory" + print_usage + exit 1 + elif [ "x${SecNM}" = "x" ] + then + echo "${Self}: --sec-nm is mandatory" + print_usage + exit 1 + elif [ "x${Kserver}" = "x" ] + then + echo "setting Kserver" + Kserver="109.105.122.84" + elif [ "x${NS}" = "x" ] + then + NS="109.106.96.141" + fi +} + +parse_commadline ${@} + +# for some bizarre reason, whichever is the last 'elif' in parse_commandline() +# isn't evaluated. So this is needed to make sure $NS is set to something: +if [ "x${NS}" = "x" ] +then + NS="109.105.96.141" +fi + +if [ "x${TmpDir}" = "x" ] +then + TmpDir=$(mktemp -d) +else + mkdir -p "${TmpDir}" +fi + +curl -o "${TmpDir}/ks-template" "https://git.nordu.net/?p=ndn-boot-img-stuffs.git;a=blob_plain;f=ks-template/hw/supermicro/SYS-5018D-FN8T/dtn-10g.ks" + +# substitutions: +sed -ie "s/HOSTNAME/${Host}/g" "${TmpDir}/ks-template" +sed -ie "s/INSTALLSERVER/${Kserver}/g" "${TmpDir}/ks-template" +sed -ie "s/PRIIP/${IP}/g" "${TmpDir}/ks-template" +sed -ie "s/PRINETMASK/${NM}/g" "${TmpDir}/ks-template" +sed -ie "s/PRIGATEWAY/${GW}/g" "${TmpDir}/ks-template" +sed -ie "s/PRINAMESERVERS/${NS}/g" "${TmpDir}/ks-template" +sed -ie "s/SECIP/${SecIP}/g" "${TmpDir}/ks-template" +sed -ie "s/SECNETMASK/${SecNM}/g" "${TmpDir}/ks-template" + +if [ "x${PublishPath}" = "x" ] +then + echo "PublishPath no set, leaving everything in ${TmpDir}" +else + mkdir -p "${PublishPath}/ks" + mv "${TmpDir}/ks-template" "${PublishPath}/ks/${Host}.ks" + rm -rf "${TmpDir}/*" +fi |
