The current implementation will overwrity any previously set hostname ( kernel / dhcp ) by either the contents of /etc/hostname or ${HOSTNAME} (which is set in /etc/conf.d/hostname, I assume) This patch will check if the hostname has already been set and ignore any local configuration shoud that be the case. In effect you will only be able to run the script once. I hope this does not raise any problems, does it?
Created attachment 79758 [details, diff] now in correct order
your patch is reversed
Comment on attachment 79758 [details, diff] now in correct order --- hostname.org 2006-02-14 15:09:56.000000000 +0100 +++ hostname 2006-02-14 15:38:07.000000000 +0100 @@ -10,17 +10,16 @@ local myhost=$(/bin/hostname 2>/dev/null) local retval=0 - # If the hostname is already set via the kernel, and /etc/hostname - # isn't setup, then we shouldn't go reseting the configuration #38172. + # If the hostname is NOT set already (e.g. via the kernel), + # reset the configuration #38172. if [[ -z ${myhost} ]] || [[ ${myhost} == "(none)" ]] ; then - myhost="localhost" - fi - - if [[ -f /etc/hostname ]] ; then - ewarn "You should stop using /etc/hostname and use /etc/conf.d/hostname" - myhost=$(</etc/hostname) - else - myhost=${HOSTNAME} + # Warn if the old /etc/hostname is still set + if [[ -f /etc/hostname ]] ; then + ewarn "You should stop using /etc/hostname and use /etc/conf.d/hostname" + myhost=$(</etc/hostname) + else + myhost=${HOSTNAME} + fi fi ebegin "Setting hostname to ${myhost}"
Comment on attachment 79758 [details, diff] now in correct order err, please just post a new one
Created attachment 79782 [details, diff] new to this ... gotta learn ;)
ok, now that i see the patch, current behavior is intended if you dont want to reset the configuration, dont setup /etc/hostname and/or /etc/conf.d/hostname
(In reply to comment #6) > if you dont want to reset the configuration, dont setup /etc/hostname and/or > /etc/conf.d/hostname I do not have the file /etc/hostname, so the current script will set myhost to ${HOSTNAME} in the else statement. When /etc/conf.d/hostname contains a line like: HOSTNAME= or HOSTNAME="" or #HOSTNAME= The myhost variable will be overwritten and the hostname WILL be set to an empty string (/bin/hostname "${myhost}"). This means that the the configuration will always be overwritten ... Where am I wrong?
ok ... so I moved /etc/conf.d/hostname to somewhere else, now HOSTNAME is set to the hostname given by dhcp. The behaviour is somewhat unintuitive, as the /etc/conf.d/hostname will be recreated everytime the baselayout gets updated ... thus people think this file must exist ... maybe an OVERRIDE option like in /etc/conf.d/domainname would be more consistent? Tell me if I should submit a patch that works like that.
comment out HOSTNAME in your /etc/conf.d/hostname file i'll update the default
Roy: how does the net scripts in baselayout-1.12.x+ handle this ? i know we merged the domain name funk ...
We only set hostname in our net scripts from DHCP client setup like so # Configure our hostname - but only if we need it if [[ -n ${hostname} ]]; then x="$( hostname )" [[ ${x} == "(none)" || ${x} == "localhost" ]] && hostname "${hostname}" fi So if the DHCP client does not set hostname then we don't change it. Also we only change it if the hostname is not set regardless of what the DHCP client wants.
Fixed in baselayout-1.12.0_pre17