{-# LANGUAGE DeriveDataTypeable #-}
module Propellor.Property.Schroot where
import Propellor.Base
import Propellor.Types.Info
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
data UseOverlays = UseOverlays deriving (Eq, Show, Typeable)
useOverlays :: Property (HasInfo + UnixLike)
useOverlays = pureInfoProperty "use schroot overlays" (InfoVal UseOverlays)
usesOverlays :: Propellor Bool
usesOverlays = isJust . fromInfoVal
<$> (askInfo :: Propellor (InfoVal UseOverlays))
overlaysInTmpfs :: RevertableProperty (HasInfo + DebianLike) UnixLike
overlaysInTmpfs = (go `requires` installed) <!> undo
where
f = "/etc/schroot/setup.d/04tmpfs"
go :: Property (HasInfo + UnixLike)
go = combineProperties "schroot overlays in tmpfs" $ props
& useOverlays
& f `File.hasContent`
[ "#!/bin/sh"
, ""
, "set -e"
, ""
, ". \"$SETUP_DATA_DIR/common-data\""
, ". \"$SETUP_DATA_DIR/common-functions\""
, ". \"$SETUP_DATA_DIR/common-config\""
, ""
, ""
, "if [ $STAGE = \"setup-start\" ]; then"
, " mount -t tmpfs overlay /var/lib/schroot/union/overlay"
, "elif [ $STAGE = \"setup-recover\" ]; then"
, " mount -t tmpfs overlay /var/lib/schroot/union/overlay"
, "elif [ $STAGE = \"setup-stop\" ]; then"
, " umount -f /var/lib/schroot/union/overlay"
, "fi"
]
`onChange` (f `File.mode` combineModes (readModes ++ executeModes))
undo = File.notPresent f
installed :: Property DebianLike
installed = Apt.installed ["schroot"]