summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Nullmailer.hs
diff options
context:
space:
mode:
authorNicolas Schodet2018-09-02 17:46:23 +0200
committerNicolas Schodet2018-09-02 22:18:36 +0200
commit2222911ad5bf4db3fcd57818e8764b5bbb53979c (patch)
tree3fbcbcb6653271f32399f320ceb07c4cb6ed793f /src/Propellor/Property/Nullmailer.hs
parentc4beab2529fc67ed9e4f2eb8e639f8d783b3a106 (diff)
Nullmailer: handle nullmailer configurationnullmailer
Diffstat (limited to 'src/Propellor/Property/Nullmailer.hs')
-rw-r--r--src/Propellor/Property/Nullmailer.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Propellor/Property/Nullmailer.hs b/src/Propellor/Property/Nullmailer.hs
new file mode 100644
index 00000000..fe03f5dd
--- /dev/null
+++ b/src/Propellor/Property/Nullmailer.hs
@@ -0,0 +1,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"