diff options
author | Simon Rettberg | 2022-05-23 15:19:05 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-05-23 15:19:30 +0200 |
commit | 2166aa15ea56fa627bbe6bd020fc2fc1335a481c (patch) | |
tree | c3a0fd22ffe464b4b726356ad5af16a9df0caa2d | |
parent | config(.tgz): Increase retry timeout to 20 seconds, use --slx-time (diff) | |
download | systemd-init-2166aa15ea56fa627bbe6bd020fc2fc1335a481c.tar.gz systemd-init-2166aa15ea56fa627bbe6bd020fc2fc1335a481c.tar.xz systemd-init-2166aa15ea56fa627bbe6bd020fc2fc1335a481c.zip |
Merge DNS search list from DHCP and config server (SLX_NET_SEARCH)
3 files changed, 35 insertions, 6 deletions
diff --git a/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh b/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh index 1d601a22..7e2b74e3 100755 --- a/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh +++ b/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh @@ -1,8 +1,31 @@ #!/usr/bin/env bash # -*- coding: utf-8 -*- type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh + source "/etc/openslx" +# Merge search domain from server and from dhcp +( + search="$SLX_NET_SEARCH" + source /run/openslx/network.conf + search="$SLX_NET_SEARCH $search" # DHCP > config vars + declare -a uniq + declare -A dups # Don't use keys for output later as order is undefined + for i in $search; do + [ -n "${dups["$i"]}" ] && continue + dups["$i"]=1 + uniq+=( "$i" ) + done + sed -i 's/^SLX_NET_SEARCH=/# &/' "/etc/openslx" "/run/openslx/network.conf" + echo "SLX_NET_SEARCH='${uniq[*]}'" >> "/run/openslx/network.conf" + if grep -q '^search' "/etc/resolv.conf"; then + sed -i "s/^search.*$/search ${uniq[*]}/" "/etc/resolv.conf" + else + echo "search ${uniq[*]}" "/etc/resolv.conf" + fi +) + + mkdir --parents "${NEWROOT}/opt/openslx" cp "/etc/openslx" "${NEWROOT}/opt/openslx/config" diff --git a/modules.d/slx-network/hooks/copy-network-files.sh b/modules.d/slx-network/hooks/copy-network-files.sh index d1dd48d1..5d28669e 100644 --- a/modules.d/slx-network/hooks/copy-network-files.sh +++ b/modules.d/slx-network/hooks/copy-network-files.sh @@ -6,13 +6,13 @@ if [ -n "$NEWROOT" ]; then # backup network configuration files found in stage4 for file in /etc/{hostname,hosts,resolv.conf}; do if [ ! -e "$file" ]; then - warn "Missing '$file' - won't move it to stage4. " + warn "Missing '$file' - can't move it to stage4. " continue fi if [ -e "${NEWROOT}/${file}" ] || [ -h "${NEWROOT}/${file}" ]; then - mv "${NEWROOT}/${file}" "${NEWROOT}/${file}.stage4" + mv "${NEWROOT}/${file}" "${NEWROOT}/${file}.renamed-by-stage3" fi - cp -af "$file" "${NEWROOT}/etc" + cp -af "$file" "${NEWROOT}/etc/" done # special handling for resolv.conf: # move it to /opt/openslx to detect we are managing it diff --git a/modules.d/slx-network/scripts/udhcpc-trigger.stage3 b/modules.d/slx-network/scripts/udhcpc-trigger.stage3 index 5833c0b4..82a21f6f 100755 --- a/modules.d/slx-network/scripts/udhcpc-trigger.stage3 +++ b/modules.d/slx-network/scripts/udhcpc-trigger.stage3 @@ -84,6 +84,12 @@ done # always check DNS echo "Checking DNS record for this host..." [ -z "$fqdn" ] && fqdn="$(reverse_lookup "$ip")" +[ -z "$fqdn" ] && [ -n "$hostname" ] && [ -n "$domain" ] && fqdn="${hostname}.${domain}" +# Otherwise, retry DNS one time +if [ -z "$fqdn" ]; then + sleep 1 + fqdn="$(reverse_lookup "$ip")" +fi [ -n "$fqdn" ] && fqdn_hostname="${fqdn%%.*}" if [ -z "$domain" ]; then @@ -105,16 +111,16 @@ fi # Write out if [ -n "$domain" ]; then echo "domain $domain" >> "/etc/resolv.conf" - echo "SLX_NET_DOMAIN='$domain'" >> "/run/openslx/network.conf" + echo "SLX_NET_DOMAIN='$domain'" >> "$NETWORK_CONF" fi if [ -n "$search" ]; then echo "search $search" >> "/etc/resolv.conf" - echo "SLX_NET_SEARCH='$search'" >> "/run/openslx/network.conf" + echo "SLX_NET_SEARCH='$search'" >> "$NETWORK_CONF" fi if [ -n "$ntpsrv" ]; then - echo "SLX_DHCP_NTP='$ntpsrv'" >> "/run/openslx/network.conf" + echo "SLX_DHCP_NTP='$ntpsrv'" >> "$NETWORK_CONF" fi # Hostname |