summaryrefslogtreecommitdiff
path: root/Propellor/CmdLine.hs
diff options
context:
space:
mode:
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')