From e170189b23724d8f8b610d5dcb80c35a16f5fd0a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 31 Mar 2014 18:53:27 -0400 Subject: propellor spin --- Propellor/CmdLine.hs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'Propellor/CmdLine.hs') 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') -- cgit v1.2.3