summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Clausen <jac@nordu.net>2018-07-16 14:08:16 +0200
committerJon Clausen <jac@nordu.net>2018-07-16 14:08:16 +0200
commit09632c0f8b69528f238bd850be27afa33fc1206b (patch)
treea5fbd73d20ab282aaa49ded08b3d88d818fef9e3
parent64bb4076f0ac9549a4fc0c746926e10d2bb178fa (diff)
big bang, things are now working -ish
-rwxr-xr-xadapt-ks-template191
-rwxr-xr-xcreate-boot-floppy72
-rwxr-xr-xprep-boot-floppy-and-ks-config195
3 files changed, 437 insertions, 21 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
diff --git a/create-boot-floppy b/create-boot-floppy
index 7494043..6178e76 100755
--- a/create-boot-floppy
+++ b/create-boot-floppy
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
# proof of concept script to create a bootable 'deployment' floppy
#
@@ -42,6 +42,9 @@ bootstrapping, and leave the system unmanaged.
If -N, -K, -S options are not given, default values are provided.
+The script needs ipxe and syslinux to run, and 'sudo' to copy things onto the
+floppy image
+
EOF
}
@@ -80,10 +83,18 @@ function parse_commadline {
Kserver="$2"
shift
;;
+ -P|--publish-path)
+ PublishPath="$2"
+ shift
+ ;;
-S|--cosmos-hash)
CosmosHash="$2"
shift
;;
+ -T|--tmp-dir)
+ TmpDir="${2}"
+ shift
+ ;;
*)
echo "what do you mean \"$1\"?"
exit 1
@@ -91,41 +102,57 @@ function parse_commadline {
esac
shift
done
+}
+
+function check_options {
if [ "x${Host}" = "x" ]
then
echo "${Self}: --host is mandatory"
print_usage
exit 1
- elif [ "x${Domain}" = "x" ]
+ fi
+ if [ "x${Domain}" = "x" ]
then
echo "${Self}: --domain is mandatory"
print_usage
exit 1
- elif [ "x${IP}" = "x" ]
+ fi
+ if [ "x${IP}" = "x" ]
then
echo "${Self}: --ip is mandatory"
print_usage
exit 1
- elif [ "x${NM}" = "x" ]
+ fi
+ if [ "x${NM}" = "x" ]
then
echo "${Self}: --netmask is mandatory"
print_usage
exit 1
- elif [ "x${GW}" = "x" ]
+ fi
+ if [ "x${GW}" = "x" ]
then
echo "${Self}: --gateway is mandatory"
print_usage
exit 1
- elif [ "x${NS}" = "x" ]
+ fi
+ if [ "x${NS}" = "x" ]
then
NS="109.105.96.141"
- elif [ "x${Kserver}" = "x" ]
+ fi
+ if [ "x${Kserver}" = "x" ]
then
Kserver="109.105.122.84"
- elif [ "x${CosmosHash}" = "x" ]
+ fi
+ if [ "x${CosmosHash}" = "x" ]
then
CosmosHash="2f15e1edb02f14607084f167929bc145ed47954d"
fi
+ if [ "x${TmpDir}" = "x" ]
+ then
+ TmpDir=$(mktemp -d)
+ else
+ mkdir -p "${TmpDir}"
+ fi
}
# Host="kas-fiona-10-02"
@@ -138,6 +165,7 @@ function parse_commadline {
# CosmosHash="2f15e1edb02f14607084f167929bc145ed47954d"
parse_commadline $@
+check_options
####
# In a bid to be clever, we're adding the 'cosmos hash' to the install
@@ -145,7 +173,7 @@ parse_commadline $@
# lost or 'go missing' from the initial invocation here, until the
# anaconda/kickstart process takes over...
-WorkDir="$HOME/tmp/${Host}.d"
+WorkDir="${TmpDir}/${Host}.d"
mkdir -p ${WorkDir}/mnt
dd if=/dev/zero of=${WorkDir}/${Host}.img bs=2x80x18b count=1
@@ -182,6 +210,7 @@ set gw ${GW}
set ns ${NS}
set hn ${Host}
set dn ${Domain}
+set ks ${Kserver}
###
# Set up network:
@@ -203,8 +232,8 @@ show domain
route
###
# Set install parameters:
-set base http://109.105.122.84/install/centos/7/os/x86_64
-kernel \\$"{"base"}"/images/pxeboot/vmlinuz text console=tty1 console=ttyS1,115200n8 ip=\\$"{"ip"}" netmask=\\$"{"nm"}" gateway=\\$"{"gw"}" repo=\\$"{"base"}" ks=http://\\$"{"Kserver"}"/install/ks/kas-fiona-10-02.cfg cosmoshash=${CosmosHash}
+set base http://\\$"{"ks"}"/install/centos/7/os/x86_64
+kernel \\$"{"base"}"/images/pxeboot/vmlinuz text console=tty1 console=ttyS1,115200n8 ip=\\$"{"ip"}" netmask=\\$"{"nm"}" gateway=\\$"{"gw"}" repo=\\$"{"base"}" ks=http://\\$"{"ks"}"/install/ks/\\$"{"hn"}".ks cosmoshash=${CosmosHash}
initrd \\$"{"base"}"/images/pxeboot/initrd.img
###
# Boot into install
@@ -218,6 +247,25 @@ EOF
#read
-sudo cp -a /usr/share/ipxe/ipxe.lkrn ${WorkDir}/mnt/
+if [ -r /etc/redhat-release ]
+then
+ sudo cp -a /usr/share/ipxe/ipxe.lkrn ${WorkDir}/mnt/
+elif [ -r /etc/debian_version ]
+then
+ sudo cp -a /boot/ipxe.lkrn ${WorkDir}/mnt/
+else
+ echo "neither redhat nor debian, I'm outta here..."
+ exit 1
+fi
sudo extlinux --install ${WorkDir}/mnt/
sudo umount ${WorkDir}/mnt/
+
+if [ ! "x${PublishPath}" = "x" ]
+then
+ mkdir -p "${PublishPath}/${Host}.d/"
+ mv "${WorkDir}/${Host}.img" "${PublishPath}/${Host}.d/"
+ rm -rf ${WorkDir}
+else
+ echo "no PublishPath set, leaving everything in ${WorkDir}"
+fi
+
diff --git a/prep-boot-floppy-and-ks-config b/prep-boot-floppy-and-ks-config
index 5e3f8cf..61dbd64 100755
--- a/prep-boot-floppy-and-ks-config
+++ b/prep-boot-floppy-and-ks-config
@@ -1,11 +1,198 @@
#!/bin/bash
#
-# This is a (placeholder for a) wrapper script
+# 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'
#
-# The results of both scripts will be made available for download, and will be
-# able to bootstrap a (CentOS 7) instance up to, and possibly including,
-# cosmos+puppet bootstrap
+Self=$(basename $0)
+
+function print_usage {
+ echo "usage: $Self <options>"
+}
+
+function print_help {
+cat <<EOF
+$Self <options>
+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
+ --sec-ip IP of secondary interface
+ --sec-nm Netmask 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.
+
+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
+ ;;
+ --sec-ip)
+ SecIP="${2}"
+ shift
+ ;;
+ --sec-nm)
+ SecNM="${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${SecIP}" = "x" ]
+ then
+ echo "${Self}: --sec-ip is mandatory"
+ print_usage
+ exit 1
+ fi
+ if [ "x${SecNM}" = "x" ]
+ then
+ echo "${Self}: --sec-nm is mandatory"
+ print_usage
+ exit 1
+ fi
+ if [ "x${CosmosHash}" = "x" ]
+ then
+ CosmosHash="2f15e1edb02f14607084f167929bc145ed47954d"
+ fi
+ # optional/defaults:
+ if [ "x${Kserver}" = "x" ]
+ then
+ Kserver="109.105.122.84"
+ fi
+ if [ "x${NS}" = "x" ]
+ then
+ NS="109.106.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
+
+${ScriptPath}/create-boot-floppy -D ${Domain} -G ${GW} -H ${Host} \
+ -I ${IP} -M ${NM} -T ${TmpDir} -P ${PublishPath}
+
+${ScriptPath}/adapt-ks-template -D ${Domain} -G ${GW} -H ${Host} \
+ -I ${IP} -M ${NM} -T ${TmpDir} -P ${PublishPath} --sec-ip ${SecIP} \
+ --sec-nm ${SecNM}
+
+# 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}