summaryrefslogtreecommitdiff
path: root/Propellor/CmdLine.hs
diff options
context:
space:
mode:
authorJoey Hess2014-04-03 13:58:21 -0400
committerJoey Hess2014-04-03 13:58:21 -0400
commitb14b56d84a448664bb86cde8079812ff11a9a79d (patch)
treeeffe4010302eec431ae38bec2380b2ab214ff0dd /Propellor/CmdLine.hs
parente1c42aeeb1770b42373ae04ef21c897248f62380 (diff)
propellor spin
Diffstat (limited to 'Propellor/CmdLine.hs')
-rw-r--r--Propellor/CmdLine.hs17
1 files changed, 4 insertions, 13 deletions
diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs
index f1c002ac..a9c61993 100644
--- a/Propellor/CmdLine.hs
+++ b/Propellor/CmdLine.hs
@@ -68,24 +68,15 @@ defaultMain getprops = do
go True cmdline@(Spin _) = buildFirst cmdline $ go False cmdline
go True cmdline = updateFirst cmdline $ go False cmdline
go False (Spin host) = withprops host $ const $ spin host
- go False cmdline@(Run host) = withprops host $
- asRoot cmdline . ensureProperties
+ go False (Run host) = ifM ((==) 0 <$> getRealUserID)
+ ( withprops host ensureProperties
+ , go True (Spin host)
+ )
go False (Boot host) = withprops host $ boot
withprops host a = maybe (unknownhost host) a $
headMaybe $ catMaybes $ map (\get -> get host) getprops
-asRoot :: CmdLine -> IO a -> IO a
-asRoot cmdline a = ifM ((==) 0 <$> getRealUserID)
- ( a
- , do
- hPutStrLn stderr "Need to be root to provision the local host! Running sudo propellor..."
- hFlush stderr
- (_, _, _, pid) <- createProcess $
- proc "sudo" ["./propellor", show (Continue cmdline)]
- exitWith =<< waitForProcess pid
- )
-
unknownhost :: HostName -> IO a
unknownhost h = errorMessage $ unlines
[ "Unknown host: " ++ h