module Propellor.Property.Hostname where
import Propellor
import qualified Propellor.Property.File as File
set :: HostName -> Property
set hostname = combineProperties desc go
`onChange` cmdProperty "hostname" [host]
where
desc = "hostname " ++ hostname
(host, domain) = separate (== '.') hostname
go = catMaybes
[ Just $ "/etc/hostname" `File.hasContent` [host]
, if null domain
then Nothing
else Just $ File.filePropertydesc
addhostline "/etc/hosts"
]
hostip = "127.0.1.1"
hostline = hostip ++ "\t" ++ hostname ++ " " ++ host
addhostline ls = hostline : filter (not . hashostip) ls
hashostip l = headMaybe (words l) == Just hostip