2014-03-31 03:37:54 +00:00
|
|
|
|
module Propellor.Property.Hostname where
|
2014-03-30 03:45:48 +00:00
|
|
|
|
|
2014-03-31 03:55:59 +00:00
|
|
|
|
import Propellor
|
2014-03-31 03:37:54 +00:00
|
|
|
|
import qualified Propellor.Property.File as File
|
2014-03-30 03:45:48 +00:00
|
|
|
|
|
2014-04-10 21:46:03 +00:00
|
|
|
|
-- | Ensures that the hostname is set to the HostAttr value.
|
2014-04-14 19:17:31 +00:00
|
|
|
|
-- Configures /etc/hostname and the current hostname.
|
2014-04-04 03:57:36 +00:00
|
|
|
|
--
|
2014-04-14 19:17:31 +00:00
|
|
|
|
-- 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).
|
2014-04-10 21:46:03 +00:00
|
|
|
|
sane :: Property
|
2014-04-18 07:59:06 +00:00
|
|
|
|
sane = property ("sane hostname") (ensureProperty . setTo =<< getHostName)
|
2014-04-10 21:46:03 +00:00
|
|
|
|
|
|
|
|
|
setTo :: HostName -> Property
|
2014-04-11 01:09:20 +00:00
|
|
|
|
setTo hn = combineProperties desc go
|
|
|
|
|
`onChange` cmdProperty "hostname" [basehost]
|
2014-04-04 03:35:36 +00:00
|
|
|
|
where
|
2014-04-11 01:09:20 +00:00
|
|
|
|
desc = "hostname " ++ hn
|
|
|
|
|
(basehost, domain) = separate (== '.') hn
|
2014-04-04 03:57:36 +00:00
|
|
|
|
|
|
|
|
|
go = catMaybes
|
2014-04-11 01:09:20 +00:00
|
|
|
|
[ Just $ "/etc/hostname" `File.hasContent` [basehost]
|
2014-04-04 03:57:36 +00:00
|
|
|
|
, if null domain
|
|
|
|
|
then Nothing
|
|
|
|
|
else Just $ File.fileProperty desc
|
|
|
|
|
addhostline "/etc/hosts"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
hostip = "127.0.1.1"
|
2014-04-11 01:09:20 +00:00
|
|
|
|
hostline = hostip ++ "\t" ++ hn ++ " " ++ basehost
|
2014-04-04 03:57:36 +00:00
|
|
|
|
|
|
|
|
|
addhostline ls = hostline : filter (not . hashostip) ls
|
|
|
|
|
hashostip l = headMaybe (words l) == Just hostip
|