diff --git a/content/bootenvs/discovery.yml b/content/bootenvs/discovery.yml index dc97010d..320865c5 100644 --- a/content/bootenvs/discovery.yml +++ b/content/bootenvs/discovery.yml @@ -51,20 +51,7 @@ Templates: Path: "machines/start-up.sh" Contents: | #!/bin/bash - - export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ' export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin - set -x - set -e - shopt -s extglob - - get_param() { - [[ $(cat /proc/cmdline) =~ $1 ]] && echo "${BASH_REMATCH[1]}" - } - - dhcp_param() { - [[ $(cat /var/lib/dhclient/dhclient.leases) =~ $1 ]] && echo "${BASH_REMATCH[1]}" - } get_macs() { local maclist="" @@ -76,9 +63,19 @@ Templates: printf '[%s]' "${maclist#,}" } + if [[ ! -f /etc/systemd/network/20-bootif.network ]]; then + get_param() { + [[ $(cat /proc/cmdline) =~ $1 ]] && echo "${BASH_REMATCH[1]}" + } + + dhcp_param() { + [[ $(cat /var/lib/dhclient/dhclient.leases) =~ $1 ]] && echo "${BASH_REMATCH[1]}" + } + + # Since we are not using normal networking, make sure that # dhclient will stick around forever even if we exit - cat >"/etc/systemd/system/dhclient-$BOOTDEV.service" << EOF + cat >"/etc/systemd/system/dhclient-$BOOTDEV.service" << EOF [Unit] Description=dhclient for $BOOTDEV.service After=network-online.target @@ -92,38 +89,39 @@ Templates: WantedBy=multi-user.target EOF - systemctl daemon-reload - dhclient -x - systemctl start "dhclient-$BOOTDEV" - sleep 5 - - # Stuff from sledgehammer file that makes this command debuggable - # Some useful boot parameter matches - ip_re='([0-9a-f.:]+/[0-9]+)' - host_re='rs\.uuid=([^ ]+)' - hostname_re='option host-name "([^"]+)' - fixed_ip='fixed-address ([0-9a-f.:]+)' - uuid_re='^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$' - netname_re='"network":"([^ ]+)"' - - # Assume nothing about the hostname. - unset HOSTNAME - - # Check for DHCP set host name. Expand it to a FQDN if needed. - if dhcp_hostname="$(dhcp_param "$hostname_re")"; then - echo "Hostname set by DHCP to $dhcp_hostname" - if [[ ${dhcp_hostname%%.*} == $dhcp_hostname ]]; then - HOSTNAME="${dhcp_hostname}.${DOMAIN}" + systemctl daemon-reload + dhclient -x + systemctl start "dhclient-$BOOTDEV" + sleep 5 + + # Stuff from sledgehammer file that makes this command debuggable + # Some useful boot parameter matches + ip_re='([0-9a-f.:]+/[0-9]+)' + host_re='rs\.uuid=([^ ]+)' + hostname_re='option host-name "([^"]+)' + fixed_ip='fixed-address ([0-9a-f.:]+)' + uuid_re='^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$' + netname_re='"network":"([^ ]+)"' + + # Assume nothing about the hostname. + unset HOSTNAME + + # Check for DHCP set host name. Expand it to a FQDN if needed. + if dhcp_hostname="$(dhcp_param "$hostname_re")"; then + echo "Hostname set by DHCP to $dhcp_hostname" + if [[ ${dhcp_hostname%%.*} == $dhcp_hostname ]]; then + HOSTNAME="${dhcp_hostname}.${DOMAIN}" + else + HOSTNAME="$dhcp_hostname" + fi else - HOSTNAME="$dhcp_hostname" - fi - else - dhcp_ip="$(dhcp_param "$fixed_ip")" - if [[ $dhcp_ip != "" ]] ; then - lookup_1=$(getent hosts $dhcp_ip | awk '{print $2}') - lookup_2=$(getent hosts $dhcp_ip | awk '{print $2}') - if [[ $lookup_1 && $lookup_1 == $lookup_2 && $lookup_1 != localhost* ]]; then - HOSTNAME=$lookup_1 + dhcp_ip="$(dhcp_param "$fixed_ip")" + if [[ $dhcp_ip != "" ]] ; then + lookup_1=$(getent hosts $dhcp_ip | awk '{print $2}') + lookup_2=$(getent hosts $dhcp_ip | awk '{print $2}') + if [[ $lookup_1 && $lookup_1 == $lookup_2 && $lookup_1 != localhost* ]]; then + HOSTNAME=$lookup_1 + fi fi fi fi