diff options
author | David Cantrell <dcantrell@redhat.com> | 2008-09-29 08:26:52 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2008-09-29 08:26:52 -1000 |
commit | 9b8bff03fb2c3ee70da6cd8e234fb5289c839f06 (patch) | |
tree | 483b93a160b0f336ca1506903e7215fda5822410 /network.py | |
parent | 61fd2ec47555cedbf012cce7a11a0371166fc43d (diff) | |
download | anaconda-9b8bff03fb2c3ee70da6cd8e234fb5289c839f06.tar.gz anaconda-9b8bff03fb2c3ee70da6cd8e234fb5289c839f06.tar.xz anaconda-9b8bff03fb2c3ee70da6cd8e234fb5289c839f06.zip |
Allow users to enter a hostname or FQDN during installation (#464191)
Set up /etc/hosts correctly if the user enters a hostname or an FQDN
in the hostname screen in anaconda. This avoids name resolution
problems when starting sendmail.
Patch from Thomas Woerner <twoerner AT redhat DOT com>.
Diffstat (limited to 'network.py')
-rw-r--r-- | network.py | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/network.py b/network.py index 3a7010d9d..d3ab6345e 100644 --- a/network.py +++ b/network.py @@ -536,43 +536,56 @@ class Network: # /etc/hosts f = open(instPath + "/etc/hosts", "w") - localline = "" log.info("self.hostname = %s", self.hostname) + # IP address ip = self.lookupHostname() - l = string.split(self.hostname, ".") + if ip in [ "127.0.0.1", "::1" ]: + ip = None - # If the hostname is not resolvable, tie it to 127.0.0.1 - if not ip and self.hostname != "localhost.localdomain": - localline += self.hostname + " " - if len(l) > 1: - localline += l[0] + " " - - # always add the short hostname to 127.0.0.1 (#253979) - localline += "localhost.localdomain localhost" - if len(l) > 1: - localline += " " + l[0] + # fqdn and hostname + if "." in hostname: + fqdn = self.hostname + hostname = hostname.split('.', 1)[0] + else: + fqdn = socket.getfqdn(self.hostname) + hostname = self.hostname + if fqdn in [ "localhost.localdomain", "localhost", + "localhost6.localdomain6", "localhost6" ]: + fqdn = None + + # domainname + domainname = fqdn[(fqdn.find('.') + 1):] + if domainname in [ "localdomain", "localdomain6" ]: + domainname = None + + localline = "localhost.localdomain localhost" + if not ip or not fqdn: + # There is no ip or no fqdn, tie it to 127.0.0.1. + if fqdn: + # add fqdn to 127.0.0.1 + localline += " " + fqdn + if hostname and hostname != "localhost": + # add short hostname to 127.0.0.1 + localline += " " + hostname f.write("# Do not remove the following line, or various programs\n") f.write("# that require network functionality will fail.\n") f.write("127.0.0.1\t\t" + localline + "\n") f.write("::1\t\tlocalhost6.localdomain6 localhost6\n") - if ip: - nameline = "%s\t\t%s" % (ip, self.hostname) - n = string.split(self.hostname, ".") - if len(n) > 1: - nameline = nameline + " " + n[0] - f.write("%s\n" %(nameline,)) + if ip and fqdn: + # Add an extra entry for ip, fqdn and hostname + f.write("%s\t\t%s %s\n" % (ip, fqdn, hostname)) + + f.close() # If the hostname was not looked up, but typed in by the user, # domain might not be computed, so do it now. if self.domains == ["localdomain"] or not self.domains: - if '.' in self.hostname: - # chop off everything before the leading '.' - domain = self.hostname[(string.find(self.hostname, '.') + 1):] - self.domains = [domain] + if domainname: + self.domains = [domainname] # /etc/resolv.conf f = open(instPath + "/etc/resolv.conf", "w") |