From e7c7adc0c4cdc838eada045334b038c7f01dcc56 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 7 Mar 2016 21:51:25 -0400 Subject: add unsupportedOS --- src/Propellor/Property.hs | 11 ++++++++++- src/Propellor/Property/Apt.hs | 6 ++---- src/Propellor/Property/OS.hs | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src/Propellor') diff --git a/src/Propellor/Property.hs b/src/Propellor/Property.hs index fe99a3fd..b6b8dc0d 100644 --- a/src/Propellor/Property.hs +++ b/src/Propellor/Property.hs @@ -20,6 +20,7 @@ module Propellor.Property ( , property , ensureProperty , withOS + , unsupportedOS , makeChange , noChange , doNothing @@ -256,10 +257,18 @@ isNewerThan x y = do -- > myproperty = withOS "foo installed" $ \o -> case o of -- > (Just (System (Debian suite) arch)) -> ... -- > (Just (System (Buntish release) arch)) -> ... --- > Nothing -> ... +-- > Nothing -> unsupportedOS withOS :: Desc -> (Maybe System -> Propellor Result) -> Property NoInfo withOS desc a = property desc $ a =<< getOS +-- | Throws an error, for use in `withOS` when a property is lacking +-- support for an OS. +unsupportedOS :: Propellor a +unsupportedOS = go =<< getOS + where + go Nothing = error "Unknown host OS is not supported by this property." + go (Just o) = error $ "This property is not implemented for " ++ show o + -- | Undoes the effect of a RevertableProperty. revert :: RevertableProperty i -> RevertableProperty i revert (RevertableProperty p1 p2) = RevertableProperty p2 p1 diff --git a/src/Propellor/Property/Apt.hs b/src/Propellor/Property/Apt.hs index eae56ab5..7301a6ae 100644 --- a/src/Propellor/Property/Apt.hs +++ b/src/Propellor/Property/Apt.hs @@ -160,16 +160,14 @@ installed' params ps = robustly $ check (isInstallable ps) go installedBackport :: [Package] -> Property NoInfo installedBackport ps = withOS desc $ \o -> case o of - Nothing -> error "cannot install backports; os not declared" (Just (System (Debian suite) _)) -> case backportSuite suite of - Nothing -> notsupported o + Nothing -> unsupportedOS Just bs -> ensureProperty $ runApt (["install", "-t", bs, "-y"] ++ ps) `changesFile` dpkgStatus - _ -> notsupported o + _ -> unsupportedOS where desc = unwords ("apt installed backport":ps) - notsupported o = error $ "backports not supported on " ++ show o -- | Minimal install of package, without recommends. installedMin :: [Package] -> Property NoInfo diff --git a/src/Propellor/Property/OS.hs b/src/Propellor/Property/OS.hs index 5f1adddb..e5da0921 100644 --- a/src/Propellor/Property/OS.hs +++ b/src/Propellor/Property/OS.hs @@ -86,7 +86,7 @@ cleanInstallOnce confirmation = check (not <$> doesFileExist flagfile) $ osbootstrapped = withOS (newOSDir ++ " bootstrapped") $ \o -> case o of (Just d@(System (Debian _) _)) -> debootstrap d (Just u@(System (Buntish _) _)) -> debootstrap u - _ -> error "os is not declared to be Debian or *buntu" + _ -> unsupportedOS debootstrap targetos = ensureProperty $ -- Ignore the os setting, and install debootstrap from -- cgit v1.2.3