diff options
| author | Joey Hess <joey@kitenet.net> | 2014-04-03 23:57:36 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-04-03 23:57:36 -0400 |
| commit | 7932c5abec925bfd0240b62290e00977141419e7 (patch) | |
| tree | 1a0145c777839b8f966cb640f5cba3e4d77d5ff3 /Propellor | |
| parent | fbc57d684509180f518c84469c45e2d85bb20708 (diff) | |
propellor spin
Diffstat (limited to 'Propellor')
| -rw-r--r-- | Propellor/Property/Hostname.hs | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/Propellor/Property/Hostname.hs b/Propellor/Property/Hostname.hs index a2e3c7c6..44a3b111 100644 --- a/Propellor/Property/Hostname.hs +++ b/Propellor/Property/Hostname.hs @@ -3,12 +3,30 @@ module Propellor.Property.Hostname where import Propellor import qualified Propellor.Property.File as File --- | Sets the hostname. Should be provided with a FQDN, and will configure --- both /etc/hostname (with the base hostname) and /etc/hosts (with the --- full hostname). Also sets the current hostname. +-- | Sets the hostname. Configures both /etc/hostname and the current +-- hostname. +-- +-- When provided with a FQDN, also configures /etc/hosts, +-- with an entry for 127.0.1.1, which is standard at least on Debian +-- to set the FDQN (127.0.0.1 is localhost). set :: HostName -> Property -set hostname = "/etc/hostname" `File.hasContent` [hostname] - `onChange` cmdProperty "hostname" [hostname] - `describe` ("hostname " ++ hostname) +set hostname = propertyList desc go + `onChange` cmdProperty "hostname" [host] + `describe` desc where + desc = "hostname " ++ hostname (host, domain) = separate (== '.') hostname + + go = catMaybes + [ Just $ "/etc/hostname" `File.hasContent` [host] + , if null domain + then Nothing + else Just $ File.fileProperty desc + addhostline "/etc/hosts" + ] + + hostip = "127.0.1.1" + hostline = hostip ++ "\t" ++ hostname ++ " " ++ host + + addhostline ls = hostline : filter (not . hashostip) ls + hashostip l = headMaybe (words l) == Just hostip |
