propellor spin

This commit is contained in:
Joey Hess 2014-03-31 14:41:40 -04:00
parent 48b3c546b7
commit ac76e80fa2
Failed to extract signature
4 changed files with 13 additions and 31 deletions

View File

@ -11,7 +11,7 @@ build: deps dist/setup-config
ln -sf dist/build/propellor/propellor
deps:
@if [ $$(whoami) = root ]; then apt-get -y install gnupg ghc cabal-install libghc-missingh-dev libghc-ansi-terminal-dev libghc-ifelse-dev libghc-unix-compat-dev libghc-hslogger-dev libghc-dataenc-dev; fi || true
@if [ $$(whoami) = root ]; then apt-get -y install gnupg ghc cabal-install libghc-missingh-dev libghc-ansi-terminal-dev libghc-ifelse-dev libghc-unix-compat-dev libghc-hslogger-dev libghc-base64-bytestring-dev; fi || true
dist/setup-config: propellor.cabal
cabal configure

View File

@ -3,11 +3,14 @@ module Propellor.CmdLine where
import System.Environment
import Data.List
import System.Exit
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Base64.Lazy as B64
import Data.Bits.Utils
import Propellor
import Utility.FileMode
import Utility.SafeCommand
import Utility.Base64
import Utility.Data
data CmdLine
= Run HostName
@ -73,7 +76,8 @@ spin host = do
NeedKeyRing -> do
putStr $ "Sending " ++ keyring ++ " to " ++ host ++ "..."
hFlush stdout
s <- toB64 <$> readFile keyring
s <- w82s . BL.unpack . B64.encode
<$> BL.readFile keyring
putStrLn $ show $ toMarked keyringMarker s
hFlush stdout
hPutStrLn toh $ toMarked keyringMarker s
@ -153,8 +157,11 @@ boot props = do
makePrivDataDir
maybe noop (writeFileProtected privDataLocal) $
fromMarked privDataMarker reply
maybe noop (writeFileProtected keyring) $
fromB64Maybe =<< fromMarked keyringMarker reply
case eitherToMaybe . B64.decode . BL.pack . s2w8 =<< fromMarked keyringMarker reply of
Nothing -> noop
Just d -> do
writeFileProtected keyring ""
BL.writeFile keyring d
ensureProperties props
addKey :: String -> IO ()

View File

@ -1,24 +0,0 @@
{- Simple Base64 access
-
- Copyright 2011 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Utility.Base64 (toB64, fromB64Maybe, fromB64) where
import "dataenc" Codec.Binary.Base64
import Data.Bits.Utils
import Control.Applicative
import Data.Maybe
toB64 :: String -> String
toB64 = encode . s2w8
fromB64Maybe :: String -> Maybe String
fromB64Maybe s = w82s <$> decode s
fromB64 :: String -> String
fromB64 = fromMaybe bad . fromB64Maybe
where
bad = error "bad base64 encoded data"

View File

@ -29,7 +29,7 @@ Executable propellor
Extensions: PackageImports
Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5,
IfElse, process, bytestring, hslogger, unix-compat, ansi-terminal,
containers, dataenc
containers, base64-bytestring
if (! os(windows))
Build-Depends: unix
@ -67,7 +67,6 @@ Library
Propellor.Types
Other-Modules:
Utility.Applicative
Utility.Base64
Utility.Data
Utility.Directory
Utility.Env