summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2015-05-07 12:18:23 -0400
committerJoey Hess2015-05-07 12:18:23 -0400
commit49ca7cb93f49fac0ff89090b500d3d48968f2b18 (patch)
treea2ca3d5e942650fe93561087aede9707e7f624c3
parent31bde3114b1f362fb1211f465c0ccfcaf82e468a (diff)
parent63ccccb1bb3eb14f351b4e8745a952d8738c0f5e (diff)
Merge branch 'joeyconfig'
-rw-r--r--debian/changelog7
-rw-r--r--src/Propellor/Property/Apt.hs6
-rw-r--r--src/Propellor/Property/Cmd.hs17
-rw-r--r--src/Utility/SafeCommand.hs27
4 files changed, 41 insertions, 16 deletions
diff --git a/debian/changelog b/debian/changelog
index ae8deef6..37d31938 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+propellor (2.5.0) UNRELEASED; urgency=medium
+
+ * cmdProperty' renamed to cmdPropertyEnv to make way for a new,
+ more generic cmdProperty' (API change)
+
+ -- Joey Hess <id@joeyh.name> Thu, 07 May 2015 12:08:34 -0400
+
propellor (2.4.0) unstable; urgency=medium
* Propellor no longer supports Debian wheezy (oldstable).
diff --git a/src/Propellor/Property/Apt.hs b/src/Propellor/Property/Apt.hs
index 7f2ed795..81005f1a 100644
--- a/src/Propellor/Property/Apt.hs
+++ b/src/Propellor/Property/Apt.hs
@@ -109,7 +109,7 @@ setSourcesListD ls basename = f `File.hasContent` ls `onChange` update
f = "/etc/apt/sources.list.d/" ++ basename ++ ".list"
runApt :: [String] -> Property NoInfo
-runApt ps = cmdProperty' "apt-get" ps noninteractiveEnv
+runApt ps = cmdPropertyEnv "apt-get" ps noninteractiveEnv
noninteractiveEnv :: [(String, String)]
noninteractiveEnv =
@@ -170,7 +170,7 @@ buildDep ps = robustly go
buildDepIn :: FilePath -> Property NoInfo
buildDepIn dir = go `requires` installedMin ["devscripts", "equivs"]
where
- go = cmdProperty' "sh" ["-c", "cd '" ++ dir ++ "' && mk-build-deps debian/control --install --tool 'apt-get -y --no-install-recommends' --remove"]
+ go = cmdPropertyEnv "sh" ["-c", "cd '" ++ dir ++ "' && mk-build-deps debian/control --install --tool 'apt-get -y --no-install-recommends' --remove"]
noninteractiveEnv
-- | Package installation may fail becuse the archive has changed.
@@ -251,7 +251,7 @@ reConfigure package vals = reconfigure `requires` setselections
forM_ vals $ \(tmpl, tmpltype, value) ->
hPutStrLn h $ unwords [package, tmpl, tmpltype, value]
hClose h
- reconfigure = cmdProperty' "dpkg-reconfigure" ["-fnone", package] noninteractiveEnv
+ reconfigure = cmdPropertyEnv "dpkg-reconfigure" ["-fnone", package] noninteractiveEnv
-- | Ensures that a service is installed and running.
--
diff --git a/src/Propellor/Property/Cmd.hs b/src/Propellor/Property/Cmd.hs
index e2b91db1..859302c8 100644
--- a/src/Propellor/Property/Cmd.hs
+++ b/src/Propellor/Property/Cmd.hs
@@ -3,6 +3,7 @@
module Propellor.Property.Cmd (
cmdProperty,
cmdProperty',
+ cmdPropertyEnv,
scriptProperty,
userScriptProperty,
) where
@@ -10,6 +11,7 @@ module Propellor.Property.Cmd (
import Control.Applicative
import Data.List
import "mtl" Control.Monad.Reader
+import System.Process (CreateProcess)
import Propellor.Types
import Propellor.Property
@@ -20,12 +22,19 @@ import Utility.Env
--
-- The command must exit 0 on success.
cmdProperty :: String -> [String] -> Property NoInfo
-cmdProperty cmd params = cmdProperty' cmd params []
+cmdProperty cmd params = cmdProperty' cmd params id
+
+cmdProperty' :: String -> [String] -> (CreateProcess -> CreateProcess) -> Property NoInfo
+cmdProperty' cmd params mkprocess = property desc $ liftIO $ do
+ toResult <$> boolSystem' cmd (map Param params) mkprocess
+ where
+ desc = unwords $ cmd : params
-- | A property that can be satisfied by running a command,
--- with added environment.
-cmdProperty' :: String -> [String] -> [(String, String)] -> Property NoInfo
-cmdProperty' cmd params env = property desc $ liftIO $ do
+-- with added environment variables in addition to the standard
+-- environment.
+cmdPropertyEnv :: String -> [String] -> [(String, String)] -> Property NoInfo
+cmdPropertyEnv cmd params env = property desc $ liftIO $ do
env' <- addEntries env <$> getEnvironment
toResult <$> boolSystemEnv cmd (map Param params) (Just env')
where
diff --git a/src/Utility/SafeCommand.hs b/src/Utility/SafeCommand.hs
index f44112b8..9eaa5308 100644
--- a/src/Utility/SafeCommand.hs
+++ b/src/Utility/SafeCommand.hs
@@ -1,6 +1,6 @@
{- safely running shell commands
-
- - Copyright 2010-2013 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2015 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
@@ -44,23 +44,32 @@ toCommand = concatMap unwrap
- if it succeeded or failed.
-}
boolSystem :: FilePath -> [CommandParam] -> IO Bool
-boolSystem command params = boolSystemEnv command params Nothing
+boolSystem command params = boolSystem' command params id
-boolSystemEnv :: FilePath -> [CommandParam] -> Maybe [(String, String)] -> IO Bool
-boolSystemEnv command params environ = dispatch <$> safeSystemEnv command params environ
+boolSystem' :: FilePath -> [CommandParam] -> (CreateProcess -> CreateProcess) -> IO Bool
+boolSystem' command params mkprocess = dispatch <$> safeSystem' command params mkprocess
where
dispatch ExitSuccess = True
dispatch _ = False
+boolSystemEnv :: FilePath -> [CommandParam] -> Maybe [(String, String)] -> IO Bool
+boolSystemEnv command params environ = boolSystem' command params $
+ \p -> p { env = environ }
+
{- Runs a system command, returning the exit status. -}
safeSystem :: FilePath -> [CommandParam] -> IO ExitCode
-safeSystem command params = safeSystemEnv command params Nothing
+safeSystem command params = safeSystem' command params id
-safeSystemEnv :: FilePath -> [CommandParam] -> Maybe [(String, String)] -> IO ExitCode
-safeSystemEnv command params environ = do
- (_, _, _, pid) <- createProcess (proc command $ toCommand params)
- { env = environ }
+safeSystem' :: FilePath -> [CommandParam] -> (CreateProcess -> CreateProcess) -> IO ExitCode
+safeSystem' command params mkprocess = do
+ (_, _, _, pid) <- createProcess p
waitForProcess pid
+ where
+ p = mkprocess $ proc command (toCommand params)
+
+safeSystemEnv :: FilePath -> [CommandParam] -> Maybe [(String, String)] -> IO ExitCode
+safeSystemEnv command params environ = safeSystem' command params $
+ \p -> p { env = environ }
{- Wraps a shell command line inside sh -c, allowing it to be run in a
- login shell that may not support POSIX shell, eg csh. -}