diff options
author | Jonathan Bauer | 2020-10-05 16:30:26 +0200 |
---|---|---|
committer | Jonathan Bauer | 2020-10-05 16:30:26 +0200 |
commit | d8162a8c56e2f1d2f32916ee55be7c718beac862 (patch) | |
tree | 1a7dfc42dd31b07ea67f11f362cb6cd2dfdd02bd /core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx | |
parent | [dhcpc-busybox] do not handle hostname in stage4 (diff) | |
download | mltk-d8162a8c56e2f1d2f32916ee55be7c718beac862.tar.gz mltk-d8162a8c56e2f1d2f32916ee55be7c718beac862.tar.xz mltk-d8162a8c56e2f1d2f32916ee55be7c718beac862.zip |
[dhcpc-busybox] reintroduce /etc/hosts handling
Diffstat (limited to 'core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx')
-rwxr-xr-x | core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx index 8bface1b..1b4dbc98 100755 --- a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx +++ b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx @@ -155,7 +155,9 @@ case "$1" in rebuild_resolv_conf fi - + # NOTE: The udev rule triggering our network setup is changed in *installer* + # to only trigger this script on additional interfaces bridges. Keeping the code + # here for now and for easier merging... # Things that should only happen for the main interface that was used for booting if [ "$interface" = "$primary" ]; then # Update IP, TODO: check if we really want/need to overwrite the PXE_IP, @@ -188,7 +190,27 @@ case "$1" in done fi fi # end "primary only" - + + # Hostname in /etc/hosts + touch "/etc/hosts" + hostlist="" + [ -n "$dns_fqdn" ] && hostlist="$dns_fqdn" + [ -n "$hostname" ] && [ -n "$domain" ] && [ "x${hostname}.${domain}" != "x$dns_fqdn" ] && hostlist="$hostlist ${hostname}.${domain}" + if [ -n "$hostlist" ]; then + for host in $hostlist; do + host_short="${host%%.*}" + [ "x$host_short" = "x$host" ] && host_short="" + sed -i -r "s/\s$(escape_search "$host")(\s|$)/ /g" /etc/hosts + [ -n "$host_short" ] && sed -i -r "s/\s$(escape_search "$host_short")(\s|$)/ /g" /etc/hosts + if grep -q -E "^$ip\s" /etc/hosts; then + sed -i "s/^$(escape_search "$ip")\s.*/$(escape_replace "$ip $host $host_short")/g" /etc/hosts + else + echo "$ip $host $host_short" >> /etc/hosts + fi + done + fi + # Get rid of orphaned lines in /etc/hosts + sed -i -r '/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s*$/d' /etc/hosts # Write to openslx-config echo "# Config written by openslx-dhcp-script (2)" >> /opt/openslx/config sed -i "/^SLX_DNS=/d" /opt/openslx/config |