summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2015-12-06 00:51:25 -0400
committerJoey Hess2015-12-06 00:51:25 -0400
commitfe746525f3efe483d7a50575a325faa88089112c (patch)
tree513da3c64f18f05ebad9279063ead39fe2dcc4a7 /src
parentd5710d64c15b57c8a5d37437d4a36c3eb231d4f4 (diff)
only write /etc/hosts once, avoiding always returning MadeChange
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Hostname.hs42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/Propellor/Property/Hostname.hs b/src/Propellor/Property/Hostname.hs
index fcb88f59..7ab350ae 100644
--- a/src/Propellor/Property/Hostname.hs
+++ b/src/Propellor/Property/Hostname.hs
@@ -35,31 +35,33 @@ setTo :: HostName -> Property NoInfo
setTo = setTo' extractDomain
setTo' :: ExtractDomain -> HostName -> Property NoInfo
-setTo' extractdomain hn = combineProperties desc go
+setTo' extractdomain hn = combineProperties desc
+ [ "/etc/hostname" `File.hasContent` [basehost]
+ , hostslines $ catMaybes
+ [ if null domain
+ then Nothing
+ else Just ("127.0.1.1", [hn, basehost])
+ , Just ("127.0.0.1", ["localhost"])
+ ]
+ , check (not <$> inChroot) $
+ cmdProperty "hostname" [basehost]
+ `assume` NoChange
+ , "/etc/mailname" `File.hasContent`
+ [if null domain then hn else domain]
+ ]
where
desc = "hostname " ++ hn
basehost = takeWhile (/= '.') hn
domain = extractdomain hn
-
- go = catMaybes
- [ Just $ "/etc/hostname" `File.hasContent` [basehost]
- , if null domain
- then Nothing
- else Just $ hostsline "127.0.1.1" [hn, basehost]
- , Just $ hostsline "127.0.0.1" ["localhost"]
- , Just $ check (not <$> inChroot) $
- cmdProperty "hostname" [basehost]
- `assume` NoChange
- , Just $ "/etc/mailname" `File.hasContent`
- [if null domain then hn else domain]
- ]
- hostsline ip names = File.fileProperty desc
- (addhostsline ip names)
- "/etc/hosts"
- addhostsline ip names ls =
- (ip ++ "\t" ++ (unwords names)) : filter (not . hasip ip) ls
- hasip ip l = headMaybe (words l) == Just ip
+ hostslines ipsnames =
+ File.fileProperty desc (addhostslines ipsnames) "/etc/hosts"
+ addhostslines :: [(String, [String])] -> [String] -> [String]
+ addhostslines ipsnames ls =
+ let ips = map fst ipsnames
+ hasip l = maybe False (`elem` ips) (headMaybe (words l))
+ mkline (ip, names) = ip ++ "\t" ++ (unwords names)
+ in map mkline ipsnames ++ filter (not . hasip) ls
-- | Makes </etc/resolv.conf> contain search and domain lines for
-- the domain that the hostname is in.