module Propellor.Property.OS (
cleanInstallOnce,
Confirmation(..),
preserveNetwork,
preserveResolvConf,
preserveRootSshAuthorized,
oldOSRemoved,
) where
import Propellor.Base
import qualified Propellor.Property.Debootstrap as Debootstrap
import qualified Propellor.Property.Ssh as Ssh
import qualified Propellor.Property.Network as Network
import qualified Propellor.Property.User as User
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Reboot as Reboot
import Propellor.Property.Mount
import Propellor.Property.Chroot.Util (stdPATH)
import System.Posix.Files (rename, fileExist)
import Control.Exception (throw)
cleanInstallOnce :: Confirmation -> Property DebianLike
cleanInstallOnce :: Confirmation -> Property DebianLike
cleanInstallOnce Confirmation
confirmation = IO Bool -> Property DebianLike -> Property DebianLike
forall (p :: * -> *) i (m :: * -> *).
(Checkable p i, LiftPropellor m) =>
m Bool -> p i -> Property i
check (Bool -> Bool
not (Bool -> Bool) -> IO Bool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HostName -> IO Bool
doesFileExist HostName
flagfile) (Property DebianLike -> Property DebianLike)
-> Property DebianLike -> Property DebianLike
forall a b. (a -> b) -> a -> b
$
Property DebianLike
go Property DebianLike
-> Property UnixLike
-> CombinedType (Property DebianLike) (Property UnixLike)
forall x y. Combines x y => x -> y -> CombinedType x y
`requires` HostName -> Confirmation -> Property UnixLike
confirmed HostName
"clean install confirmed" Confirmation
confirmation
where
go :: CombinedType
(CombinedType
(CombinedType
(CombinedType (Property DebianLike) (Property Linux))
(Property UnixLike))
(Property Linux))
(Property Linux)
go =
Property UnixLike
finalized
Property UnixLike
-> Property DebianLike
-> CombinedType (Property UnixLike) (Property DebianLike)
forall x y. Combines x y => x -> y -> CombinedType x y
`requires`
Bool -> Property DebianLike
User.shadowConfig Bool
True
Property DebianLike
-> Property Linux
-> CombinedType (Property DebianLike) (Property Linux)
forall x y. Combines x y => x -> y -> CombinedType x y
`requires`
Bool -> (Result -> Bool) -> Property Linux
Reboot.atEnd Bool
True (Result -> Result -> Bool
forall a. Eq a => a -> a -> Bool
/= Result
FailedChange)
CombinedType (Property DebianLike) (Property Linux)
-> Property UnixLike
-> CombinedType
(CombinedType (Property DebianLike) (Property Linux))
(Property UnixLike)
forall x y. Combines x y => x -> y -> CombinedType x y
`requires`
Property UnixLike
propellorbootstrapped
CombinedType
(CombinedType (Property DebianLike) (Property Linux))
(Property UnixLike)
-> Property Linux
-> CombinedType
(CombinedType
(CombinedType (Property DebianLike) (Property Linux))
(Property UnixLike))
(Property Linux)
forall x y. Combines x y => x -> y -> CombinedType x y
`requires`
Property Linux
flipped
CombinedType
(CombinedType
(CombinedType (Property DebianLike) (Property Linux))
(Property UnixLike))
(Property Linux)
-> Property Linux
-> CombinedType
(CombinedType
(CombinedType
(CombinedType (Property DebianLike) (Property Linux))
(Property UnixLike))
(Property Linux))
(Property Linux)
forall x y. Combines x y => x -> y -> CombinedType x y
`requires`
Property Linux
osbootstrapped
osbootstrapped :: Property Linux
osbootstrapped :: Property Linux
osbootstrapped = HostName
-> (OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
-> Maybe System -> Propellor Result)
-> Property Linux
forall {k} (metatypes :: k).
SingI metatypes =>
HostName
-> (OuterMetaTypesWitness metatypes
-> Maybe System -> Propellor Result)
-> Property (MetaTypes metatypes)
withOS (HostName
newOSDir HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
" bootstrapped") ((OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
-> Maybe System -> Propellor Result)
-> Property Linux)
-> (OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
-> Maybe System -> Propellor Result)
-> Property Linux
forall a b. (a -> b) -> a -> b
$ \OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
w Maybe System
o -> case Maybe System
o of
(Just d :: System
d@(System (Debian DebianKernel
_ DebianSuite
_) Architecture
_)) -> OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
-> Property Linux -> Propellor Result
forall (inner :: [MetaType]) (outer :: [MetaType]).
EnsurePropertyAllowed inner outer =>
OuterMetaTypesWitness outer
-> Property (MetaTypes inner) -> Propellor Result
ensureProperty OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
w (Property Linux -> Propellor Result)
-> Property Linux -> Propellor Result
forall a b. (a -> b) -> a -> b
$
System -> Property Linux
debootstrap System
d
(Just u :: System
u@(System (Buntish HostName
_) Architecture
_)) -> OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
-> Property Linux -> Propellor Result
forall (inner :: [MetaType]) (outer :: [MetaType]).
EnsurePropertyAllowed inner outer =>
OuterMetaTypesWitness outer
-> Property (MetaTypes inner) -> Propellor Result
ensureProperty OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
w (Property Linux -> Propellor Result)
-> Property Linux -> Propellor Result
forall a b. (a -> b) -> a -> b
$
System -> Property Linux
debootstrap System
u
Maybe System
_ -> Propellor Result
HasCallStack => Propellor Result
unsupportedOS'
debootstrap :: System -> Property Linux
debootstrap :: System -> Property Linux
debootstrap System
targetos =
Property Linux
-> HostName -> System -> DebootstrapConfig -> Property Linux
Debootstrap.built' Property Linux
Debootstrap.sourceInstall
HostName
newOSDir System
targetos DebootstrapConfig
Debootstrap.DefaultConfig
flipped :: Property Linux
flipped :: Property Linux
flipped = HostName -> Propellor Result -> Property Linux
forall {k} (metatypes :: k).
SingI metatypes =>
HostName -> Propellor Result -> Property (MetaTypes metatypes)
property (HostName
newOSDir HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
" moved into place") (Propellor Result -> Property Linux)
-> Propellor Result -> Property Linux
forall a b. (a -> b) -> a -> b
$ IO Result -> Propellor Result
forall a. IO a -> Propellor a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Result -> Propellor Result) -> IO Result -> Propellor Result
forall a b. (a -> b) -> a -> b
$ do
devfstype <- HostName -> Maybe HostName -> HostName
forall a. a -> Maybe a -> a
fromMaybe HostName
"devtmpfs" (Maybe HostName -> HostName) -> IO (Maybe HostName) -> IO HostName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HostName -> IO (Maybe HostName)
getFsType HostName
"/dev"
mnts <- filter (`notElem` ("/": trickydirs)) <$> mountPoints
forM_ (reverse mnts) umountLazy
renamesout <- map (\HostName
d -> (HostName
d, HostName
oldOSDir HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
d, Bool -> IO Bool
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ HostName
d HostName -> [HostName] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` (HostName
oldOSDirHostName -> [HostName] -> [HostName]
forall a. a -> [a] -> [a]
:HostName
newOSDirHostName -> [HostName] -> [HostName]
forall a. a -> [a] -> [a]
:[HostName]
trickydirs)))
<$> dirContents "/"
renamesin <- map (\HostName
d -> let dest :: HostName
dest = HostName
"/" HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName -> HostName
takeFileName HostName
d in (HostName
d, HostName
dest, Bool -> Bool
not (Bool -> Bool) -> IO Bool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HostName -> IO Bool
fileExist HostName
dest))
<$> dirContents newOSDir
createDirectoryIfMissing True oldOSDir
massRename (renamesout ++ renamesin)
removeDirectoryRecursive newOSDir
void $ setEnv "PATH" stdPATH True
void $ unsetEnv "LANG"
unlessM (mount devfstype devfstype "/dev" mempty) $ do
warningMessage $ "failed mounting /dev using " ++ devfstype ++ "; falling back to MAKEDEV generic"
void $ boolSystem "sh" [Param "-c", Param "cd /dev && /sbin/MAKEDEV generic"]
unlessM (mount "sysfs" "sysfs" "/sys" mempty) $
warningMessage "failed mounting /sys"
unlessM (mount "devpts" "devpts" "/dev/pts" mempty) $
warningMessage "failed mounting /dev/pts"
return MadeChange
propellorbootstrapped :: Property UnixLike
propellorbootstrapped :: Property UnixLike
propellorbootstrapped = HostName -> Propellor Result -> Property UnixLike
forall {k} (metatypes :: k).
SingI metatypes =>
HostName -> Propellor Result -> Property (MetaTypes metatypes)
property HostName
"propellor re-debootstrapped in new os" (Propellor Result -> Property UnixLike)
-> Propellor Result -> Property UnixLike
forall a b. (a -> b) -> a -> b
$
Result -> Propellor Result
forall a. a -> Propellor a
forall (m :: * -> *) a. Monad m => a -> m a
return Result
NoChange
finalized :: Property UnixLike
finalized :: Property UnixLike
finalized = HostName -> Propellor Result -> Property UnixLike
forall {k} (metatypes :: k).
SingI metatypes =>
HostName -> Propellor Result -> Property (MetaTypes metatypes)
property HostName
"clean OS installed" (Propellor Result -> Property UnixLike)
-> Propellor Result -> Property UnixLike
forall a b. (a -> b) -> a -> b
$ do
IO () -> Propellor ()
forall a. IO a -> Propellor a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Propellor ()) -> IO () -> Propellor ()
forall a b. (a -> b) -> a -> b
$ HostName -> HostName -> IO ()
writeFile HostName
flagfile HostName
""
Result -> Propellor Result
forall a. a -> Propellor a
forall (m :: * -> *) a. Monad m => a -> m a
return Result
MadeChange
flagfile :: HostName
flagfile = HostName
"/etc/propellor-cleaninstall"
trickydirs :: [HostName]
trickydirs =
[ HostName
"/tmp"
, HostName
"/proc"
]
massRename :: [(FilePath, FilePath, IO Bool)] -> IO ()
massRename :: [(HostName, HostName, IO Bool)] -> IO ()
massRename = [(HostName, HostName)] -> [(HostName, HostName, IO Bool)] -> IO ()
go []
where
go :: [(HostName, HostName)] -> [(HostName, HostName, IO Bool)] -> IO ()
go [(HostName, HostName)]
_ [] = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go [(HostName, HostName)]
undo ((HostName
from, HostName
to, IO Bool
test):[(HostName, HostName, IO Bool)]
rest) = IO Bool -> (IO (), IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => m Bool -> (m a, m a) -> m a
ifM IO Bool
test
( IO () -> IO (Either SomeException ())
forall (m :: * -> *) a.
MonadCatch m =>
m a -> m (Either SomeException a)
tryNonAsync (HostName -> HostName -> IO ()
rename HostName
from HostName
to)
IO (Either SomeException ())
-> (Either SomeException () -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> IO ())
-> (() -> IO ()) -> Either SomeException () -> IO ()
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
([(HostName, HostName)] -> SomeException -> IO ()
forall {t :: * -> *} {e} {b}.
(Foldable t, Exception e) =>
t (HostName, HostName) -> e -> IO b
rollback [(HostName, HostName)]
undo)
(IO () -> () -> IO ()
forall a b. a -> b -> a
const (IO () -> () -> IO ()) -> IO () -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ [(HostName, HostName)] -> [(HostName, HostName, IO Bool)] -> IO ()
go ((HostName
to, HostName
from)(HostName, HostName)
-> [(HostName, HostName)] -> [(HostName, HostName)]
forall a. a -> [a] -> [a]
:[(HostName, HostName)]
undo) [(HostName, HostName, IO Bool)]
rest)
, [(HostName, HostName)] -> [(HostName, HostName, IO Bool)] -> IO ()
go [(HostName, HostName)]
undo [(HostName, HostName, IO Bool)]
rest
)
rollback :: t (HostName, HostName) -> e -> IO b
rollback t (HostName, HostName)
undo e
e = do
((HostName, HostName) -> IO ()) -> t (HostName, HostName) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((HostName -> HostName -> IO ()) -> (HostName, HostName) -> IO ()
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry HostName -> HostName -> IO ()
rename) t (HostName, HostName)
undo
e -> IO b
forall a e. (HasCallStack, Exception e) => e -> a
throw e
e
data Confirmation = Confirmed HostName
confirmed :: Desc -> Confirmation -> Property UnixLike
confirmed :: HostName -> Confirmation -> Property UnixLike
confirmed HostName
desc (Confirmed HostName
c) = HostName -> Propellor Result -> Property UnixLike
forall {k} (metatypes :: k).
SingI metatypes =>
HostName -> Propellor Result -> Property (MetaTypes metatypes)
property HostName
desc (Propellor Result -> Property UnixLike)
-> Propellor Result -> Property UnixLike
forall a b. (a -> b) -> a -> b
$ do
hostname <- (Host -> HostName) -> Propellor HostName
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Host -> HostName
hostName
if hostname /= c
then do
warningMessage "Run with a bad confirmation, not matching hostname."
return FailedChange
else return NoChange
preserveNetwork :: Property DebianLike
preserveNetwork :: Property DebianLike
preserveNetwork = Property DebianLike
go Property DebianLike
-> Property DebianLike
-> CombinedType (Property DebianLike) (Property DebianLike)
forall x y. Combines x y => x -> y -> CombinedType x y
`requires` Property DebianLike
Network.cleanInterfacesFile
where
go :: Property DebianLike
go :: Property DebianLike
go = HostName
-> (OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]
-> Propellor Result)
-> Property DebianLike
forall {k} (metatypes :: k).
SingI metatypes =>
HostName
-> (OuterMetaTypesWitness metatypes -> Propellor Result)
-> Property (MetaTypes metatypes)
property' HostName
"preserve network configuration" ((OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]
-> Propellor Result)
-> Property DebianLike)
-> (OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]
-> Propellor Result)
-> Property DebianLike
forall a b. (a -> b) -> a -> b
$ \OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]
w -> do
ls <- IO [HostName] -> Propellor [HostName]
forall a. IO a -> Propellor a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [HostName] -> Propellor [HostName])
-> IO [HostName] -> Propellor [HostName]
forall a b. (a -> b) -> a -> b
$ HostName -> [HostName]
lines (HostName -> [HostName]) -> IO HostName -> IO [HostName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HostName -> [HostName] -> IO HostName
readProcess HostName
"ip"
[HostName
"route", HostName
"list", HostName
"scope", HostName
"global"]
case words <$> headMaybe ls of
Just (HostName
"default":HostName
"via":HostName
_:HostName
"dev":HostName
iface:[HostName]
_) ->
OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]
-> Property DebianLike -> Propellor Result
forall (inner :: [MetaType]) (outer :: [MetaType]).
EnsurePropertyAllowed inner outer =>
OuterMetaTypesWitness outer
-> Property (MetaTypes inner) -> Propellor Result
ensureProperty OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]
w (Property DebianLike -> Propellor Result)
-> Property DebianLike -> Propellor Result
forall a b. (a -> b) -> a -> b
$ HostName -> Property DebianLike
Network.preserveStatic HostName
iface
Maybe [HostName]
_ -> do
HostName -> Propellor ()
forall (m :: * -> *). MonadIO m => HostName -> m ()
warningMessage HostName
"did not find any default ipv4 route"
Result -> Propellor Result
forall a. a -> Propellor a
forall (m :: * -> *) a. Monad m => a -> m a
return Result
FailedChange
preserveResolvConf :: Property Linux
preserveResolvConf :: Property Linux
preserveResolvConf = IO Bool -> Property Linux -> Property Linux
forall (p :: * -> *) i (m :: * -> *).
(Checkable p i, LiftPropellor m) =>
m Bool -> p i -> Property i
check (HostName -> IO Bool
fileExist HostName
oldloc) (Property Linux -> Property Linux)
-> Property Linux -> Property Linux
forall a b. (a -> b) -> a -> b
$
HostName
-> (OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
-> Propellor Result)
-> Property Linux
forall {k} (metatypes :: k).
SingI metatypes =>
HostName
-> (OuterMetaTypesWitness metatypes -> Propellor Result)
-> Property (MetaTypes metatypes)
property' (HostName
newloc HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
" copied from old OS") ((OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
-> Propellor Result)
-> Property Linux)
-> (OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
-> Propellor Result)
-> Property Linux
forall a b. (a -> b) -> a -> b
$ \OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux]
w -> do
ls <- IO [HostName] -> Propellor [HostName]
forall a. IO a -> Propellor a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [HostName] -> Propellor [HostName])
-> IO [HostName] -> Propellor [HostName]
forall a b. (a -> b) -> a -> b
$ HostName -> [HostName]
lines (HostName -> [HostName]) -> IO HostName -> IO [HostName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HostName -> IO HostName
readFile HostName
oldloc
ensureProperty w $ newloc `File.hasContent` ls
where
newloc :: HostName
newloc = HostName
"/etc/resolv.conf"
oldloc :: HostName
oldloc = HostName
oldOSDir HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
newloc
preserveRootSshAuthorized :: Property UnixLike
preserveRootSshAuthorized :: Property UnixLike
preserveRootSshAuthorized = IO Bool -> Property UnixLike -> Property UnixLike
forall (p :: * -> *) i (m :: * -> *).
(Checkable p i, LiftPropellor m) =>
m Bool -> p i -> Property i
check (HostName -> IO Bool
fileExist HostName
oldloc) (Property UnixLike -> Property UnixLike)
-> Property UnixLike -> Property UnixLike
forall a b. (a -> b) -> a -> b
$
HostName
-> (OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD]
-> Propellor Result)
-> Property UnixLike
forall {k} (metatypes :: k).
SingI metatypes =>
HostName
-> (OuterMetaTypesWitness metatypes -> Propellor Result)
-> Property (MetaTypes metatypes)
property' HostName
desc ((OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD]
-> Propellor Result)
-> Property UnixLike)
-> (OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD]
-> Propellor Result)
-> Property UnixLike
forall a b. (a -> b) -> a -> b
$ \OuterMetaTypesWitness
'[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD]
w -> do
ks <- IO [HostName] -> Propellor [HostName]
forall a. IO a -> Propellor a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [HostName] -> Propellor [HostName])
-> IO [HostName] -> Propellor [HostName]
forall a b. (a -> b) -> a -> b
$ HostName -> [HostName]
lines (HostName -> [HostName]) -> IO HostName -> IO [HostName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HostName -> IO HostName
readFile HostName
oldloc
ensureProperty w $ combineProperties desc $
toProps $ map (setupRevertableProperty . Ssh.authorizedKey (User "root")) ks
where
desc :: HostName
desc = HostName
newloc HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
" copied from old OS"
newloc :: HostName
newloc = HostName
"/root/.ssh/authorized_keys"
oldloc :: HostName
oldloc = HostName
oldOSDir HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
newloc
oldOSRemoved :: Confirmation -> Property UnixLike
oldOSRemoved :: Confirmation -> Property UnixLike
oldOSRemoved Confirmation
confirmation = IO Bool -> Property UnixLike -> Property UnixLike
forall (p :: * -> *) i (m :: * -> *).
(Checkable p i, LiftPropellor m) =>
m Bool -> p i -> Property i
check (HostName -> IO Bool
doesDirectoryExist HostName
oldOSDir) (Property UnixLike -> Property UnixLike)
-> Property UnixLike -> Property UnixLike
forall a b. (a -> b) -> a -> b
$
Property UnixLike
go Property UnixLike
-> Property UnixLike
-> CombinedType (Property UnixLike) (Property UnixLike)
forall x y. Combines x y => x -> y -> CombinedType x y
`requires` HostName -> Confirmation -> Property UnixLike
confirmed HostName
"old OS backup removal confirmed" Confirmation
confirmation
where
go :: Property UnixLike
go :: Property UnixLike
go = HostName -> Propellor Result -> Property UnixLike
forall {k} (metatypes :: k).
SingI metatypes =>
HostName -> Propellor Result -> Property (MetaTypes metatypes)
property HostName
"old OS backup removed" (Propellor Result -> Property UnixLike)
-> Propellor Result -> Property UnixLike
forall a b. (a -> b) -> a -> b
$ do
IO () -> Propellor ()
forall a. IO a -> Propellor a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Propellor ()) -> IO () -> Propellor ()
forall a b. (a -> b) -> a -> b
$ HostName -> IO ()
removeDirectoryRecursive HostName
oldOSDir
Result -> Propellor Result
forall a. a -> Propellor a
forall (m :: * -> *) a. Monad m => a -> m a
return Result
MadeChange
oldOSDir :: FilePath
oldOSDir :: HostName
oldOSDir = HostName
"/old-os"
newOSDir :: FilePath
newOSDir :: HostName
newOSDir = HostName
"/new-os"