Remove accepting keys from the environment

This commit is contained in:
Andrea Bedini 2022-03-16 16:49:26 +08:00
parent 8d09cfffcf
commit 5ce3fc0501
No known key found for this signature in database
GPG Key ID: EE8DEB94262733BE
2 changed files with 17 additions and 15 deletions

View File

@ -17,8 +17,9 @@ parseOptions =
<> header "foliage - a builder for static Hackage repositories"
)
newtype Options = Options
data Options = Options
{ optionsConfig :: FilePath
, optionsKeys :: FilePath
}
optionsParser :: Parser Options
@ -31,3 +32,11 @@ optionsParser =
<> showDefault
<> value "config.toml"
)
<*> strOption
( long "keys"
<> metavar "KEYS"
<> help "Keys folder"
<> showDefault
<> value "_keys"
)

View File

@ -23,7 +23,7 @@ cabal = command1_ "cabal" []
main :: IO ()
main = do
Options {optionsConfig} <- parseOptions
Options {optionsConfig, optionsKeys} <- parseOptions
eConfig <- readConfig optionsConfig
@ -31,10 +31,10 @@ main = do
Left e ->
hPutStrLn stderr e
Right config ->
makeRepository (configSources config)
makeRepository (configSources config) optionsKeys
makeRepository :: MonadIO m => [Source] -> m ()
makeRepository sources = shelly $ do
makeRepository :: MonadIO m => [Source] -> FilePath -> m ()
makeRepository sources keysPath = shelly $ do
outDir <- absPath "_repo"
idxDir <- absPath "_repo/index"
pkgDir <- absPath "_repo/package"
@ -44,7 +44,7 @@ makeRepository sources = shelly $ do
mkdir outDir
mkdir pkgDir
keysDir <- absPath "_keys"
keysDir <- absPath keysPath
ensureKeys keysDir
forM_ sources $ processSource pkgDir
@ -89,15 +89,8 @@ ensureKeys keysDir = do
if b
then echo $ "Using existing keys in " <> toTextIgnore keysDir
else do
mKeys <- get_env "KEYS"
case mKeys of
Just _keys -> do
echo "Using keys from environment"
mkdir keysDir
bash_ ("echo \"$KEYS\" | base64 -d | tar xvz -C " <> keysDir) []
Nothing -> do
echo $ "Creating new repository keys in " <> toTextIgnore keysDir
liftIO $ createKeys keysDir
echo $ "Creating new repository keys in " <> toTextIgnore keysDir
liftIO $ createKeys keysDir
processSource :: FilePath -> Source -> Sh ()
processSource pkgDir (Source url subdirs) = do