    -- | Maintainer: Félix Sipma <felix+propellor@gueux.org>

    module Propellor.Property.Prosody where

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

    type ConfigFile = [String]

    type Conf = String

    confEnabled :: Conf -> ConfigFile -> RevertableProperty DebianLike DebianLike
    confEnabled :: Conf -> ConfigFile -> RevertableProperty DebianLike DebianLike
    confEnabled conf :: Conf
    conf cf :: ConfigFile
    cf = Property DebianLike
    enable Property DebianLike
    -> Property DebianLike -> RevertableProperty DebianLike DebianLike
    forall setupmetatypes undometatypes.
    Property setupmetatypes
    -> Property undometatypes
    -> RevertableProperty setupmetatypes undometatypes
    <!> Property DebianLike
    disable
      where
    	enable :: CombinedType (Property DebianLike) (Property DebianLike)
    enable = Conf
    dir Conf -> LinkTarget -> RevertableProperty UnixLike UnixLike
    `File.isSymlinkedTo` LinkTarget
    target
    		RevertableProperty UnixLike UnixLike
    -> Conf -> RevertableProperty UnixLike UnixLike
    forall p. IsProp p => p -> Conf -> p
    `describe` ("prosody conf enabled " Conf -> Conf -> Conf
    forall a. [a] -> [a] -> [a]
    ++ Conf
    conf)
    		RevertableProperty UnixLike UnixLike
    -> Property DebianLike
    -> CombinedType
         (RevertableProperty UnixLike UnixLike) (Property DebianLike)
    forall x y. Combines x y => x -> y -> CombinedType x y
    `requires` Conf -> ConfigFile -> Property DebianLike
    confAvailable Conf
    conf ConfigFile
    cf
    		Property DebianLike
    -> Property DebianLike
    -> CombinedType (Property DebianLike) (Property DebianLike)
    forall x y. Combines x y => x -> y -> CombinedType x y
    `requires` Property DebianLike
    installed
    		Property DebianLike
    -> Property DebianLike
    -> CombinedType (Property DebianLike) (Property DebianLike)
    forall x y. Combines x y => x -> y -> CombinedType x y
    `onChange` Property DebianLike
    reloaded
    	  where
    		target :: LinkTarget
    target = Conf -> LinkTarget
    confValRelativePath Conf
    conf
    		dir :: Conf
    dir = Conf -> Conf
    confValPath Conf
    conf
    		confValRelativePath :: Conf -> LinkTarget
    confValRelativePath conf' :: Conf
    conf' = Conf -> LinkTarget
    File.LinkTarget (Conf -> LinkTarget) -> Conf -> LinkTarget
    forall a b. (a -> b) -> a -> b
    $
    			"../conf.avail" Conf -> Conf -> Conf
    </> Conf
    conf' Conf -> Conf -> Conf
    <.> "cfg.lua"
    	disable :: CombinedType (Property DebianLike) (Property DebianLike)
    disable = Conf -> Property UnixLike
    File.notPresent (Conf -> Conf
    confValPath Conf
    conf)
    		Property UnixLike -> Conf -> Property UnixLike
    forall p. IsProp p => p -> Conf -> p
    `describe` ("prosody conf disabled " Conf -> Conf -> Conf
    forall a. [a] -> [a] -> [a]
    ++ Conf
    conf)
    		Property UnixLike
    -> Property DebianLike
    -> CombinedType (Property UnixLike) (Property DebianLike)
    forall x y. Combines x y => x -> y -> CombinedType x y
    `requires` Property DebianLike
    installed
    		Property DebianLike
    -> Property DebianLike
    -> CombinedType (Property DebianLike) (Property DebianLike)
    forall x y. Combines x y => x -> y -> CombinedType x y
    `onChange` Property DebianLike
    reloaded

    confAvailable :: Conf -> ConfigFile -> Property DebianLike
    confAvailable :: Conf -> ConfigFile -> Property DebianLike
    confAvailable conf :: Conf
    conf cf :: ConfigFile
    cf = ("prosody conf available " Conf -> Conf -> Conf
    forall a. [a] -> [a] -> [a]
    ++ Conf
    conf) Conf -> Property DebianLike -> Property DebianLike
    forall i. IsProp (Property i) => Conf -> Property i -> Property i
    ==>
    	Property UnixLike -> Property DebianLike
    forall (p :: * -> *) (untightened :: [MetaType])
           (tightened :: [MetaType]).
    (TightenTargets p, TightenTargetsAllowed untightened tightened,
     SingI tightened) =>
    p (MetaTypes untightened) -> p (MetaTypes tightened)
    tightenTargets (Conf -> Conf
    confAvailPath Conf
    conf Conf -> ConfigFile -> Property UnixLike
    `File.hasContent` (Conf
    comment Conf -> ConfigFile -> ConfigFile
    forall a. a -> [a] -> [a]
    : ConfigFile
    cf))
      where
    	comment :: Conf
    comment = "-- deployed with propellor, do not modify"

    confAvailPath :: Conf -> FilePath
    confAvailPath :: Conf -> Conf
    confAvailPath conf :: Conf
    conf = "/etc/prosody/conf.avail" Conf -> Conf -> Conf
    </> Conf
    conf Conf -> Conf -> Conf
    <.> "cfg.lua"

    confValPath :: Conf -> FilePath
    confValPath :: Conf -> Conf
    confValPath conf :: Conf
    conf = "/etc/prosody/conf.d" Conf -> Conf -> Conf
    </> Conf
    conf Conf -> Conf -> Conf
    <.> "cfg.lua"

    installed :: Property DebianLike
    installed :: Property DebianLike
    installed = ConfigFile -> Property DebianLike
    Apt.installed ["prosody"]

    restarted :: Property DebianLike
    restarted :: Property DebianLike
    restarted = Conf -> Property DebianLike
    Service.restarted "prosody"

    reloaded :: Property DebianLike
    reloaded :: Property DebianLike
    reloaded = Conf -> Property DebianLike
    Service.reloaded "prosody"