Initial move of code from ATT to LF repo
authorEby, Robert (re2429) <re2429@att.com>
Fri, 29 Jun 2018 20:47:19 +0000 (16:47 -0400)
committerEby, Robert (re2429) <re2429@att.com>
Fri, 29 Jun 2018 20:47:19 +0000 (16:47 -0400)
Signed-off-by: Eby, Robert (re2429) <re2429@att.com>
16 files changed:
apply_dellxml.sh [new file with mode: 0755]
boot.ipxe.template [new file with mode: 0644]
buildrc [new file with mode: 0644]
create_ipxe.sh [new file with mode: 0755]
dell_r740_g14_uefi_base.xml.template [new file with mode: 0644]
dell_r740_g14_uefi_httpboot.xml.template [new file with mode: 0644]
dhcpd.conf.template [new file with mode: 0644]
firstboot.sh.template [new file with mode: 0644]
get_dellnicmac.sh [new file with mode: 0755]
install_server_os.sh [new file with mode: 0755]
script.ipxe.template [new file with mode: 0644]
serverrc.template [new file with mode: 0644]
setup_tools.sh [new file with mode: 0755]
sources.list [new file with mode: 0644]
ubuntu.seed.template [new file with mode: 0644]
update_webroot.sh [new file with mode: 0755]

diff --git a/apply_dellxml.sh b/apply_dellxml.sh
new file mode 100755 (executable)
index 0000000..318d481
--- /dev/null
@@ -0,0 +1,159 @@
+#!/bin/bash
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Script to apply Dell BIOS and/or RAID settings.
+#
+# usage:  ./apply_dellxml.sh [--rc settingsfile] --template templatefile [--no-confirm] [--no-apply-hw] [--help]
+#
+
+# default behavior will require confirmation before starting
+NO_CONFIRM=${NO_CONFIRM:-}
+NO_APPLY_HW=${NO_APPLY_HW:-}
+RCFILE=
+TEMPLATE=
+
+# PROCESS COMMAND LINE ARGUMENTS
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    --rc)
+    RCFILE=$2
+    shift # past argument
+    shift # past value
+    ;;
+    --template)
+    TEMPLATE=$2
+    shift # past argument
+    shift # past value
+    ;;
+    --no-confirm|--skip-confirm)
+    NO_CONFIRM=TRUE
+    shift # past argument
+    ;;
+    --no-apply-hw|--skip-biosraid)
+    echo "WARNING:  This run will only create the xlm file and not apply BIOS and RAID configuration.  This is for testing only."
+    NO_APPLY_HW=TRUE
+    shift # past argument
+    ;;
+    --help)
+    echo "usage:  ./apply_dellxml.sh [--rc settingsfile] --template templatefile [--no-confirm] [--no-apply-hw] [--help]"
+    exit 0
+    ;;
+    *)    # unknown option
+    POSITIONAL+=("$1") # save it in an array for later
+    shift # past argument
+    ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
+# SETUP TOOLS AND LOAD DEFAULT BUILD VARIABLES
+BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+. $BASEDIR/setup_tools.sh 1>&2
+
+# LOAD SERVER VARIABLES IF SERVER RCFILE PROVIDED - OTHERWISE ASSUME THE VARIABLES HAVE BEEN EXPORTED
+if [ -n "$RCFILE" ] && [ -f "$RCFILE" ]; then
+    source $RCFILE
+fi
+
+# CHECK A FEW REQUIRED VARIABLES - BUT NOT ALL
+if [ -z "$SRV_NAME" ] || [ -z "$SRV_OOB_IP" ] || [ -z "$SRV_OOB_USR" ] || [ -z "$SRV_OOB_PWD" ]; then
+    echo "ERROR:  Invalid or missing variables in rcfile [$RCFILE]"
+    echo "usage:  ./apply_dellxml.sh [--rc settingsfile] --template templatefile [--no-confirm] [--no-apply-hw] [--help]"
+    exit 1
+fi
+
+# CHECK IF TEMPLATE PASSED AND EXISTS
+if [ -z "$TEMPLATE" ] || ! [ -f "$TOOLS_ROOT/$TEMPLATE" ]; then
+    echo "ERROR:  Invalid or missing template file [$TOOLS_ROOT/$TEMPLATE]"
+    echo "usage:  ./apply_dellxml.sh [--rc settingsfile] --template templatefile [--no-confirm] [--no-apply-hw] [--help]"
+    exit 1
+else
+    echo "Using template [$TOOLS_ROOT/$TEMPLATE]"
+fi
+
+# SET ADDITIONAL VARIABLES BASED ON RC FILE
+SRV_IPXE_URL=http://$BUILD_WEBIP:$BUILD_WEBPORT/ipxe-$SRV_IPXE_INF-$SRV_VLAN.efi
+XMLFILE=$SRV_NAME.${TEMPLATE%\.template}
+
+if [ -z "$NO_CONFIRM" ]; then
+    echo ""
+    read -r -p "Preparing to apply xml file [$TEMPLATE] to server [$SRV_NAME] using oob ip [$SRV_OOB_IP].  Are you sure? [y/N] " response
+    case "$response" in
+        [yY][eE][sS]|[yY]) 
+            ;;
+        *)
+            echo "Script aborted!"
+            exit 1
+            ;;
+    esac
+    echo ""
+else
+    i="10"
+    echo -n "WARNING:  Preparing to apply xml to server [$SRV_NAME] using oob ip [$SRV_OOB_IP].  Beginning in $i seconds "
+    while [ $i -gt 0 ]; do
+        echo -n "."; sleep 1; i=$[$i-1]
+    done
+    echo ""
+fi
+
+echo "Beginning create and apply xlm file to server at" `date`
+STARTTIME=$(date +%s)
+
+## CREATE HARDWARE CONFIG XML FILE FOR USE WITH REDFISH
+echo "Creating server BIOS/RAID settings file [$BUILD_ROOT/$XMLFILE] for server [$SRV_NAME]"
+mkdir -p $BUILD_ROOT
+rm -f $BUILD_ROOT/$XMLFILE
+cp -f $TOOLS_ROOT/$TEMPLATE $BUILD_ROOT/$XMLFILE
+
+for VAR in $(set | grep -P "^SRV_|^BUILD_" | cut -f 1 -d'='); do
+    sed -i -e "s|@@$VAR@@|${!VAR}|g" $BUILD_ROOT/$XMLFILE
+done
+
+## CHECK THAT ALL VALUES WERE REPLACED
+MISSING=$(grep -Po "@@.*?@@" $BUILD_ROOT/$XMLFILE | sort | uniq)
+if [ -n "$MISSING" ] ; then
+    echo "ERROR:  Required variable(s) in template [$TEMPLATE] were not located in the resource file [$RCFILE]"
+    echo ${MISSING//@@/} | xargs -n 1 | sed -e 's/^/        /g'
+    exit 1
+fi
+
+if [ -z "$NO_APPLY_HW" ]; then
+
+    ## PUSH HARDWARE CONFIG XML USING REDFISH - BYPASS PROXY FOR INTERNAL CONNECTION TO IDRAC
+    echo "Applying server settings file [$BUILD_ROOT/$XMLFILE] to [$SRV_OOB_IP]"
+    echo "This step could take up to 10 minutes"
+    HTTPS_PROXY= https_proxy= python "$DELL_ROOT/Redfish Python/ImportSystemConfigurationLocalFilenameREDFISH.py" \
+        -ip $SRV_OOB_IP -u $SRV_OOB_USR -p $SRV_OOB_PWD -t ALL -f $BUILD_ROOT/$XMLFILE -s Forced 2>&1 | \
+        awk '// {print $0;} /FAIL/ {T=1;} END {exit $T;}'
+    if [ "$?" -ne 0 ]; then
+        echo "ERROR:  failed applying server BIOS/RAID settings"
+        exit 1
+    fi
+else
+    ## SKIPPING REBOOT 
+    echo "WARNING:  Skipping application of hardware settings - normally used for testing only"
+fi
+
+## DONE
+ENDTIME=$(date +%s)
+echo "SUCCESS:  Completed update of BIOS/RAID settings on [$SRV_NAME] at" `date`
+echo "Elapsed time was $(( ($ENDTIME - $STARTTIME) / 60 )) minutes and $(( ($ENDTIME - $STARTTIME) % 60 )) seconds"
+
diff --git a/boot.ipxe.template b/boot.ipxe.template
new file mode 100644 (file)
index 0000000..96de068
--- /dev/null
@@ -0,0 +1,24 @@
+#!ipxe
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+set vlan @@IPXE_VLAN@@
+set nic @@IPXE_INTF@@
+echo Starting network on vlan [${vlan}] using nic [${nic}]...
+vcreate --tag ${vlan} ${nic} ||
+ifconf --configurator dhcp ${nic}-${vlan} ||
+isset ${filename} && chain ${filename} || echo Boot file [${filename}] does not exist or is invalid...
+prompt --key 0x02 --timeout 0 Press Ctrl-B for the iPXE command line... && shell || 
+
diff --git a/buildrc b/buildrc
new file mode 100644 (file)
index 0000000..0a59bac
--- /dev/null
+++ b/buildrc
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# NOTE: User will need to update up the required environment variables
+# before executing the build scripts if they differ from the default values.
+
+# SET DEFAULT VALUES
+export IPXE_GIT=${IPXE_GIT:-http://git.ipxe.org/ipxe.git}
+export REDFISH_GIT=${REDFISH_GIT:-http://gerrit.att-akraino.org/redfish.git}
+export DELL_GIT=${DELL_GIT:-https://github.com/dell/iDRAC-Redfish-Scripting.git}
+export IPXE_GIT=${IPXE_GIT:-http://git.ipxe.org/ipxe.git}
+
+export REDFISH_ROOT=${REDFISH_ROOT:-/opt/akraino}
+export WEB_ROOT=${WEB_ROOT:-$REDFISH_ROOT/www}
+export DHCP_ROOT=${DHCP_ROOT:-$REDFISH_ROOT/dhcp}
+export TOOLS_ROOT=${TOOLS_ROOT:-$REDFISH_ROOT/tools}
+export DELL_ROOT=${DELL_ROOT:-$REDFISH_ROOT/dell}
+export REGION_ROOT=${REGION_ROOT:-$WEB_ROOT/region}
+export BUILD_ROOT=${BUILD_ROOT:-$REDFISH_ROOT/server-config}
+export IPXE_ROOT=${IPXE_ROOT:-$REDFISH_ROOT/ipxe}
+
+export UBUNTU_URL=${UBUNTU_URL:-http://releases.ubuntu.com/16.04/ubuntu-16.04.4-server-amd64.iso}
+
diff --git a/create_ipxe.sh b/create_ipxe.sh
new file mode 100755 (executable)
index 0000000..2dda187
--- /dev/null
@@ -0,0 +1,110 @@
+#!/bin/bash
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Script to create webroot for ubuntu os install.
+#
+# usage:  ./create_ipxe.sh [--rc settingsfile] [--help]
+
+# Define Variables
+#
+RCFILE=
+
+# PROCESS COMMAND LINE ARGUMENTS
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    --rc)
+    RCFILE=$2
+    shift # past argument
+    shift # past value
+    ;;
+    --help)
+    echo "usage:  ./create_ipxe.sh [--rc settingsfile] [--help]"
+    exit 0
+    ;;
+    *)    # unknown option
+    POSITIONAL+=("$1") # save it in an array for later
+    shift # past argument
+    ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
+# LOAD BUILD DEFAULT VALUES IF BUILD VARIABLES ARE NOT LOADED
+if [ -z "$REDFISH_ROOT" ]; then
+    BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+    if [ -z "$BASEDIR" ] || ! [ -f "$BASEDIR/buildrc" ]; then
+        echo "ERROR:  Invalid or missing build variables rcfile [$BASEDIR/buildrc]"
+        exit 1
+    fi
+    source "$BASEDIR/buildrc"
+fi
+
+# LOAD SERVER VARIABLES IF SERVER RCFILE PROVIDED - OTHERWISE ASSUME THE VARIABLES HAVE BEEN EXPORTED
+if [ -n "$RCFILE" ] && [ -f "$RCFILE" ]; then
+    source $RCFILE
+fi
+
+IPXE_VLAN=${IPXE_VLAN:-1}
+IPXE_INTF=${IPXE_INTF:-net1}
+
+## CHECK IF IPXE EFI FILE ALREADY EXISTS
+if [ -f "$WEB_ROOT/ipxe-$IPXE_INTF-$IPXE_VLAN.efi" ]; then
+    echo "Skipping ipxe build because efi file [$WEB_ROOT/ipxe-$IPXE_INTF-$IPXE_VLAN.efi] already exists"
+    exit 0
+fi
+
+## GIT CLONE IPXE IF $IPXE_ROOT DOES NOT EXIST
+if [ ! -d "$IPXE_ROOT" ]; then
+    echo "Cloning ipxe source from [$IPXE_GIT] to [$IPXE_ROOT]"
+    git clone $IPXE_GIT $IPXE_ROOT
+fi
+
+## ENABLE VLAN SUPPORT
+if [ ! -f "$IPXE_ROOT/src/config/general.h" ]; then
+    echo "ERROR:  Could not find config file [$IPXE_ROOT/src/config/general.h]"
+    exit 1
+fi
+sed -i 's|//#define VLAN_CMD|#define VLAN_CMD|g' $IPXE_ROOT/src/config/general.h
+
+## CREATE BOOT.IPXE
+rm -f $IPXE_ROOT/boot.ipxe
+sed -e "s|@@IPXE_VLAN@@|$IPXE_VLAN|g" \
+    -e "s|@@IPXE_INTF@@|$IPXE_INTF|g" \
+    $TOOLS_ROOT/boot.ipxe.template > $IPXE_ROOT/boot.ipxe
+if [ ! -f "$IPXE_ROOT/boot.ipxe" ]; then
+    echo "ERROR:  failed creating script [$IPXE_ROOT/boot.ipxe]"
+    exit 1
+fi
+
+## BUILD IPXE
+rm -f $IPXE_ROOT/src/bin-x86_64-efi/ipxe.efi
+echo "Building ipxe from [$IPXE_ROOT/src] with embeded script [$IPXE_ROOT/boot.ipxe]"
+make -C $IPXE_ROOT/src bin-x86_64-efi/ipxe.efi EMBED=$IPXE_ROOT/boot.ipxe 2>&1 | grep -v "[DEPS]"| sed -e "s/^/    /g"
+if [ ! -f "$IPXE_ROOT/src/bin-x86_64-efi/ipxe.efi" ]; then
+    echo "ERROR:  failed creating ipxe.efi [$IPXE_ROOT/src/bin-x86_64-efi/ipxe.efi]"
+    exit 1
+fi
+
+## COPY IPXE TO WEB ROOT
+cp -f $IPXE_ROOT/src/bin-x86_64-efi/ipxe.efi $WEB_ROOT/ipxe-$IPXE_INTF-$IPXE_VLAN.efi
+
+echo "Created ipxe file [$WEB_ROOT/ipxe-$IPXE_INTF-$IPXE_VLAN.efi] in web root [$WEB_ROOT]"
+
diff --git a/dell_r740_g14_uefi_base.xml.template b/dell_r740_g14_uefi_base.xml.template
new file mode 100644 (file)
index 0000000..10455e3
--- /dev/null
@@ -0,0 +1,164 @@
+<!-- Copyright 2018 AT&T Intellectual Property.  All other rights reserved.   -->
+<!--                                                                          -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License");          -->
+<!-- you may not use this file except in compliance with the License.         -->
+<!-- You may obtain a copy of the License at                                  -->
+<!--                                                                          -->
+<!--     http://www.apache.org/licenses/LICENSE-2.0                           -->
+<!--                                                                          -->
+<!-- Unless required by applicable law or agreed to in writing, software      -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,        -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
+<!-- See the License for the specific language governing permissions and      -->
+<!-- limitations under the License.                                           -->
+<!--                                                                          -->
+<SystemConfiguration Model="PowerEdge R740" ServiceTag="XXXXXXX" TimeStamp="Thu Jun  8 11:05:19 2018">
+    <!--Export type is Clone,Selective-->
+    <Component FQDD="RAID.Slot.6-1">
+        <Attribute Name="RAIDresetConfig">True</Attribute>
+        <Attribute Name="RAIDforeignConfig">Clear</Attribute>
+        <Attribute Name="CurrentControllerMode">RAID</Attribute>
+        <Attribute Name="RAIDrekey">False</Attribute>
+        <Attribute Name="EncryptionMode">None</Attribute>
+        <!-- <Attribute Name="KeyID"></Attribute>-->
+        <!-- <Attribute Name="OldControllerKey">******</Attribute>-->
+        <!-- <Attribute Name="NewControllerKey">******</Attribute>-->
+        <Attribute Name="RAIDprMode">Automatic</Attribute>
+        <Attribute Name="RAIDPatrolReadUnconfiguredArea">Enabled</Attribute>
+        <Attribute Name="RAIDloadBalancedMode">Automatic</Attribute>
+        <Attribute Name="RAIDccMode">Normal</Attribute>
+        <Attribute Name="RAIDcopybackMode">On</Attribute>
+        <Attribute Name="RAIDControllerBootMode">Continue Boot On Error</Attribute>
+        <Attribute Name="RAIDEnhancedAutoImportForeignConfig">Disabled</Attribute>
+        <Attribute Name="RAIDrebuildRate">30</Attribute>
+        <Attribute Name="RAIDbgiRate">30</Attribute>
+        <Attribute Name="RAIDccRate">30</Attribute>
+        <Attribute Name="RAIDreconstructRate">30</Attribute>
+        <Component FQDD="Disk.Virtual.0:RAID.Slot.6-1">
+                <Attribute Name="RAIDaction">Create</Attribute>
+                <Attribute Name="LockStatus">Unlocked</Attribute>
+                <Attribute Name="RAIDinitOperation">None</Attribute>
+                <!-- <Attribute Name="T10PIStatus">Disabled</Attribute> -->
+                <Attribute Name="DiskCachePolicy">Default</Attribute>
+                <Attribute Name="RAIDdefaultWritePolicy">WriteBack</Attribute>
+                <Attribute Name="RAIDdefaultReadPolicy">ReadAhead</Attribute>
+                <Attribute Name="Name">root</Attribute>
+                <Attribute Name="Size">479559942144</Attribute>
+                <Attribute Name="StripeSize">128</Attribute>
+                <Attribute Name="SpanDepth">1</Attribute>
+                <Attribute Name="SpanLength">2</Attribute>
+                <Attribute Name="RAIDTypes">RAID 1</Attribute>
+                <Attribute Name="IncludedPhysicalDiskID">Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.6-1</Attribute>
+                <Attribute Name="IncludedPhysicalDiskID">Disk.Bay.1:Enclosure.Internal.0-1:RAID.Slot.6-1</Attribute>
+        </Component>
+        <Component FQDD="Disk.Virtual.1:RAID.Slot.6-1">
+                <Attribute Name="RAIDaction">create</Attribute>
+                <Attribute Name="LockStatus">Unlocked</Attribute>
+                <Attribute Name="RAIDinitOperation">None</Attribute>
+                <!-- <Attribute Name="T10PIStatus">Disabled</Attribute> -->
+                <Attribute Name="DiskCachePolicy">Default</Attribute>
+                <Attribute Name="RAIDdefaultWritePolicy">WriteBack</Attribute>
+                <Attribute Name="RAIDdefaultReadPolicy">ReadAhead</Attribute>
+                <Attribute Name="Name">ceph</Attribute>
+                <Attribute Name="Size">479559942144</Attribute>
+                <Attribute Name="StripeSize">128</Attribute>
+                <Attribute Name="SpanDepth">1</Attribute>
+                <Attribute Name="SpanLength">2</Attribute>
+                <Attribute Name="RAIDTypes">RAID 1</Attribute>
+                <Attribute Name="IncludedPhysicalDiskID">Disk.Bay.2:Enclosure.Internal.0-1:RAID.Slot.6-1</Attribute>
+                <Attribute Name="IncludedPhysicalDiskID">Disk.Bay.3:Enclosure.Internal.0-1:RAID.Slot.6-1</Attribute>
+        </Component>
+        <Component FQDD="Enclosure.Internal.0-1:RAID.Slot.6-1">
+            <Component FQDD="Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Ready</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.1:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Ready</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.2:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Ready</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.3:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Ready</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.4:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Non-RAID</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.5:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Non-RAID</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.6:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Non-RAID</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.7:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Non-RAID</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.8:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Non-RAID</Attribute>
+            </Component>
+            <Component FQDD="Disk.Bay.9:Enclosure.Internal.0-1:RAID.Slot.6-1">
+                <Attribute Name="RAIDHotSpareStatus">No</Attribute>
+                <Attribute Name="RAIDPDState">Non-RAID</Attribute>
+            </Component>
+        </Component>
+        <Attribute Name="RAIDremoveControllerKey">False</Attribute>
+    </Component>
+    <Component FQDD="BIOS.Setup.1-1">
+        <Attribute Name="BootMode">Uefi</Attribute>
+        <Attribute Name="BootSeqRetry">Enabled</Attribute>
+        <Attribute Name="SetBootOrderFqdd1"></Attribute>
+        <Attribute Name="SetBootOrderFqdd2"></Attribute>
+        <Attribute Name="SetBootOrderFqdd3"></Attribute>
+        <Attribute Name="SetBootOrderFqdd4"></Attribute>
+        <Attribute Name="SetBootOrderFqdd5"></Attribute>
+        <Attribute Name="SetBootOrderFqdd6"></Attribute>
+        <Attribute Name="SetBootOrderFqdd7"></Attribute>
+        <Attribute Name="SetBootOrderFqdd8"></Attribute>
+        <Attribute Name="SetBootOrderFqdd9"></Attribute>
+        <Attribute Name="SetBootOrderFqdd10"></Attribute>
+        <Attribute Name="SetBootOrderFqdd11"></Attribute>
+        <Attribute Name="SetBootOrderFqdd12"></Attribute>
+        <Attribute Name="SetBootOrderFqdd13"></Attribute>
+        <Attribute Name="SetBootOrderFqdd14"></Attribute>
+        <Attribute Name="SetBootOrderFqdd15"></Attribute>
+        <Attribute Name="SetBootOrderFqdd16"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd1"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd2"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd3"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd4"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd5"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd6"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd7"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd8"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd9"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd10"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd11"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd12"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd13"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd14"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd15"></Attribute>
+        <Attribute Name="SetLegacyHddOrderFqdd16"></Attribute>
+        <Attribute Name="PxeDev1EnDis">Enabled</Attribute>
+        <Attribute Name="PxeDev2EnDis">Disabled</Attribute>
+        <Attribute Name="PxeDev3EnDis">Disabled</Attribute>
+        <Attribute Name="PxeDev4EnDis">Disabled</Attribute>
+        <Attribute Name="HttpDev1EnDis">Enabled</Attribute>
+        <Attribute Name="HttpDev2EnDis">Disabled</Attribute>
+        <Attribute Name="HttpDev3EnDis">Disabled</Attribute>
+        <Attribute Name="HttpDev4EnDis">Disabled</Attribute>
+        <Attribute Name="IscsiDev1EnDis">Disabled</Attribute>
+        <Attribute Name="IscsiDev1Con1EnDis">Disabled</Attribute>
+        <Attribute Name="IscsiDev1Con2EnDis">Disabled</Attribute>
+        <Attribute Name="SecureBoot">Disabled</Attribute>
+        <Attribute Name="UefiBootSeq">Disk.Virtual.0:RAID.Slot.6-1, NIC.PxeDevice.1-1</Attribute>
+    </Component>
+</SystemConfiguration>
diff --git a/dell_r740_g14_uefi_httpboot.xml.template b/dell_r740_g14_uefi_httpboot.xml.template
new file mode 100644 (file)
index 0000000..74c3c90
--- /dev/null
@@ -0,0 +1,26 @@
+<!-- Copyright 2018 AT&T Intellectual Property.  All other rights reserved.   -->
+<!--                                                                          -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License");          -->
+<!-- you may not use this file except in compliance with the License.         -->
+<!-- You may obtain a copy of the License at                                  -->
+<!--                                                                          -->
+<!--     http://www.apache.org/licenses/LICENSE-2.0                           -->
+<!--                                                                          -->
+<!-- Unless required by applicable law or agreed to in writing, software      -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,        -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
+<!-- See the License for the specific language governing permissions and      -->
+<!-- limitations under the License.                                           -->
+<!--                                                                          -->
+<SystemConfiguration Model="PowerEdge R740" ServiceTag="XXXXXXX" TimeStamp="Thu Jun  8 11:05:19 2018">
+    <!--Export type is Clone,Selective-->
+    <Component FQDD="BIOS.Setup.1-1">
+        <Attribute Name="HttpDev1Interface">@@SRV_HTTP_BOOT_DEV@@</Attribute>
+        <Attribute Name="HttpDev1Protocol">IPv4</Attribute>
+        <Attribute Name="HttpDev1VlanEnDis">Enabled</Attribute>
+        <Attribute Name="HttpDev1VlanId">@@SRV_VLAN@@</Attribute>
+        <Attribute Name="HttpDev1VlanPriority">0</Attribute>
+        <Attribute Name="HttpDev1Uri">@@SRV_IPXE_URL@@</Attribute>
+        <Attribute Name="UefiBootSeq">Disk.Virtual.0:RAID.Slot.6-1, NIC.HttpDevice.1-1, NIC.PxeDevice.1-1</Attribute>
+    </Component>
+</SystemConfiguration>
diff --git a/dhcpd.conf.template b/dhcpd.conf.template
new file mode 100644 (file)
index 0000000..cc37cd0
--- /dev/null
@@ -0,0 +1,53 @@
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# default settings
+default-lease-time 600;
+max-lease-time 7200;
+
+# local dhcp options used to tell ixpe the web server path and server interface name
+option ipxe-web-server code 128 = string;
+option ipxe-interface code 129 = string;
+
+##########################################################################
+# subnet and host entry examples
+# use filename to point to the ubuntu os version desired
+#
+#subnet 192.168.2.0 netmask 255.255.255.0 {
+#    option subnet-mask 255.255.255.0;
+#    option routers 192.168.2.85;
+#    option domain-name-servers 135.25.120.104, 192.168.2.5;
+#    option domain-name lab.akraino.org;
+#    option ipxe-web-server 192.168.2.5:8090;
+#}
+#host server10 {
+#    hardware ethernet 3c:fd:fe:b8:10:60;
+#    fixed-address 192.168.2.10;
+#    option host-name server10;
+#    option ipxe-interface enp135s0f0;
+#    if substring (option vendor-class-identifier,0,9) = "PXEClient" {
+#        filename "http://192.168.2.5:8090/script-hwe-16.04.4-amd64.ipxe";
+#    }
+#}
+#host server11 {
+#    hardware ethernet 3c:fd:fe:b8:02:90;
+#    fixed-address 192.168.2.11;
+#    option host-name server10;
+#    option ipxe-interface enp135s0f0;
+#    if substring (option vendor-class-identifier,0,9) = "PXEClient" {
+#        filename "http://192.168.2.5:8090/script-hwe-16.04.4-amd64.ipxe";
+#    }
+#}
+#
diff --git a/firstboot.sh.template b/firstboot.sh.template
new file mode 100644 (file)
index 0000000..8405f2f
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Add proxy settings if required for your environment
+#
+#export http_proxy=http://your.proxy.com:8080/
+#export https_proxy=http://your.proxy.com:8080/
+
+HOSTNAME=$(hostname -s)
+echo "### BEGINING FIRSTBOOT SCRIPT ###" "[`date`]"
+echo " "
+echo "### BUILDING SERVER [$HOSTNAME]"
+echo " "
+
+echo "Updating available packages"
+apt-get update 
+apt-get install -y apt-transport-https
+
+echo "Adding docker source and key"
+curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -  
+echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" >/etc/apt/sources.list.d/kubernetes.list
+
+echo "Updating available packages"
+apt-get update &>/dev/null
+
+echo "Installing docker"
+apt-get install -y docker.io aufs-tools  2>&1
+
+echo "Checking that docker is running"
+docker ps
+
+echo "Installing sshpass, python-requests and xorriso"
+apt-get install -y sshpass python-requests xorriso  2>&1
+
+exit
+
diff --git a/get_dellnicmac.sh b/get_dellnicmac.sh
new file mode 100755 (executable)
index 0000000..1e3d8a4
--- /dev/null
@@ -0,0 +1,89 @@
+#!/bin/bash
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Script to get Dell nic settings.
+#
+# usage:  ./get_dellnicmac.sh [--rc settingsfile] [--nic FQDD] [--help]
+#
+
+RCFILE=
+FQDD=
+
+# PROCESS COMMAND LINE ARGUMENTS
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    --rc)
+    RCFILE=$2
+    shift # past argument
+    shift # past value
+    ;;
+    --nic)
+    FQDD=$2
+    shift # past argument
+    shift # past value
+    ;;
+    --help)
+    echo "usage:  ./get_dellnicmac.sh [--rc settingsfile] [--nic FQDD] [--help]"
+    exit 0
+    ;;
+    *)    # unknown option
+    POSITIONAL+=("$1") # save it in an array for later
+    shift # past argument
+    ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
+# SETUP TOOLS AND LOAD DEFAULT BUILD VARIABLES
+BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+. $BASEDIR/setup_tools.sh 1>&2
+
+# LOAD SERVER VARIABLES IF SERVER RCFILE PROVIDED - OTHERWISE ASSUME THE VARIABLES HAVE BEEN EXPORTED
+if [ -n "$RCFILE" ] && [ -f "$RCFILE" ]; then
+    source $RCFILE
+fi
+
+# CHECK A FEW REQUIRED VARIABLES - BUT NOT ALL
+if [ -z "$SRV_NAME" ] || [ -z "$SRV_OOB_IP" ] || [ -z "$SRV_OOB_USR" ] || [ -z "$SRV_OOB_PWD" ]; then
+    echo "ERROR:  Invalid or missing variables in rcfile [$RCFILE]"
+    exit 1
+fi
+
+# CHECK IF NIC VALUE PASSED - OTHERWISE USE SRV_HTTP_BOOT_DEV
+if [ -z "$FQDD" ] && [ -z "$SRV_HTTP_BOOT_DEV" ] ; then
+    echo "ERROR:  parameter --nic [$FQDD] or variable SRV_HTTP_BOOT_DEV [$SRV_HTTP_BOOT_DEV] required"
+    exit 1
+fi
+
+if [ -z "$FQDD" ] ; then
+    FQDD=$SRV_HTTP_BOOT_DEV
+fi
+
+## GET NIC SETTINGS USING REDFISH - BYPASS PROXY FOR INTERNAL CONNECTION TO IDRAC
+NIC_DETAILS=$(HTTPS_PROXY= https_proxy= python "$DELL_ROOT/Redfish Python/GetEthernetInterfacesREDFISH.py"  -ip $SRV_OOB_IP -u $SRV_OOB_USR -p $SRV_OOB_PWD -d $FQDD)
+if [ "$?" -ne 0 ]; then
+    echo "ERROR:  failed to get nic settings"
+    exit 1
+fi
+
+## DONE
+echo "$NIC_DETAILS" | grep "^MACAddress" | grep -o "..:..:..:..:..:.." | tr '[:upper:]' '[:lower:]'
+
diff --git a/install_server_os.sh b/install_server_os.sh
new file mode 100755 (executable)
index 0000000..4c2d712
--- /dev/null
@@ -0,0 +1,340 @@
+#!/bin/bash
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Script to install region server.
+#
+# usage:  ./install_regionserver.sh  [--rc settingsfile] [--no-confirm] [--no-apply-hw] [--help]
+
+# Define Variables
+#
+# NOTE: User will need to set up the required environment variables
+# before executing this script if they differ from the default values.
+
+# SET DEFAULT VALUES
+UBUNTU_ISO=${UBUNTU_ISO:-}  ## IF NOT SET, UBUNTU_URL WILL BE USED TO DOWNLOAD DEFAULT ISO
+
+echo "Beginning $0 as user [$USER] in pwd [$PWD] with home [$HOME]"
+
+# default behavior will require confirmation before starting
+NO_CONFIRM=${NO_CONFIRM:-}
+NO_APPLY_HW=${NO_APPLY_HW:-}
+RCFILE=
+
+# PROCESS COMMAND LINE ARGUMENTS
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    --rc)
+    RCFILE=$2
+    shift # past argument
+    shift # past value
+    ;;
+    --no-confirm|--skip-confirm)
+    NO_CONFIRM=TRUE
+    shift # past argument
+    ;;
+    --no-apply-hw|--skip-biosraid)
+    echo "WARNING:  This run will only create the server files and not apply BIOS and RAID configuration.  This is for testing only."
+    NO_APPLY_HW=TRUE
+    shift # past argument
+    ;;
+    --help)
+    echo "usage:  ./install_regionserver.sh  [--rc settingsfile] [--no-confirm] [--no-apply-hw] [--help]"
+    exit 0
+    ;;
+    *)    # unknown option
+    POSITIONAL+=("$1") # save it in an array for later
+    shift # past argument
+    ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
+# MAKE VARIABLES AVAILABLE TO OTHER TOOLS CALLED BY THIS SCRIPT
+export NO_CONFIRM; 
+export NO_APPLY_HW; 
+export RCFILE;
+
+# SETUP TOOLS AND LOAD DEFAULT BUILD VARIABLES
+BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+. $BASEDIR/setup_tools.sh 1>&2
+
+# LOAD SERVER VARIABLES IF SERVER RCFILE PROVIDED - OTHERWISE ASSUME THE VARIABLES HAVE BEEN EXPORTED
+if [ -n "$RCFILE" ] && [ -f "$RCFILE" ]; then
+    source $RCFILE
+fi
+
+if [ -z "$SRV_NAME" ] || [ -z "$SRV_OOB_IP" ] || [ -z "$SRV_OOB_USR" ] || [ -z "$SRV_OOB_PWD" ] || [ -z "$SRV_IPXE_INF" ] || [ -z "$BUILD_WEBIP" ]; then
+    echo "ERROR:  Invalid or missing variables in rcfile [$RCFILE]"
+    echo "usage:  ./install_regionserver.sh  [--rc settingsfile] [--no-confirm] [--no-apply-hw] [--help]"
+    exit 1
+fi
+
+# SET ADDITIONAL VARIABLES BASED ON RC FILE
+IPXE_VLAN=$SRV_VLAN
+IPXE_INTF=$SRV_IPXE_INF
+IPXE_URL=http://$BUILD_WEBIP:$BUILD_WEBPORT/ipxe-$SRV_IPXE_INF-$SRV_VLAN.efi
+
+if [ -z "$NO_CONFIRM" ]; then
+    echo ""
+    read -r -p "Preparing to build of server [$SRV_NAME] using oob ip [$SRV_OOB_IP].  Are you sure? [y/N] " response
+    case "$response" in
+        [yY][eE][sS]|[yY]) 
+            ;;
+        *)
+            echo "Script aborted!"
+            exit 1
+            ;;
+    esac
+    echo ""
+else
+    i="10"
+    echo -n "WARNING:  Preparing to build server [$SRV_NAME] using oob ip [$SRV_OOB_IP].  Beginning in $i seconds "
+    while [ $i -gt 0 ]; do
+        echo -n "."; sleep 1; i=$[$i-1]
+    done
+    echo ""
+fi
+
+echo "Beginning bare metal install of os at" `date`
+STARTTIME=$(date +%s)
+
+## CHECK THAT DOCKER EXISTS
+VERSION=$(docker --version)
+if [ $? -ne 0 ] || [ -z "$VERSION" ]; then
+    echo "ERROR: Unable to determine docker version [$VERSION]"
+    exit 1;
+fi
+
+## CHECK IF BUILD_WEBIP IS ON THIS SERVER
+if ! ifconfig | grep -B1 ":$BUILD_WEBIP " >/dev/null; then
+    echo "ERROR:  Build Web ip address [$BUILD_WEBIP] not found on this server"
+    ifconfig | grep --no-group-separator -B1 "inet addr:"
+    exit 1
+else
+    echo "Found build web ip address [$BUILD_WEBIP] on this server!"
+    ifconfig | grep --no-group-separator -B1 ":$BUILD_WEBIP "
+fi
+
+## COLLECT ANY ADDITIONAL SERVER DATA NEEDED - IE LOOKUP MAC FOR DELL NIC
+case $SRV_OEM in
+    Dell|DELL)
+    if [ -z "$SRV_MAC" ]; then
+        SRV_MAC=$(. $TOOLS_ROOT/get_dellnicmac.sh --nic $SRV_HTTP_BOOT_DEV)
+        if [ "$?" -ne 0 ]; then
+            echo "ERROR:  Unable to get Dell nic mac address from [$SRV_OOB_IP]"
+            exit 1;
+        fi
+    fi
+    ;;
+    HP|HPE)
+    echo "ERROR:  HPE SERVER BUILDS ARE NOT SUPPORTED YET!!!"
+    exit 1;
+    ;;
+    *)    # unknown option
+    echo "ERROR:  Unknown server oem [$SRV_OEM]"
+    exit 1;
+    ;;
+esac
+
+## UPDATE WEB ROOT WITH UBUNTU ISO
+. $TOOLS_ROOT/update_webroot.sh;
+if [ "$?" -ne 0 ]; then
+    echo "ERROR:  failed to add [$UBUNTU_ISO] contents to web root"
+    exit 1
+fi
+
+## CREATE IPXE FILE
+echo "Creating ixpe.efi for web root in folder [$WEB_ROOT] using interface [$SRV_IPXE_INF] and vlan [$SRV_VLAN]"
+if ! (IPXE_VLAN=$SRV_VLAN IPXE_INTF=$SRV_IPXE_INF $TOOLS_ROOT/create_ipxe.sh); then
+    echo "ERROR:  failed to add ipxe file to web root"
+    exit 1
+fi
+
+## ADD FIRSTBOOT SCRIPT TO WEB ROOT
+echo "Adding firstboot script [$SRV_NAME.firstboot.sh] to web root [$WEB_ROOT]"
+cp -f $TOOLS_ROOT/firstboot.sh.template $WEB_ROOT/$SRV_NAME.firstboot.sh
+
+for VAR in $(set | grep -P "^SRV_|^BUILD_" | cut -f 1 -d'='); do
+    sed -i -e "s|@@$VAR@@|${!VAR}|g" $WEB_ROOT/$SRV_NAME.firstboot.sh
+done
+
+## CHECK THAT ALL VALUES WERE REPLACED
+MISSING=$(grep -Po "@@.*?@@" $WEB_ROOT/$SRV_NAME.firstboot.sh | sort | uniq)
+if [ -n "$MISSING" ] ; then
+    echo "ERROR:  Required variable(s) in template [firstboot.sh.template] were not located in the resource file [$RCFILE]"
+    echo ${MISSING//@@/} | xargs -n 1 | sed -e 's/^/        /g'
+    exit 1
+fi
+
+## CREATE SERVER SEED FILE
+echo "Creating seed file [$WEB_ROOT/$SRV_NAME.seed] for server [$SRV_NAME]"
+cp -f $TOOLS_ROOT/ubuntu.seed.template $WEB_ROOT/$SRV_NAME.seed
+
+for VAR in $(set | grep -P "^SRV_|^BUILD_" | cut -f 1 -d'='); do
+    sed -i -e "s|@@$VAR@@|${!VAR}|g" $WEB_ROOT/$SRV_NAME.seed
+done
+
+## CHECK THAT ALL VALUES WERE REPLACED
+MISSING=$(grep -Po "@@.*?@@" $WEB_ROOT/$SRV_NAME.seed | sort | uniq)
+if [ -n "$MISSING" ] ; then
+    echo "ERROR:  Required variable(s) in template [ubuntu.seed.template] were not located in the resource file [$RCFILE]"
+    echo ${MISSING//@@/} | xargs -n 1 | sed -e 's/^/        /g'
+    exit 1
+fi
+
+## START WEB SERVICE
+echo "Starting web server using folder [$WEB_ROOT] on port [$BUILD_WEBPORT]"
+# existing container is using different web root or does not exist
+docker stop boot-www-server &> /dev/null
+docker rm boot-www-server &> /dev/null
+docker run -dit --name boot-www-server -p $BUILD_WEBPORT:80 -v "$WEB_ROOT":/usr/local/apache2/htdocs/ httpd:alpine >/dev/null && sleep 5
+if ! docker ps | grep boot-www-server >/dev/null || ! curl http://localhost:$BUILD_WEBPORT/ &>/dev/null ; then
+    echo "ERROR: Failed to start web server using folder [$WEB_ROOT] and port [$BUILD_WEBPORT]"
+    ls -l $WEB_ROOT
+    docker run -it --name boot-www-server -p $BUILD_WEBPORT:80 -v "$WEB_ROOT":/usr/local/apache2/htdocs/ httpd:alpine 2>&1
+    exit 1
+fi
+
+## CREATE DHCP CONFIG FILE
+if [ ! -f "$DHCP_ROOT/dhcpd.conf" ]; then
+    echo "Creating new dhcp configuration [$DHCP_ROOT/dhcpd.conf]"
+    mkdir -p $DHCP_ROOT
+    cp -f $TOOLS_ROOT/dhcpd.conf.template $DHCP_ROOT/dhcpd.conf
+fi
+
+echo "Updating dhcp configuration [$DHCP_ROOT/dhcpd.conf] with subnet [$SRV_SUBNET]"
+perl -i -p0e "s/^subnet $SRV_SUBNET .*?\n\}\n//gms" $DHCP_ROOT/dhcpd.conf
+cat >>$DHCP_ROOT/dhcpd.conf <<EOF
+subnet $SRV_SUBNET netmask $SRV_NETMASK {
+    option subnet-mask $SRV_NETMASK;
+    option routers $SRV_GATEWAY;
+    option domain-name-servers $SRV_DNS;
+    option domain-name "$SRV_DOMAIN";
+    option ipxe-web-server "$BUILD_WEBIP:$BUILD_WEBPORT";
+}
+EOF
+
+echo "Updating dhcp configuration [$DHCP_ROOT/dhcpd.conf] with server [$SRV_NAME]"
+## DELETE ANY HOST ENTRY WITH THE SAME MAC ADDRESS (IGNORING THE NAME WHICH COULD CHANGE)
+perl -i -p0e "s/^host.*?$SRV_MAC.*?\n\}\n//gms" $DHCP_ROOT/dhcpd.conf
+cat >>$DHCP_ROOT/dhcpd.conf <<EOF
+host $SRV_NAME {
+    hardware ethernet $SRV_MAC;
+    fixed-address $SRV_IP;
+    option host-name $SRV_NAME;
+    option ipxe-interface "$SRV_BLD_INF";
+    if substring (option vendor-class-identifier,0,9) = "PXEClient" {
+        filename "http://$BUILD_WEBIP:$BUILD_WEBPORT/$SRV_BLD_SCRIPT";
+    }
+}
+EOF
+
+## START DHCP SERVICE
+echo "Starting dhcp server using folder [$DHCP_ROOT] on interface [$BUILD_INTERFACE]"
+docker stop boot-dhcp-server &> /dev/null
+docker rm boot-dhcp-server &> /dev/null
+docker run -dit --name boot-dhcp-server --rm --net=host -v "$DHCP_ROOT":/data networkboot/dhcpd $BUILD_INTERFACE >/dev/null && sleep 5
+if ! docker ps | grep boot-dhcp-server >/dev/null; then
+    echo "ERROR: Failed to start dhcp server using folder [$DHCP_ROOT] and interface [$BUILD_INTERFACE]"
+    echo "Contents of [$DHCP_ROOT/dhcpd.conf]"
+    cat $DHCP_ROOT/dhcpd.conf 
+    docker run -it --name boot-dhcp-server --rm --net=host -v "$DHCP_ROOT":/data networkboot/dhcpd $BUILD_INTERFACE 2>&1
+    exit 1
+fi
+
+## CREATE CONFIG FILES AND APPLY UNLESS CALLED WITH --no-apply-hw
+. $TOOLS_ROOT/apply_dellxml.sh --template $SRV_BIOS_TEMPLATE
+echo "Completed update with status [$?]"
+sleep 20
+
+. $TOOLS_ROOT/apply_dellxml.sh --template $SRV_BOOT_TEMPLATE
+echo "Completed update with status [$?]"
+sleep 20
+
+if [ -z "$NO_APPLY_HW" ]; then
+
+    ## WAIT FOR UBUNTU INSTALL TO DOWNLOAD $SRV_NAME.firstboot.sh
+    echo "Waiting for server [$SRV_IP] to download [$SRV_NAME.firstboot.sh] from web container at" `date`
+    echo "This step could take up to 15 minutes"
+    WEBLOG_START=$(date +%FT%T)  
+    # ONLY CHECK ENTRIES AFTER WEBLOG_START TO AVOID PAST BUILDS, CHECK UP TO LAST 10 ENTRIES TO AVOID MISSING MESSAGES AFTER RESTART
+    while ( ! (docker logs --since "$WEBLOG_START" --tail 10 -f boot-www-server &) | awk "// {print \$0;} /^$SRV_IP.*GET \/$SRV_NAME.firstboot.sh/ {exit;}" ); do
+        echo "WARNING:  Web server was restarted..."
+    done
+
+    ## WAIT FOR SERVER TO START REBOOT
+    echo "Waiting for server [$SRV_IP] to reboot" `date`
+    echo "Waiting for server to shutdown..."
+    (ping -i 5 $SRV_IP &) | awk '// {print $0;} /Destination Host Unreachable/ {x++; if (x>3) {exit;}}'
+    
+    # wait for previous ping to abort
+    sleep 10
+else
+    ## SKIPPING REBOOT 
+    echo "Skipping application of BIOS/RAID settings - OS should be installed already to work properly - normally used for testing only"
+fi
+
+## WAIT FOR SERVER TO FINISH REBOOT - PING SUCCEEDS 4 TIMES
+echo "Waiting for server to come back up..."
+(ping -i 5 $SRV_IP &) | awk '// {print $0;} /time=/ {x++; if (x>3) {exit;}}'
+
+## SETUP SSH KEYS
+echo "Setting up ssh keys for user [$USER] with home [$HOME]"
+if ! dpkg -l | grep "sshpass " > /dev/null; then
+    echo "  Installing sshpass"
+    apt-get install -y sshpass 2>&1 || echo "ERROR: sshpass is required to complete the build"; exit 1;
+fi
+if ! [ -f $HOME/.ssh/id_rsa ]; then 
+    echo "  Creating rsa key [$HOME/.ssh/id_rsa]"
+    ssh-keygen -t rsa -f $HOME/.ssh/id_rsa -P ""
+fi
+echo "  Removing any old host keys for [$SRV_IP]"
+ls -l $HOME/.ssh/
+chown $USER:$USER $HOME/.ssh/known_hosts
+ssh-keygen -f "$HOME/.ssh/known_hosts" -R $SRV_IP
+chown $USER:$USER $HOME/.ssh/known_hosts
+ls -l $HOME/.ssh/
+
+echo "  Getting new host keys for [$SRV_IP]"
+sleep 5
+ssh-keyscan -t rsa -H $SRV_IP >> $HOME/.ssh/known_hosts
+
+echo "  copying user key to [root@$SRV_IP]"
+sleep 5
+export SSHPASS=$SRV_PWD
+sshpass -e ssh-copy-id -i $HOME/.ssh/id_rsa root@$SRV_IP
+
+## RUN FIRSTBOOT SCRIPT
+echo "Running first boot script"
+sleep 5
+sshpass -e ssh -i $HOME/.ssh/id_rsa root@$SRV_IP /root/$SRV_NAME.firstboot.sh
+if [ "$?" -ne 0 ]; then
+    echo "FAILED:  Unable to run firstboot script on new server"
+    exit 1
+fi
+
+## DONE
+ENDTIME=$(date +%s)
+echo "SUCCESS:  Completed bare metal install of regional server [$SRV_NAME] at" `date`
+echo "SUCCESS:  Try connecting with 'ssh root@$SRV_IP' as user $USER"
+echo "Elapsed time was $(( ($ENDTIME - $STARTTIME) / 60 )) minutes and $(( ($ENDTIME - $STARTTIME) % 60 )) seconds"
+exit 0
+
diff --git a/script.ipxe.template b/script.ipxe.template
new file mode 100644 (file)
index 0000000..8b967af
--- /dev/null
@@ -0,0 +1,34 @@
+#!ipxe
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+set web-server ${128:string}
+set base-url http://${web-server}
+set interface ${129:string}
+
+echo Using vlan [${vlan}] nic [${nic}] from embedded boot.ipxe
+echo Using base-url [${base-url}] and interface [${interface}]
+echo Starting Ubuntu Xenial installer for [${mac}] on [${hostname}]
+
+prompt --key 0x02 --timeout 15000 Press Ctrl-B for the iPXE command line... && shell ||
+
+kernel ${base-url}/@@KERNEL@@ root=/dev/ram0 load_ramdisk=1 initrd=@@INITRD@@ showopts ramdisk_size=65535 auto=true locale=en_US hostname=${hostname} url=${base-url}/${hostname}.seed interface=${interface} netcfg/vlan_id=${vlan} base-installer/kernel/override-image=@@BASE_KERNEL@@ live-installer/net-image=${base-url}/@@UBUNTU_ROOT@@/install/filesystem.squashfs mirror/http/directory=/@@UBUNTU_ROOT@@ mirror/http/hostname=${web-server}
+initrd ${base-url}/@@INITRD@@
+boot || goto failed
+
+:failed
+echo Boot from ${base-url} failed
+shell
+
diff --git a/serverrc.template b/serverrc.template
new file mode 100644 (file)
index 0000000..09114d3
--- /dev/null
@@ -0,0 +1,80 @@
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Add proxy settings if required for your environment
+# export http_proxy=http://your.proxy.com:8080/
+# export https_proxy=http://your.proxy.com:8080/
+#
+
+# Set the ip and port to use when creating the web server
+BUILD_WEBIP=192.168.2.5
+BUILD_WEBPORT=8090
+
+# host name for server
+SRV_NAME=aknode44
+
+# server oem - Dell or HPE (case sensitive)
+SRV_OEM=Dell
+
+# out of band interface information for server (idrac/ilo/etc)
+SRV_OOB_IP=192.168.41.254
+SRV_OOB_USR=root
+SRV_OOB_PWD=calvin
+
+# mac address of server to be used during the build - not required for Dell servers
+# SRV_MAC=3c:fd:fe:b8:10:60
+
+# name of network interface used during build when ipxe.efi is booted and when os is booted
+# ipxe numbers ports from 0-n in pci bus order. 
+# the netx value will depend on how many nics are in the server 
+# and which pci device number is assigned to the slot
+SRV_IPXE_INF=net4
+
+# the build interface is the nic used by the Ubuntu installed to load the OS
+SRV_BLD_INF=enp94s0f0
+
+# the boot device is the device name on which the OS will be loaded
+SRV_BOOT_DEVICE=sda
+
+# ipxe script to use - based on the os version and kernel to install
+# valid options are script-hwe-16.04.4-amd64.ipxe or script-16.04.4-amd64.ipxe
+SRV_BLD_SCRIPT=script-hwe-16.04.4-amd64.ipxe
+
+# template xml file to set bios and raid configuration settings
+SRV_BIOS_TEMPLATE=dell_r740_g14_uefi_base.xml.template
+SRV_BOOT_TEMPLATE=dell_r740_g14_uefi_httpboot.xml.template
+SRV_HTTP_BOOT_DEV=NIC.Slot.3-1-1
+
+# VLAN to use during build and for final network configuration
+SRV_VLAN=41
+
+# basic network information for dhcp config and final server network settings
+SRV_MTU=9000
+SRV_IP=192.168.2.44
+SRV_SUBNET=192.168.2.0
+SRV_NETMASK=255.255.255.0
+SRV_GATEWAY=192.168.2.200
+SRV_DNS=192.168.2.85
+SRV_DOMAIN=lab.akraino.org
+SRV_DNSSEARCH=lab.akraino.org
+SRV_NTP=ntp.ubuntu.org
+
+# root password for server being built
+SRV_PWD=akraino,d
+
+# network bond information
+SRV_BOND=bond0
+SRV_SLAVE1=enp94s0f0
+SRV_SLAVE2=enp94s0f1
+
diff --git a/setup_tools.sh b/setup_tools.sh
new file mode 100755 (executable)
index 0000000..90bc19f
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/bash
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Script to download tools for build.
+#
+# usage:  ./setup_tools.sh [--help]
+#
+
+# Define Variables
+#
+
+# PROCESS COMMAND LINE ARGUMENTS
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    --help)
+    echo "usage:  ./setup_tools.sh [--help]"
+    exit 0
+    ;;
+    *)    # unknown option
+    POSITIONAL+=("$1") # save it in an array for later
+    shift # past argument
+    ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
+# LOAD BUILD DEFAULT VALUES IF BUILD VARIABLES ARE NOT LOADED
+if [ -z "$REDFISH_ROOT" ]; then
+    BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+    if [ -z "$BASEDIR" ] || ! [ -f "$BASEDIR/buildrc" ]; then
+        echo "ERROR:  Invalid or missing build variables rcfile [$BASEDIR/buildrc]"
+        exit 1
+    fi
+    source "$BASEDIR/buildrc"
+fi
+
+# CHECK A FEW REQUIRED VARIABLES
+if [ -z "$WEB_ROOT" ] || [ -z "$DHCP_ROOT" ] || [ -z "$TOOLS_ROOT" ] || [ -z "$DELL_ROOT" ] || [ -z "$BUILD_ROOT" ]; then
+    echo "ERROR:  Invalid or missing variables in rcfile [$BASEDIR/buildrc]"
+    exit 1
+fi
+
+## MAKE DIRECTORIES
+mkdir -p $WEB_ROOT
+mkdir -p $DHCP_ROOT
+mkdir -p $BUILD_ROOT
+
+## CHECK XORRISO INSTALLED
+if ! dpkg -l | grep xorriso >>/dev/null; then
+    echo "FAILED:  required package xorriso not found.  try sudo 'apt-get install xorriso -y'"
+    exit 1
+fi
+
+## DOWNLOAD TOOLS TO TOOLS_ROOT IF TOOLS FOLDER MISSING
+if [ ! -d "$TOOLS_ROOT" ]; then
+    echo "Cloning latest tools from [$REDFISH_GIT] to [$TOOLS_ROOT]"
+    git clone $REDFISH_GIT $TOOLS_ROOT
+fi
+if [ ! -f "$TOOLS_ROOT/boot.ipxe.template" ]; then
+    echo "ERROR:  failed cloning tools from [$REDFISH_GIT] to [$TOOLS_ROOT]"
+    exit 1
+fi
+
+## DOWNLOAD DELL REDFISH TOOLS_ROOT IF DELL FOLDER MISSING
+if [ ! -d "$DELL_ROOT" ]; then
+    echo "Cloning Dell redfish source from [$DELL_GIT] to [$DELL_ROOT]"
+    git clone $DELL_GIT $DELL_ROOT
+fi
+if [ ! -f "$DELL_ROOT/Redfish Python/ImportSystemConfigurationLocalFilenameREDFISH.py" ]; then
+    echo "ERROR:  failed cloning Dell redfish tools from [$DELL_GIT] to [$DELL_ROOT]"
+    exit 1
+else
+    ## PATCH STATUS REPORTING DELAY TO 15 SECS (INSTEAD OF 3)
+    sed -i -e 's/time.sleep(3)/time.sleep(15)/g' "$DELL_ROOT/Redfish Python/ImportSystemConfigurationLocalFilenameREDFISH.py"
+fi
+
+echo "Tools are ready in [$REDFISH_ROOT]"
+
diff --git a/sources.list b/sources.list
new file mode 100644 (file)
index 0000000..d0a9974
--- /dev/null
@@ -0,0 +1,8 @@
+deb http://archive.ubuntu.com/ubuntu xenial main restricted
+deb http://archive.ubuntu.com/ubuntu xenial-updates main restricted
+deb http://archive.ubuntu.com/ubuntu xenial universe
+deb http://archive.ubuntu.com/ubuntu xenial-updates universe
+deb http://archive.ubuntu.com/ubuntu xenial multiverse
+deb http://archive.ubuntu.com/ubuntu xenial-updates multiverse
+deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse
+
diff --git a/ubuntu.seed.template b/ubuntu.seed.template
new file mode 100644 (file)
index 0000000..fa3ef86
--- /dev/null
@@ -0,0 +1,176 @@
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+### Pre Install
+
+# Command Line 1: This is necessary otherwise you will be prompted to umount /dev/sda. See Ubuntu bug #1347726.
+d-i preseed/early_command string \
+    umount /media || true
+
+### Localization
+
+d-i debian-installer/country string US
+d-i debian-installer/locale string en_US.UTF-8
+d-i debian-installer/language string en
+
+### Keyboard
+
+# Disable automatic (interactive) keymap detection.
+d-i console-setup/ask_detect boolean false
+d-i console-setup/layoutcode string us
+d-i console-setup/variantcode string
+d-i keyboard-configuration/layoutcode string us
+
+### Network configuration - SKIPPED
+#   Install interface and vlan are provided in kernel boot options
+#   Install IP information, name, and domain are provided by dhcp
+#   Final network configuration is done in Post Install to address bonding, etc
+
+### Mirror
+
+d-i mirror/country string manual
+d-i mirror/http/proxy manual
+
+### Clock and Time Zone
+
+# Controls whether to use NTP to set the clock during the install
+d-i clock-setup/ntp boolean true
+d-i clock-setup/ntp-server string @@SRV_NTP@@
+
+# You may set this to any valid setting for $TZ; see the contents of
+# /usr/share/zoneinfo/ for valid values.
+d-i time/zone string UTC
+
+# Controls whether or not the hardware clock is set to UTC.
+d-i clock-setup/utc boolean true
+
+### Partitioning
+
+# If one of the disks that are going to be automatically partitioned
+# contains an old LVM configuration, the user will normally receive a
+# warning. This can be preseeded away...
+d-i partman-lvm/device_remove_lvm boolean true
+
+# The same applies to pre-existing software RAID array:
+d-i partman-md/device_remove_md boolean true
+
+# And the same goes for the confirmation to write the lvm partitions.
+d-i partman-lvm/confirm boolean true
+d-i partman-lvm/confirm_nooverwrite boolean true
+
+d-i partman-auto/method string lvm
+d-i partman-auto/disk string /dev/@@SRV_BOOT_DEVICE@@
+
+# For LVM partitioning, you can select how much of the volume group to use
+d-i partman-auto-lvm/guided_size string max
+
+# You can choose one of the three predefined partitioning recipes:
+# - atomic: all files in one partition
+# - home:   separate /home partition
+# - multi:  separate /home, /var, and /tmp partitions
+d-i partman-auto/choose_recipe select atomic
+
+# This makes partman automatically partition without confirmation.
+d-i partman-md/confirm boolean true
+d-i partman-partitioning/confirm_write_new_label boolean true
+d-i partman/choose_partition select finish
+d-i partman/confirm boolean true
+d-i partman/confirm_nooverwrite boolean true
+d-i partman-efi/non_efi_system boolean true
+
+## Controlling how partitions are mounted
+# The default is to mount by UUID, but you can also choose "traditional" to
+# use traditional device names, or "label" to try filesystem labels before
+# falling back to UUIDs.
+d-i partman/mount_style select traditional
+
+### Packages
+
+# disable APT to autoupdate during iso installation
+d-i apt-setup/use_mirror boolean false
+d-i apt-setup/services-select-ubuntu multiselect ""
+
+# Package selection
+tasksel tasksel/first multiselect standard, server, openssh-server, python-minimal
+
+# Individual additional packages to install
+d-i pkgsel/include string vim git ethtool ntp ifenslave vlan curl \
+    build-essential python open-vm-tools man-db autofs libpam-cracklib \
+    sysstat snmpd snmp tcpdump ntpdate libaio1 lvm2 at gcc
+
+# Whether to upgrade packages after debootstrap.
+# Allowed values: none, safe-upgrade, full-upgrade
+d-i pkgsel/upgrade select none
+
+# Policy for applying updates. May be "none" (no automatic updates)
+d-i pkgsel/update-policy select none
+
+# Some versions of the installer can report back on what software you have
+# installed, and what software you use. The default is not to report back,
+# but sending reports helps the project determine what software is most
+# popular and include it on CDs.
+popularity-contest popularity-contest/participate boolean false
+
+### Users and Password
+
+# Skip creation of a root account (normal user account will be able to
+# use sudo). The default is false; preseed this to true if you want to set
+# a root password.
+d-i passwd/root-login boolean true
+
+# Alternatively, to skip creation of a normal user account.
+d-i passwd/make-user boolean false
+
+# The installer will warn about weak passwords. If you are sure you know
+# what you're doing and want to override it, uncomment this.
+d-i user-setup/allow-password-weak boolean true
+
+# Root password, either in clear text
+d-i passwd/root-password password @@SRV_PWD@@
+d-i passwd/root-password-again password @@SRV_PWD@@
+
+### Bootloader
+
+# This is fairly safe to set, it makes grub install automatically to the MBR
+# if no other operating system is detected on the machine.
+d-i grub-installer/only_debian boolean true
+d-i grub-installer/with_other_os boolean true
+
+### Post Install
+
+# Command Line 1: Allow root to SSH.
+d-i pkgsel/update-policy select none
+d-i finish-install/reboot_in_progress note
+d-i preseed/late_command string \
+    in-target /bin/sed -i 's/^PermitRootLogin .*$/PermitRootLogin yes/g' /etc/ssh/sshd_config; \
+    in-target /bin/sed -i 's/^server /#server /g' /etc/ntp.conf; \
+    in-target /bin/sed -i 's/^pool /#pool /g' /etc/ntp.conf; \
+    in-target /bin/bash -c '/bin/echo "server @@SRV_NTP@@" >> /etc/ntp.conf'; \
+    in-target /bin/bash -c '/bin/echo "8021q" >> /etc/modules'; \
+    in-target /bin/bash -c 'mv /etc/network/interfaces /etc/network/interfaces.save'; \
+    in-target /bin/bash -c 'grep -A2 -B10 "^auto lo" /etc/network/interfaces.save > /etc/network/interfaces'; \
+    in-target /bin/bash -c 'echo -n -e "auto @@SRV_SLAVE1@@\niface @@SRV_SLAVE1@@ inet manual\n    bond-master bond0\n    mtu @@SRV_MTU@@\n\n" >> /etc/network/interfaces'; \
+    in-target /bin/bash -c 'echo -n -e "auto @@SRV_SLAVE2@@\niface @@SRV_SLAVE2@@ inet manual\n    bond-master bond0\n    mtu @@SRV_MTU@@\n\n" >> /etc/network/interfaces'; \
+    in-target /bin/bash -c 'echo -n -e "auto bond0\niface bond0 inet manual\n    bond-mode 4\n" >> /etc/network/interfaces'; \
+    in-target /bin/bash -c 'echo -n -e "    bond-miimon 100\n    bond-slaves @@SRV_SLAVE1@@ @@SRV_SLAVE2@@\n    mtu @@SRV_MTU@@\n\n" >> /etc/network/interfaces'; \
+    in-target /bin/bash -c 'echo -n -e "auto @@SRV_BOND@@.@@SRV_VLAN@@\niface @@SRV_BOND@@.@@SRV_VLAN@@ inet static\n    address @@SRV_IP@@\n    netmask @@SRV_NETMASK@@\n" >> /etc/network/interfaces'; \
+    in-target /bin/bash -c 'echo -n -e "    gateway @@SRV_GATEWAY@@\n    dns-nameservers @@SRV_DNS@@\n    dns-search @@SRV_DNSSEARCH@@\n    vlan-raw-device @@SRV_BOND@@\n    mtu @@SRV_MTU@@\n" >> /etc/network/interfaces'; \
+    in-target /bin/bash -c 'curl http://@@BUILD_WEBIP@@:@@BUILD_WEBPORT@@/sources.list > /etc/apt/sources.list'; \
+    in-target /bin/bash -c 'curl http://@@BUILD_WEBIP@@:@@BUILD_WEBPORT@@/@@SRV_NAME@@.firstboot.sh > /root/@@SRV_NAME@@.firstboot.sh; chmod +x /root/@@SRV_NAME@@.firstboot.sh';
+
+### Finish
+# Reboot after the install is finished.
+d-i finish-install/reboot_in_progress note
+
+
diff --git a/update_webroot.sh b/update_webroot.sh
new file mode 100755 (executable)
index 0000000..ba6ad29
--- /dev/null
@@ -0,0 +1,149 @@
+#!/bin/bash
+#
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Script to update webroot with ubuntu os files.
+#
+# usage:  ./update_webroot.sh [--rc settingsfile] [--iso ubuntu.iso] [--help]
+
+# Define Variables
+#
+UBUNTU_ISO=${UBUNTU_ISO:-}  ## MUST BE PASSED BY USER OR CALLING SCRIPT
+
+# PROCESS COMMAND LINE ARGUMENTS
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    --rc)
+    RCFILE=$2
+    shift # past argument
+    shift # past value
+    ;;
+    --iso)
+    UBUNTU_ISO=$2
+    shift # past argument
+    shift # past value
+    ;;
+    --help)
+    echo "usage:  ./update_webroot.sh [--rc settingsfile] [--iso ubuntu.iso] [--help]"
+    exit 0
+    ;;
+    *)    # unknown option
+    POSITIONAL+=("$1") # save it in an array for later
+    shift # past argument
+    ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
+# SETUP TOOLS AND LOAD DEFAULT BUILD VARIABLES
+BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+. $BASEDIR/setup_tools.sh
+
+# LOAD SERVER VARIABLES IF SERVER RCFILE PROVIDED - OTHERWISE ASSUME THE VARIABLES HAVE BEEN EXPORTED
+if [ -n "$RCFILE" ] && [ -f "$RCFILE" ]; then
+    source $RCFILE
+fi
+
+echo "Checking iso [$UBUNTU_ISO]"
+
+## CHECK IF ISO EXISTS
+if [ -n "$UBUNTU_ISO" ] && [ ! -f $UBUNTU_ISO ]; then 
+    echo "ERROR:  ISO file [$UBUNTU_ISO] does not exists"
+    exit 1
+fi
+
+## CHECK IF ISO IS VALID
+mkdir -p $WEB_ROOT
+if [ -z $UBUNTU_ISO ] || ! xorriso --indev $UBUNTU_ISO --check-media &>/dev/null; then 
+    echo "WARNING:  ISO file [$UBUNTU_ISO] appears to be missing or corrupt.  Downloading instead."
+    xorriso --indev $UBUNTU_ISO --check-media 2>&1 | sed -e "s/^/    /g"
+    export UBUNTU_ISO=${UBUNTU_URL##*/}
+    echo "WARNING:  Attempting to us [$UBUNTU_ISO] instead."
+    if ! [ -f $WEB_ROOT/$UBUNTU_ISO ]; then 
+        echo "Downloading Ubuntu iso from [$UBUNTU_URL] to [$UBUNTU_ISO]"
+        curl -Lo $WEB_ROOT/$UBUNTU_ISO $UBUNTU_URL
+    else
+        echo "Ubuntu iso [$UBUNTU_ISO] already exists in [$WEB_ROOT]"
+    fi
+else
+    cp $UBUNTU_ISO $WEB_ROOT/${UBUNTU_ISO##*/}
+fi
+UBUNTU_ISO=$WEB_ROOT/${UBUNTU_ISO##*/}
+
+echo "Updating web root folder [$WEB_ROOT] with ubuntu iso [$UBUNTU_ISO] contents"
+## CHECK AGAIN IF ISO EXISTS/IS ISO FORMAT
+if [ ! -f $UBUNTU_ISO ] || ! xorriso --indev $UBUNTU_ISO --check-media &>/dev/null; then 
+    echo "ERROR:  ISO file [$UBUNTU_ISO] does not exists or is corrupt"
+    xorriso --indev $UBUNTU_ISO --check-media | sed -e "s/^/    /g"
+    exit 1
+fi
+
+## EXTRACT README.diskdefines
+xorriso -osirrox on -indev $UBUNTU_ISO -extract /README.diskdefines $UBUNTU_ISO.README.diskdefines &>/dev/null
+
+## GET ISO VERSION/ARCH
+ISO_VERSION=$(grep -oh "[0-9]*\.[0-9]*\.[0-9]*" $UBUNTU_ISO.README.diskdefines)
+ISO_ARCH=$(grep "#define ARCH " $UBUNTU_ISO.README.diskdefines | awk '{print $3}')
+if [ -z "$ISO_VERSION" ] || [ -z "$ISO_ARCH" ]; then
+    echo "FAILED:  Unable to determine version [$ISO_VERSION] or arch [$ISO_ARCH] from iso [$UBUNTU_ISO]"
+    exit 1
+fi
+echo "Found ubuntu version [ISO_VERSION] arch [$ISO_ARCH]"
+rm -f $UBUNTU_ISO.README.diskdefines
+
+## CREATE ROOT FOLDER
+UBUNTU_ROOT=ubuntu-$ISO_VERSION-$ISO_ARCH
+UBUNTU_FOLDER=$WEB_ROOT/$UBUNTU_ROOT
+mkdir -p $UBUNTU_FOLDER
+
+## COPY FILES
+echo "Extracting files to [$WEB_ROOT]"
+cp -f $TOOLS_ROOT/sources.list $WEB_ROOT
+xorriso -osirrox on:auto_chmod_on -indev $UBUNTU_ISO -find / -type d -exec chmod u+rwx -- -extract / $UBUNTU_FOLDER -rollback_end 2>&1 | sed -e "s/^/    /g"
+
+## EXPAND KERNEL AND INITRD (HWE AND STANDARD)
+HWE_OIMAGE=linux-generic-hwe-${ISO_VERSION%.*}
+HWE_KERNEL=linux-hwe-$ISO_VERSION-$ISO_ARCH
+HWE_INITRD=initrd-hwe-$ISO_VERSION-$ISO_ARCH
+cp -f $UBUNTU_FOLDER/install/hwe-netboot/ubuntu-installer/$ISO_ARCH/linux $WEB_ROOT/$HWE_KERNEL
+gunzip -c $UBUNTU_FOLDER/install/hwe-netboot/ubuntu-installer/$ISO_ARCH/initrd.gz > $WEB_ROOT/$HWE_INITRD
+
+STD_OIMAGE=linux-generic-${ISO_VERSION%.*}
+STD_KERNEL=linux-$ISO_VERSION-$ISO_ARCH
+STD_INITRD=initrd-$ISO_VERSION-$ISO_ARCH
+cp -f $UBUNTU_FOLDER/install/netboot/ubuntu-installer/$ISO_ARCH/linux $WEB_ROOT/$STD_KERNEL
+gunzip -c $UBUNTU_FOLDER/install/netboot/ubuntu-installer/$ISO_ARCH/initrd.gz > $WEB_ROOT/$STD_INITRD
+
+## CREATE SCRIPT-ISO_VERSION-ISO_ARCH.IPXE FILE
+sed -e "s|@@KERNEL@@|$HWE_KERNEL|g" \
+    -e "s|@@INITRD@@|$HWE_INITRD|g" \
+    -e "s|@@BASE_KERNEL@@|$HWE_OIMAGE|g" \
+    -e "s|@@UBUNTU_ROOT@@|$UBUNTU_ROOT|g" \
+    $TOOLS_ROOT/script.ipxe.template > $WEB_ROOT/script-hwe-$ISO_VERSION-$ISO_ARCH.ipxe
+
+sed -e "s|@@KERNEL@@|$STD_KERNEL|g" \
+    -e "s|@@INITRD@@|$STD_INITRD|g" \
+    -e "s|@@BASE_KERNEL@@|$STD_OIMAGE|g" \
+    -e "s|@@UBUNTU_ROOT@@|$UBUNTU_ROOT|g" \
+    $TOOLS_ROOT/script.ipxe.template > $WEB_ROOT/script-$ISO_VERSION-$ISO_ARCH.ipxe
+
+echo "Files for Ubuntu version [$ISO_VERSION] [$ISO_ARCH] are ready in folder [$WEB_ROOT]"
+echo "Use script-hwe-$ISO_VERSION-$ISO_ARCH.ipxe or script-$ISO_VERSION-$ISO_ARCH.ipxe in the dhcp config depending on the kernel version required."
+