summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Hostname.hs
diff options
context:
space:
mode:
authorJoey Hess2018-08-19 13:24:52 -0400
committerJoey Hess2018-08-19 13:24:52 -0400
commit5f5d99824a2b24d11ccbf4969f934c94e58a9a90 (patch)
tree985e3b5195084debf100c3b690a31d5c6da46010 /src/Propellor/Property/Hostname.hs
parent5f530af0223913a9a5ff50a806ee5b4f8e527983 (diff)
Split mailname property out of Hostname.sane
Since bad mailname guesses can lead to ugly surprises. (API change) Kept it in the Hostname module for easy discoverability, and similar to Hostname.searchDomain it sets a value based on the hostname so makes sense to keep it in that module. Didn't implement the mailname equivilant of Hostname.setTo, because it's trivial to write the mailname file with a custom value if desired. This commit was sponsored by John Pellman on Patreon.
Diffstat (limited to 'src/Propellor/Property/Hostname.hs')
-rw-r--r--src/Propellor/Property/Hostname.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Propellor/Property/Hostname.hs b/src/Propellor/Property/Hostname.hs
index 1eb9d690..0ece92a8 100644
--- a/src/Propellor/Property/Hostname.hs
+++ b/src/Propellor/Property/Hostname.hs
@@ -14,8 +14,6 @@ import Data.List
-- (However, when used inside a chroot, avoids setting the current hostname
-- as that would impact the system outside the chroot.)
--
--- Configures </etc/mailname> with the domain part of the hostname.
---
-- </etc/hosts> is also configured, with an entry for 127.0.1.1, which is
-- standard at least on Debian to set the FDQN.
--
@@ -46,8 +44,6 @@ setTo' extractdomain hn = combineProperties desc $ toProps
, check (not <$> inChroot) $
cmdProperty "hostname" [basehost]
`assume` NoChange
- , "/etc/mailname" `File.hasContent`
- [if null domain then hn else domain]
]
where
desc = "hostname " ++ hn
@@ -85,6 +81,19 @@ searchDomain' extractdomain = property' desc $ \w ->
| "search " `isPrefixOf` l = False
| otherwise = True
+-- Configures </etc/mailname> with the domain part of the hostname of the
+-- `Host` it's used in.
+mailname :: Property UnixLike
+mailname = mailname' extractDomain
+
+mailname' :: ExtractDomain -> Property UnixLike
+mailname' extractdomain = property' ("mailname set from hostname") $ \w ->
+ ensureProperty w . go =<< asks hostName
+ where
+ go mn = "/etc/mailname" `File.hasContent` [if null mn' then mn else mn']
+ where
+ mn' = extractdomain mn
+
-- | Function to extract the domain name from a HostName.
type ExtractDomain = HostName -> String