Skip to content

Commit

Permalink
Remove accepting keys from the environment
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabedini committed Mar 16, 2022
1 parent 8d09cff commit 5ce3fc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
11 changes: 10 additions & 1 deletion app/Foliage/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,3 +32,11 @@ optionsParser =
<> showDefault
<> value "config.toml"
)
<*> strOption
( long "keys"
<> metavar "KEYS"
<> help "Keys folder"
<> showDefault
<> value "_keys"
)

21 changes: 7 additions & 14 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ cabal = command1_ "cabal" []

main :: IO ()
main = do
Options {optionsConfig} <- parseOptions
Options {optionsConfig, optionsKeys} <- parseOptions

eConfig <- readConfig optionsConfig

case eConfig of
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"
Expand All @@ -44,7 +44,7 @@ makeRepository sources = shelly $ do
mkdir outDir
mkdir pkgDir

keysDir <- absPath "_keys"
keysDir <- absPath keysPath
ensureKeys keysDir

forM_ sources $ processSource pkgDir
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5ce3fc0

Please sign in to comment.