summaryrefslogtreecommitdiffstats
path: root/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh
diff options
context:
space:
mode:
Diffstat (limited to 'modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh')
-rw-r--r--modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh64
1 files changed, 64 insertions, 0 deletions
diff --git a/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh b/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh
new file mode 100644
index 00000000..b9803729
--- /dev/null
+++ b/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+#
+# This hook creates a networkd configuration for the NEWROOT
+# * DHCP configuration for the boot interface
+# * Set static hostname via /etc/hostname
+# This uses the configuration file generated by the parse-kcl-for-networkd.sh
+# hook Note: on systemd v219, UseDomains is bugged and does not seem to do
+# anything thus that option is complemented with the KCL's domain to hopefully
+# garantee one of these will take effect.
+
+. "/run/openslx/network.conf"
+
+NETWORKD_DIR="/etc/systemd/network"
+mkdir -p "${NEWROOT}/${NETWORKD_DIR}"
+
+# First, copy over every configuration made so far,
+# excluding the physical interface if bridged
+cp "${NETWORKD_DIR}/${SLX_BRIDGE}"* "${NEWROOT}/${NETWORKD_DIR}"
+
+# Now determine which network configuration we are running
+# VLANs are already configured to DHCP, so nothing to do
+if [ -z "${SLX_VLAN_ID}" ]; then
+ # In both bridged and non-bridged mode, we need to adjust
+ # the configuration to DHCP for stage4
+ MATCH_LINE=
+ MATCH_LINE_EXTRA=
+ MAIN_NET_CONF=
+ if [ -n "${SLX_BRIDGE}" ]; then
+ MATCH_LINE="Name=${SLX_BRIDGE}"
+ MAIN_NETIF_CONF="${NETWORKD_DIR}/${SLX_BRIDGE}.network"
+ elif [ -n "${SLX_PXE_MAC}" ]; then
+ MATCH_LINE="MACAddress=${SLX_PXE_MAC}"
+ MATCH_LINE_EXTRA="Path=pci*"
+ MAIN_NETIF_CONF="${NETWORKD_DIR}/${SLX_PXE_NETIF}.network"
+ else
+ emergency_shell "Could not determine network configuration mode!"
+ fi
+ # backup current network config for later reference before overwritting it
+ if [ -e "${MAIN_NETIF_CONF}" ]; then
+ mv "${NEWROOT}/${MAIN_NETIF_CONF}" "${NEWROOT}/${MAIN_NETIF_CONF}.stage3"
+ else
+ emergency_shell "Failed to find main networkd configuration: ${MAIN_NETIF_CONF}"
+ fi
+ # Now generate a DHCP configuration for the main interface
+ cat <<-EOF > "${NEWROOT}/${MAIN_NETIF_CONF}"
+ [Match]
+ ${MATCH_LINE}
+ ${MATCH_LINE_EXTRA}
+
+ [Network]
+ DHCP=ipv4
+ LinkLocalAddressing=no
+ IPv6AcceptRA=no
+
+ [DHCP]
+ UseDNS=true
+ UseDomains=true
+ UseHostname=true
+ CriticalConnection=true
+ EOF
+fi
+
+# Workaround: UseHostname seems broken, so manually set the hostname for now...
+[ -n "${SLX_HOSTNAME}" ] && echo "${SLX_HOSTNAME}" > $NEWROOT/etc/hostname