From b971eea3b1c467b5620993b5a40c90e0cac7d6b6 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 24 Mar 2014 18:35:09 +0100 Subject: [dhcpc-busybox] fix bad hostname setting logic fixed multiple interfaces support. --- .../data/opt/openslx/scripts/udhcpc-openslx | 55 +++++++++++++--------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'remote') diff --git a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx index 2675afc2..cf140246 100755 --- a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx +++ b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx @@ -73,12 +73,25 @@ case "$1" in ip route add default via "$router" fi + # get domain, hostname and thus fqdn from DNS + dns_fqdn=$(rdns "$ip") + dns_short="${dns_fqdn%%.*}" + # check if it is fqdn + if [ "$dns_fqdn" == "$dns_short" ]; then + unset dns_fqdn dns_short + fi + # Update resolver configuration file CONF="" if [ -n "$domain" ]; then printf -v CONF "${CONF}domain $domain\n" + elif [ -n "$dns_fqdn" ]; then + domain="${dns_fqdn#*.}" + printf -v CONF "${CONF}domain $domain\n" + elif [ -n "$SLX_NET_DOMAIN" ]; then - printf -v CONF "${CONF}domain $SLX_NET_DOMAIN\n" + domain="$SLX_NET_DOMAIN" + printf -v CONF "${CONF}domain $domain\n" fi if [ -n "$search" ]; then printf -v CONF "${CONF}search $search\n" @@ -102,34 +115,34 @@ case "$1" in echo -n "$CONF" > "$THIS_RESOLV" rebuild_resolv_conf fi + # Things that should only happen for the main interface that was used for booting if [ "$interface" == "br0" ]; then - dns_host=$(rdns "$ip") - short="${dns_host%%.*}" # Update IP sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config # Only if network is not ready yet if [ ! -e "/run/network/network-ready" ]; then # Update hostname - if [ -z "$dns_host" ]; then + if [ -z "$dns_fqdn" -a -n "$domain" -a -n "$hostname" ]; then # fallback to what the dhcp told us - dns_host="$hostname" + dns_fqdn="${hostname}.${domain}" fi - if [ -z "$dns_host" ]; then + if [ -z "$dns_fqdn" ]; then # only if there is no /etc/hostname, we fall back (far back, that is) - [ ! -s "/etc/hostname" ] && dns_host="slx-client" + [ ! -s "/etc/hostname" ] && dns_fqdn="slx-client" fi - # finally, if dns_host was set to anything, apply it - if [ -n "$dns_host" ]; then - echo "$short" > "/proc/sys/kernel/hostname" - echo "$short" > "/etc/hostname" + # finally, if dns_fqdn was set to anything, apply it + if [ -n "$dns_fqdn" ]; then + dns_short="${dns_fqdn%%.*}" + echo "$dns_short" > "/proc/sys/kernel/hostname" + echo "$dns_short" > "/etc/hostname" if grep '^SLX_HOSTNAME=' /opt/openslx/config 2>/dev/null; then - sed -i "s/^\(SLX_HOSTNAME=\).*$/\1'$dns_host'/" /opt/openslx/config + sed -i "s/^\(SLX_HOSTNAME=\).*$/\1'$dns_short'/" /opt/openslx/config else echo "# Config written by openslx-dhcp-script (1)" >> /opt/openslx/config - echo "SLX_HOSTNAME='$dns_host'" >> /opt/openslx/config + echo "SLX_HOSTNAME='$dns_short'" >> /opt/openslx/config fi fi @@ -154,18 +167,18 @@ case "$1" in # Hostname in /etc/hosts touch "/etc/hosts" hostlist="" - [ -n "$dns_host" ] && hostlist="$dns_host" - [ -n "$hostname" -a "x$hostname" != "x$dns_host" ] && hostlist="$hostlist $hostname" + [ -n "$dns_fqdn" ] && hostlist="$dns_fqdn" + [ -n "$hostname" -a -n "$domain" -a "x${hostname}.${domain}" != "x$dns_fqdn" ] && hostlist="$hostlist ${hostname}.${domain}" if [ -n "$hostlist" ]; then for host in $hostlist; do - short="${host%%.*}" - [ "x$short" = "x$host" ] && short="" + host_short="${host%%.*}" + [ "x$host_short" = "x$host" ] && host_short="" sed -i -r "s/\s$(escape_search "$host")(\s|$)/ /g" /etc/hosts - [ -n "$short" ] && sed -i -r "s/\s$(escape_search "$short")(\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 $short ")/g" /etc/hosts + sed -i "s/^$(escape_search "$ip")\s.*/$(escape_replace "$ip $host $host_short")/g" /etc/hosts else - echo "$ip $host $short" >> /etc/hosts + echo "$ip $host $host_short" >> /etc/hosts fi done fi @@ -201,6 +214,7 @@ case "$1" in echo 1 > "/proc/sys/net/ipv4/conf/$interface/promote_secondaries" clientip=${ip%%:*} ip addr del "$clientip/$(ipcalc -s -p $clientip $subnet|sed s/.*=//)" dev "$interface" + sed -i "/^$(escape_search "$ip")(\s|$)/d" /etc/hosts else echo "NFS is active, not removing old ip adress. warning: lease may expire after a while." fi @@ -213,7 +227,6 @@ case "$1" in rm -f -- "$THIS_RESOLV" rebuild_resolv_conf fi - ;; leasefail) -- cgit v1.2.3-55-g7522