Skip to content

Commit

Permalink
Create symlink /etc/HOSTNAME to avoid backward compatibility issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Jun 4, 2014
1 parent 311d55b commit c6c1ef3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/clients/save_network.rb
Expand Up @@ -262,6 +262,8 @@ def configure_target

LanUdevAuto.Write if Mode.autoinst

DNS.create_hostname_link

SCR.Execute(path(".target.bash"), "chkconfig network on")

# if portmap running - start it after reboot
Expand Down
45 changes: 40 additions & 5 deletions src/modules/DNS.rb
Expand Up @@ -34,6 +34,8 @@
module Yast
class DNSClass < Module

include Logger

HOSTNAME_FILE = "hostname"
HOSTNAME_PATH = "/etc/" + HOSTNAME_FILE

Expand Down Expand Up @@ -234,11 +236,8 @@ def ReadHostname
fqhostname = read_hostname_from_install_inf
end

if fqhostname.empty? && FileUtils.Exists(HOSTNAME_PATH)
fqhostname = SCR.Read(path(".target.string"), HOSTNAME_PATH)
#avoid passing nil argument when we get non-\n-terminated string (#445531)
fqhostname = String.FirstChunk(fqhostname, "\n")
Builtins.y2milestone("Got #{fqhostname} from #{HOSTNAME_PATH}")
if fqhostname.empty?
fqhostname = read_hostname_from_etc
end

split = Hostname.SplitFQ(fqhostname)
Expand Down Expand Up @@ -397,6 +396,9 @@ def Write
HOSTNAME_PATH,
Ops.add(fqhostname, "\n")
)

create_hostname_link

Builtins.sleep(sl)

# Progress step 2/3
Expand Down Expand Up @@ -645,6 +647,20 @@ def IsHostLocal(check_host)
false
end

# Creates symlink /etc/HOSTNAME -> /etc/hostname to gurantee backward compatibility
# after changes in bnc#858908
def create_hostname_link
link_name = "/etc/HOSTNAME"
return if FileUtils.IsLink(link_name)

log.info "Creating #{link_name} symlink"

SCR.Execute(path(".target.bash"), "rm #{link_name}") if FileUtils.Exists(link_name)
SCR.Execute(path(".target.bash"), "ln -s #{DNSClass::HOSTNAME_PATH} #{link_name}")

nil
end

private
def read_hostname_from_install_inf
install_inf_hostname = SCR.Read(path(".etc.install_inf.Hostname")) || ""
Expand All @@ -667,6 +683,25 @@ def read_hostname_from_install_inf
return fqhostname
end

def read_hostname_from_etc
if FileUtils.Exists(HOSTNAME_PATH)
hostname_path = HOSTNAME_PATH
elsif FileUtils.Exists("/etc/HOSTNAME")
# backward compatibility due to changes done in bnc#858908
hostname_path = "/etc/HOSTNAME"
else
return ""
end

fqhostname = SCR.Read(path(".target.string"), hostname_path) || ""

#avoid passing nil argument when we get non-\n-terminated string (#445531)
fqhostname = String.FirstChunk(fqhostname, "\n")
log.info("Read #{fqhostname} from '/etc/'")

return fqhostname
end

publish :variable => :proposal_valid, :type => "boolean"
publish :variable => :hostname, :type => "string"
publish :variable => :domain, :type => "string"
Expand Down

0 comments on commit c6c1ef3

Please sign in to comment.