Update additional download versions in slackbuild

This commit is contained in:
Eugen Wissner 2023-11-01 19:07:49 +01:00
parent 64233c4c63
commit 24e62c3439
3 changed files with 16 additions and 14 deletions

View File

@ -385,7 +385,7 @@ updatePackage package@Package{..} info version = do
, checksums = getField @"md5sum" <$> allDownloads , checksums = getField @"md5sum" <$> allDownloads
} }
liftIO $ Text.IO.writeFile infoFilePath $ generate package' liftIO $ Text.IO.writeFile infoFilePath $ generate package'
updateSlackBuildVersion packagePath version updateSlackBuildVersion packagePath version $ snd <$> moreDownloads
commit packagePath version commit packagePath version
@ -416,8 +416,6 @@ main = do
categories <- liftIO $ findCategory repository' categories <- liftIO $ findCategory repository'
liftIO $ print $ splitFileName . makeRelative repository' <$> categories liftIO $ print $ splitFileName . makeRelative repository' <$> categories
pure Nothing pure Nothing
SlackBuildCommand packagePath version ->
updateSlackBuildVersion packagePath version >> pure Nothing
CommitCommand packagePath version -> CommitCommand packagePath version ->
commit packagePath version >> pure Nothing commit packagePath version >> pure Nothing
ExistsCommand urlPath -> pure . Text.pack . show ExistsCommand urlPath -> pure . Text.pack . show

View File

@ -21,7 +21,6 @@ import Options.Applicative
data SlackBuilderCommand data SlackBuilderCommand
= CategoryCommand Text = CategoryCommand Text
| SlackBuildCommand Text Text
| CommitCommand Text Text | CommitCommand Text Text
| ExistsCommand Text | ExistsCommand Text
| ArchiveCommand Text Text String Text | ArchiveCommand Text Text String Text
@ -52,7 +51,6 @@ slackBuilderParser = info slackBuilderCommand fullDesc
slackBuilderCommand :: Parser SlackBuilderCommand slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser slackBuilderCommand = subparser
$ command "category" (info categoryCommand mempty) $ command "category" (info categoryCommand mempty)
<> command "slackbuild" (info slackBuildCommand mempty)
<> command "commit" (info commitCommand mempty) <> command "commit" (info commitCommand mempty)
<> command "exists" (info existsCommand mempty) <> command "exists" (info existsCommand mempty)
<> command "archive" (info archiveCommand mempty) <> command "archive" (info archiveCommand mempty)
@ -63,9 +61,6 @@ slackBuilderCommand = subparser
where where
categoryCommand = CategoryCommand categoryCommand = CategoryCommand
<$> argument str (metavar "PKGNAM") <$> argument str (metavar "PKGNAM")
slackBuildCommand = SlackBuildCommand
<$> argument str (metavar "PATH")
<*> argument str (metavar "VERSION")
commitCommand = CommitCommand commitCommand = CommitCommand
<$> argument str (metavar "PATH") <$> argument str (metavar "PATH")
<*> argument str (metavar "VERSION") <*> argument str (metavar "VERSION")

View File

@ -12,6 +12,8 @@ module SlackBuilder.Download
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import qualified Data.ByteString as ByteString import qualified Data.ByteString as ByteString
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import qualified Data.Text.IO as Text.IO import qualified Data.Text.IO as Text.IO
@ -59,19 +61,26 @@ import Conduit
import Crypto.Hash (Digest, MD5, hashInit, hashFinalize, hashUpdate) import Crypto.Hash (Digest, MD5, hashInit, hashFinalize, hashUpdate)
import Data.Void (Void) import Data.Void (Void)
updateSlackBuildVersion :: Text -> Text -> SlackBuilderT () updateSlackBuildVersion :: Text -> Text -> Map Text Text -> SlackBuilderT ()
updateSlackBuildVersion packagePath version = do updateSlackBuildVersion packagePath version additionalDownloads = do
repository' <- SlackBuilderT $ asks repository repository' <- SlackBuilderT $ asks repository
let name = Text.unpack $ snd $ Text.breakOnEnd "/" packagePath let name = Text.unpack $ snd $ Text.breakOnEnd "/" packagePath
slackbuildFilename = repository' slackbuildFilename = repository'
</> Text.unpack packagePath </> Text.unpack packagePath
</> (name <.> "SlackBuild") </> (name <.> "SlackBuild")
slackbuildContents <- liftIO $ Text.IO.readFile slackbuildFilename slackbuildContents <- liftIO $ Text.IO.readFile slackbuildFilename
let (contentsHead, contentsTail) = Text.dropWhile (/= '\n') let slackbuildLines = replaceLine . updateLineVariable "VERSION" version
<$> Text.breakOn "VERSION=${VERSION:-" slackbuildContents <$> Text.lines slackbuildContents
liftIO $ Text.IO.writeFile slackbuildFilename liftIO $ Text.IO.writeFile slackbuildFilename $ Text.unlines slackbuildLines
$ contentsHead <> "VERSION=${VERSION:-" <> version <> "}" <> contentsTail where
replaceLine line = Map.foldrWithKey updateLineDependencyVersion line additionalDownloads
updateLineDependencyVersion dependencyName = updateLineVariable
$ dependencyName <> "_VERSION"
updateLineVariable variableName variableValue line
| Text.isSuffixOf (variableName <> "=") line =
variableName <> "=${" <> variableName <> ":-" <> variableValue <> "}"
| otherwise = line
commit :: Text -> Text -> SlackBuilderT () commit :: Text -> Text -> SlackBuilderT ()
commit packagePath version = do commit packagePath version = do