summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Hostname.hs
diff options
context:
space:
mode:
authorJoey Hess2015-12-06 14:33:22 -0400
committerJoey Hess2015-12-06 14:33:22 -0400
commit6c7ad5b021ae46be1fda3004f9c578ab2471d9aa (patch)
tree4319434104db22cc4598746eeb2d6fbf244ed7be /src/Propellor/Property/Hostname.hs
parent616c6c2e2c2c7dcafa9bc72c7c1bdea650e43e43 (diff)
parent516b7cb886470c6a86d4022d7cf20a8547a98bd9 (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Property/Hostname.hs')
-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.