summaryrefslogtreecommitdiff
path: root/Propellor
diff options
context:
space:
mode:
authorJoey Hess2014-03-31 14:21:14 -0400
committerJoey Hess2014-03-31 14:21:14 -0400
commit53ece3a155fb7e06af4099764c267d8cf7a7f340 (patch)
treebbc16fc2b623a2ebbf04608708bd64688051e582 /Propellor
parent20fb9057ca6be01290eaeb65d2310ccda6c76000 (diff)
propellor spin
Diffstat (limited to 'Propellor')
-rw-r--r--Propellor/CmdLine.hs19
1 files changed, 12 insertions, 7 deletions
diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs
index 44ebf529..e4a73d5b 100644
--- a/Propellor/CmdLine.hs
+++ b/Propellor/CmdLine.hs
@@ -71,6 +71,7 @@ spin host = do
status <- getstatus fromh `catchIO` error "protocol error"
case status of
NeedKeyRing -> do
+ putStrLn $ "Sending " ++ keyring ++ " to " ++ host
s <- toB64 <$> readFile keyring
hPutStrLn toh $ toMarked keyringMarker s
HaveKeyRing -> noop
@@ -100,7 +101,7 @@ spin host = do
]
getstatus :: Handle -> IO BootStrapStatus
getstatus h = maybe (getstatus h) return
- . readish . fromMarked statusMarker
+ . (readish <=< fromMarked statusMarker)
=<< hGetLine h
data BootStrapStatus = HaveKeyRing | NeedKeyRing
@@ -121,10 +122,13 @@ privDataMarker = "PRIVDATA "
toMarked :: Marker -> String -> String
toMarked marker = unlines . map (marker ++) . lines
-fromMarked :: Marker -> Marked -> String
-fromMarked marker = unlines . map (drop len) . filter (marker `isPrefixOf`) . lines
+fromMarked :: Marker -> Marked -> Maybe String
+fromMarked marker s
+ | null matches = Nothing
+ | otherwise = Just $ unlines $ map (drop len) matches
where
len = length marker
+ matches = filter (marker `isPrefixOf`) $ lines s
boot :: [Property] -> IO ()
boot props = do
@@ -133,13 +137,14 @@ boot props = do
hFlush stdout
reply <- getContents
- hPutStrLn stderr $ fromMarked keyringMarker reply
+ hPutStrLn stderr $ show $ fromMarked keyringMarker reply
hFlush stderr
makePrivDataDir
- writeFileProtected privDataLocal $ fromMarked privDataMarker reply
- maybe noop (writeFileProtected keyring) $ fromB64Maybe $
- fromMarked keyringMarker reply
+ maybe noop (writeFileProtected privDataLocal) $
+ fromMarked privDataMarker reply
+ maybe noop (writeFileProtected keyring) $
+ fromB64Maybe =<< fromMarked keyringMarker reply
ensureProperties props
addKey :: String -> IO ()