summaryrefslogtreecommitdiff
path: root/Propellor/CmdLine.hs
diff options
context:
space:
mode:
authorJoey Hess2014-03-31 18:53:27 -0400
committerJoey Hess2014-03-31 18:53:27 -0400
commite170189b23724d8f8b610d5dcb80c35a16f5fd0a (patch)
treea9b0712b4f6978279b06286e6b7a4b7573db565e /Propellor/CmdLine.hs
parent45a453a87efb04f3777c7b153da3f391fc0513fb (diff)
propellor spin
Diffstat (limited to 'Propellor/CmdLine.hs')
-rw-r--r--Propellor/CmdLine.hs21
1 files changed, 18 insertions, 3 deletions
diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs
index 08d95249..7461a824 100644
--- a/Propellor/CmdLine.hs
+++ b/Propellor/CmdLine.hs
@@ -56,10 +56,11 @@ defaultMain getprops = go True =<< processCmdLine
go _ (Continue cmdline) = go False cmdline
go _ (Set host field) = setPrivData host field
go _ (AddKey keyid) = addKey keyid
- go _ (Spin host) = withprops host $ const $ spin host
+ go True cmdline@(Spin _) = buildFirst cmdline $ go False cmdline
go True cmdline = updateFirst cmdline $ go False cmdline
- go _ (Run host) = withprops host $ ensureProperties
- go _ (Boot host) = withprops host $ boot
+ go False (Spin host) = withprops host $ const $ spin host
+ go False (Run host) = withprops host $ ensureProperties
+ go False (Boot host) = withprops host $ boot
withprops host a = maybe (unknownhost host) a (getprops host)
@@ -69,6 +70,20 @@ unknownhost h = errorMessage $ unwords
, "(perhaps you should specify the real hostname on the command line?)"
]
+buildFirst :: CmdLine -> IO () -> IO ()
+buildFirst cmdline next = do
+ oldtime <- getmtime
+ ifM (actionMessage "Rebuilding propellor" $ boolSystem "make" [Param "build"])
+ ( do
+ newtime <- getmtime
+ if newtime == oldtime
+ then next
+ else void $ boolSystem "./propellor" [Param "--continue", Param (show cmdline)]
+ , errorMessage "Propellor build failed!"
+ )
+ where
+ getmtime = catchMaybeIO $ getModificationTime "propellor"
+
updateFirst :: CmdLine -> IO () -> IO ()
updateFirst cmdline next = do
branchref <- takeWhile (/= '\n')