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 ln -sf dist/build/propellor/propellor
deps: 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 dist/setup-config: propellor.cabal
cabal configure cabal configure

View File

@ -3,11 +3,14 @@ module Propellor.CmdLine where
import System.Environment import System.Environment
import Data.List import Data.List
import System.Exit 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 Propellor
import Utility.FileMode import Utility.FileMode
import Utility.SafeCommand import Utility.SafeCommand
import Utility.Base64 import Utility.Data
data CmdLine data CmdLine
= Run HostName = Run HostName
@ -73,7 +76,8 @@ spin host = do
NeedKeyRing -> do NeedKeyRing -> do
putStr $ "Sending " ++ keyring ++ " to " ++ host ++ "..." putStr $ "Sending " ++ keyring ++ " to " ++ host ++ "..."
hFlush stdout hFlush stdout
s <- toB64 <$> readFile keyring s <- w82s . BL.unpack . B64.encode
<$> BL.readFile keyring
putStrLn $ show $ toMarked keyringMarker s putStrLn $ show $ toMarked keyringMarker s
hFlush stdout hFlush stdout
hPutStrLn toh $ toMarked keyringMarker s hPutStrLn toh $ toMarked keyringMarker s
@ -153,8 +157,11 @@ boot props = do
makePrivDataDir makePrivDataDir
maybe noop (writeFileProtected privDataLocal) $ maybe noop (writeFileProtected privDataLocal) $
fromMarked privDataMarker reply fromMarked privDataMarker reply
maybe noop (writeFileProtected keyring) $ case eitherToMaybe . B64.decode . BL.pack . s2w8 =<< fromMarked keyringMarker reply of
fromB64Maybe =<< fromMarked keyringMarker reply Nothing -> noop
Just d -> do
writeFileProtected keyring ""
BL.writeFile keyring d
ensureProperties props ensureProperties props
addKey :: String -> IO () 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 Extensions: PackageImports
Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5, Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5,
IfElse, process, bytestring, hslogger, unix-compat, ansi-terminal, IfElse, process, bytestring, hslogger, unix-compat, ansi-terminal,
containers, dataenc containers, base64-bytestring
if (! os(windows)) if (! os(windows))
Build-Depends: unix Build-Depends: unix
@ -67,7 +67,6 @@ Library
Propellor.Types Propellor.Types
Other-Modules: Other-Modules:
Utility.Applicative Utility.Applicative
Utility.Base64
Utility.Data Utility.Data
Utility.Directory Utility.Directory
Utility.Env Utility.Env