summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Hostname.hs
diff options
context:
space:
mode:
authorJoey Hess2014-07-18 00:20:09 -0400
committerJoey Hess2014-07-18 00:20:09 -0400
commit5590c1c75a4207ab5ad3d02a2073f974b0b27add (patch)
tree0d76160523851c3cc21b33d36d230f619568324a /src/Propellor/Property/Hostname.hs
parent863cdf470b91fb284405f4b96910f32727da1281 (diff)
propellor spin
Diffstat (limited to 'src/Propellor/Property/Hostname.hs')
-rw-r--r--src/Propellor/Property/Hostname.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Propellor/Property/Hostname.hs b/src/Propellor/Property/Hostname.hs
index 1cce4e60..c3821eb4 100644
--- a/src/Propellor/Property/Hostname.hs
+++ b/src/Propellor/Property/Hostname.hs
@@ -3,6 +3,8 @@ module Propellor.Property.Hostname where
import Propellor
import qualified Propellor.Property.File as File
+import Data.List
+
-- | Ensures that the hostname is set using best practices.
--
-- Configures /etc/hostname and the current hostname.
@@ -37,3 +39,21 @@ setTo hn = combineProperties desc go
addhostsline ip names ls =
(ip ++ "\t" ++ (unwords names)) : filter (not . hasip ip) ls
hasip ip l = headMaybe (words l) == Just ip
+
+-- | Makes /etc/resolv.conf contain search and domain lines for
+-- the domain that the hostname is in.
+searchDomain :: Property
+searchDomain = property desc (ensureProperty . go =<< asks hostName)
+ where
+ desc = "resolv.conf search and domain configured"
+ go hn =
+ let (_basehost, domain) = separate (== '.') hn
+ in File.fileProperty desc (use domain) "/etc/resolv.conf"
+ use domain ls = filter wanted $ nub (ls ++ cfgs)
+ where
+ cfgs = ["domain " ++ domain, "search " ++ domain]
+ wanted l
+ | l `elem` cfgs = True
+ | "domain " `isPrefixOf` l = False
+ | "search " `isPrefixOf` l = False
+ | otherwise = True