summaryrefslogtreecommitdiff
path: root/Property.hs
diff options
context:
space:
mode:
authorJoey Hess2014-03-30 01:13:53 -0400
committerJoey Hess2014-03-30 01:13:53 -0400
commit8684db8bbf886d5dc41523e2b79df54aa1702cf8 (patch)
tree168828f2920a74c52e6ec747970f2c603ce39701 /Property.hs
parente812acce3e46b7dd259783fc28c2c65d4ad7a228 (diff)
run apt noninteractively
Diffstat (limited to 'Property.hs')
-rw-r--r--Property.hs24
1 files changed, 15 insertions, 9 deletions
diff --git a/Property.hs b/Property.hs
index c4db8bcf..3fdbcd3b 100644
--- a/Property.hs
+++ b/Property.hs
@@ -6,16 +6,17 @@ import Control.Monad
import System.Console.ANSI
import System.Exit
-import Utility.Tmp
+import Utility.Monad
import Utility.Exception
import Utility.SafeCommand
-import Utility.Monad
+import Utility.Tmp
+import Utility.Env
-- Ensures that the system has some property.
-- Actions must be idempotent; will be run repeatedly.
data Property
= FileProperty Desc FilePath ([Line] -> [Line])
- | CmdProperty Desc String [CommandParam]
+ | CmdProperty Desc String [CommandParam] [(String, String)]
| IOProperty Desc (IO Result)
data Result = NoChange | MadeChange | FailedChange
@@ -33,7 +34,7 @@ combineResult NoChange NoChange = NoChange
propertyDesc :: Property -> Desc
propertyDesc (FileProperty d _ _) = d
-propertyDesc (CmdProperty d _ _) = d
+propertyDesc (CmdProperty d _ _ _) = d
propertyDesc (IOProperty d _) = d
combineProperties :: Desc -> [Property] -> Property
@@ -59,10 +60,12 @@ ensureProperty' (FileProperty _ f a) = go =<< doesFileExist f
then noChange
else makeChange $ viaTmp writeFile f (unlines ls')
go False = makeChange $ writeFile f (unlines $ a [])
-ensureProperty' (CmdProperty _ cmd params) = ifM (boolSystem cmd params)
- ( return MadeChange
- , return FailedChange
- )
+ensureProperty' (CmdProperty _ cmd params env) = do
+ env' <- addEntries env <$> getEnvironment
+ ifM (boolSystemEnv cmd params (Just env'))
+ ( return MadeChange
+ , return FailedChange
+ )
ensureProperty' (IOProperty _ a) = a
ensureProperties :: [Property] -> IO ()
@@ -96,7 +99,10 @@ noChange :: IO Result
noChange = return NoChange
cmdProperty :: String -> [CommandParam] -> Property
-cmdProperty cmd params = CmdProperty desc cmd params
+cmdProperty cmd params = cmdProperty' cmd params []
+
+cmdProperty' :: String -> [CommandParam] -> [(String, String)] -> Property
+cmdProperty' cmd params env = CmdProperty desc cmd params env
where
desc = unwords $ cmd : map showp params
showp (Params s) = s