module Propellor.Property.FlashKernel where
import Propellor.Base
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import Propellor.Property.Mount
import Propellor.Types.Bootloader
import Propellor.Types.Info
type Machine = String
installed :: Machine -> Property (HasInfo + DebianLike)
installed machine = setInfoProperty go (toInfo [FlashKernelInstalled])
where
go = "/etc/flash-kernel/machine" `File.hasContent` [machine]
`onChange` flashKernel
`requires` File.dirExists "/etc/flash-kernel"
`requires` Apt.installed ["flash-kernel"]
flashKernel :: Property DebianLike
flashKernel = tightenTargets $
cmdProperty "flash-kernel" [] `assume` MadeChange
flashKernelMounted :: FilePath -> Property Linux
flashKernelMounted mnt = combineProperties desc $ props
& cleanupmounts
& bindMount "/dev" (inmnt "/dev")
& mounted "proc" "proc" (inmnt "/proc") mempty
& mounted "sysfs" "sys" (inmnt "/sys") mempty
& inchroot "update-initramfs" ["-u"]
`assume` MadeChange
& inchroot "flash-kernel" []
`assume` MadeChange
& cleanupmounts
where
desc = "flash-kernel run"
inmnt f = mnt ++ f
inchroot cmd ps = cmdProperty "chroot" ([mnt, cmd] ++ ps)
cleanupmounts :: Property Linux
cleanupmounts = property desc $ liftIO $ do
cleanup "/sys"
cleanup "/proc"
cleanup "/dev"
return NoChange
where
cleanup m =
let mp = inmnt m
in whenM (isMounted mp) $
umountLazy mp