summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Nullmailer.hs
blob: fe03f5dd18a3f37303186ec5a8f50aa8fa942122 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- | Maintainer: Nicolas Schodet <nico@ni.fr.eu.org>
--
-- Support for Nullmailer.

module Propellor.Property.Nullmailer (
	installed,
	configured,
	configured',
) where

import Propellor
import Propellor.Base
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Systemd as Systemd

-- | Make sure needed tools are installed.
installed :: RevertableProperty DebianLike DebianLike
installed = install <!> remove
  where
	install = Apt.installed packages
	remove = Apt.removed packages
	packages = ["nullmailer"]

-- | Configure nullmailer using the hostname of the `Host`.
configured :: HostName -> String -> Property DebianLike
configured relayHost adminAddr = property' "nullmailer configured" $ \w ->
	ensureProperty w . configured' relayHost adminAddr =<< asks hostName

-- | Like configured, but allow to specify the hostname.
configured' :: HostName -> String -> HostName -> Property DebianLike
configured' relayHost adminAddr hn =
	(setup `onChange` reload) `requires` installed
  where
	setup :: Property UnixLike
	setup = combineProperties desc $ props
			& config "defaulthost" hn
			& config "adminaddr" adminAddr
			& config "remotes" (relayHost ++ " smtp")
	desc = "nullmailer configured"
	config name value = File.hasContent ("/etc/nullmailer" </> name) [value]
	reload = Systemd.restarted "nullmailer"