diff options
| author | Joey Hess <joey@kitenet.net> | 2014-11-18 15:05:15 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-11-18 15:05:15 -0400 |
| commit | bad6a8c3e641894c900f195c23092a528853c904 (patch) | |
| tree | 5fbae1c0afb97a2ecf41ffb68facd73f072a4536 /src/Propellor/CmdLine.hs | |
| parent | 38fc71077dd774fc4078993daacfd836bad55fdc (diff) | |
propellor spin
Diffstat (limited to 'src/Propellor/CmdLine.hs')
| -rw-r--r-- | src/Propellor/CmdLine.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs index 21ae1c42..49c1dc4d 100644 --- a/src/Propellor/CmdLine.hs +++ b/src/Propellor/CmdLine.hs @@ -11,6 +11,8 @@ import System.PosixCompat import Control.Exception (bracket) import System.Posix.IO import Data.Time.Clock.POSIX +import Control.Concurrent.Async +import qualified Data.ByteString as B import Propellor import Propellor.Protocol @@ -54,6 +56,7 @@ processCmdLine = go =<< getArgs Nothing -> errorMessage "--continue serialization failure" go ("--chain":h:[]) = return $ Chain h go ("--docker":h:[]) = return $ Docker h + go ("--gitpush":fin:fout:_) = return $ GitPush (Prelude.read fin) (Prelude.read fout) go (h:[]) | "--" `isPrefixOf` h = usage | otherwise = return $ Run h @@ -86,6 +89,7 @@ defaultMain hostlist = do r <- runPropellor h $ ensureProperties $ hostProperties h putStrLn $ "\n" ++ show r go _ (Docker hn) = Docker.chain hn + go _ (GitPush fin fout) = gitPush fin fout go True cmdline@(Spin _) = buildFirst cmdline $ go False cmdline go True cmdline = updateFirst cmdline $ go False cmdline go False (Spin hn) = withhost hn $ spin hn @@ -206,6 +210,12 @@ spin hn hst = do Just NeedPrivData -> do sendprivdata toh privdata loop + Just NeedGitPush -> do + sendMarked toh gitPushMarker "" + unlessM (boolSystem "git" [Param "send-pack", Param "--thin", Param "."]) $ + warningMessage "git send-pack failed" + -- no more protocol possible after + -- git push Just NeedGitClone -> do hClose toh hClose fromh @@ -283,6 +293,28 @@ boot = do makePrivDataDir req NeedPrivData privDataMarker $ writeFileProtected privDataLocal + req NeedGitPush gitPushMarker $ \_ -> do + hin <- dup stdInput + hClose stdin + hout <- dup stdOutput + hClose stdout + unlessM (boolSystem "git" [Param "pull", Param $ "--upload=pack=./propellor gitpush " ++ show hin ++ " " ++ show hout, Param "."]) $ + warningMessage "git pull from client failed" + +-- Shim for git push over the propellor ssh channel. +-- Reads from stdin and sends it to the first fd; +-- reads from the second fd and sends it to stdout. +gitPush :: Fd -> Fd -> IO () +gitPush hin hout = do + print ("gitPush", hin, hout) + void $ fromstdin `concurrently` tostdout + where + fromstdin = do + h <- fdToHandle hin + B.getContents >>= B.hPut h + tostdout = do + h <- fdToHandle hout + B.hGetContents h >>= B.putStr setRepoUrl :: String -> IO () setRepoUrl "" = return () |
