Combine info file structures
This commit is contained in:
parent
7b5598a02e
commit
f3beee3e19
29
Rakefile
29
Rakefile
@ -83,36 +83,7 @@ task 'rdiff-backup', [:version] do |_, arguments|
|
|||||||
commit 'system/rdiff-backup', arguments[:version]
|
commit 'system/rdiff-backup', arguments[:version]
|
||||||
end
|
end
|
||||||
|
|
||||||
module SlackBuilder
|
|
||||||
class Updater
|
|
||||||
include Rake::FileUtilsExt
|
|
||||||
|
|
||||||
def update(version)
|
|
||||||
raise NotImplementedError
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class PHP < Updater
|
|
||||||
def update(version)
|
|
||||||
package = Package.new 'development/php82',
|
|
||||||
version: version,
|
|
||||||
homepage: 'https://www.php.net/',
|
|
||||||
requires: ['postgresql']
|
|
||||||
|
|
||||||
uri = "https://www.php.net/distributions/php-#{version}.tar.xz"
|
|
||||||
tarball = "slackbuilds/development/php82/php-#{version}.tar.xz"
|
|
||||||
checksum = SlackBuilder.download URI(uri), tarball
|
|
||||||
|
|
||||||
write_info package, downloads: [Download.new(uri, checksum)]
|
|
||||||
update_slackbuild_version 'development/php82', version
|
|
||||||
|
|
||||||
commit 'development/php82', version
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
AUTO_UPDATABLE = {
|
AUTO_UPDATABLE = {
|
||||||
'php82' => [SlackBuilder::GitHub.new('php', 'php-src', 'php'), SlackBuilder::PHP.new],
|
|
||||||
'rdiff-backup' => [SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup', 'rdiff-backup')],
|
'rdiff-backup' => [SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup', 'rdiff-backup')],
|
||||||
'librsync' => [SlackBuilder::GitHub.new('librsync', 'librsync')],
|
'librsync' => [SlackBuilder::GitHub.new('librsync', 'librsync')],
|
||||||
'dmd' => [SlackBuilder::LatestText.new('https://downloads.dlang.org/releases/LATEST')]
|
'dmd' => [SlackBuilder::LatestText.new('https://downloads.dlang.org/releases/LATEST')]
|
||||||
|
50
app/Main.hs
50
app/Main.hs
@ -15,28 +15,20 @@ import qualified Toml
|
|||||||
import qualified Data.ByteString as ByteString
|
import qualified Data.ByteString as ByteString
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
|
import qualified Data.Text.Encoding as Text.Encoding
|
||||||
import qualified Data.Text.IO as Text.IO
|
import qualified Data.Text.IO as Text.IO
|
||||||
import Control.Monad.Trans.Reader (ReaderT(..), asks)
|
import Control.Monad.Trans.Reader (ReaderT(..), asks)
|
||||||
import SlackBuilder.Download
|
import SlackBuilder.Download
|
||||||
|
import SlackBuilder.Package (Package(..))
|
||||||
import qualified SlackBuilder.Package as Package
|
import qualified SlackBuilder.Package as Package
|
||||||
import Text.URI (mkURI, URI)
|
import Text.URI (mkURI)
|
||||||
import Text.URI.QQ (uri)
|
import Text.URI.QQ (uri)
|
||||||
import Data.Foldable (for_)
|
import Data.Foldable (for_)
|
||||||
import qualified Text.URI as URI
|
import qualified Text.URI as URI
|
||||||
import GHC.Records (HasField(..))
|
|
||||||
import System.FilePath ((</>), (<.>))
|
import System.FilePath ((</>), (<.>))
|
||||||
import SlackBuilder.Info
|
import SlackBuilder.Info
|
||||||
import Text.Megaparsec (parse, errorBundlePretty)
|
import Text.Megaparsec (parse, errorBundlePretty)
|
||||||
|
|
||||||
data Package = Package
|
|
||||||
{ latest :: Package.Updater
|
|
||||||
, category :: Text
|
|
||||||
, name :: Text
|
|
||||||
, homepage :: Maybe URI
|
|
||||||
, requires :: [Text]
|
|
||||||
, reupload :: Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
autoUpdatable :: [Package]
|
autoUpdatable :: [Package]
|
||||||
autoUpdatable =
|
autoUpdatable =
|
||||||
[ Package
|
[ Package
|
||||||
@ -55,7 +47,7 @@ autoUpdatable =
|
|||||||
in Package.Updater latest' template
|
in Package.Updater latest' template
|
||||||
, category = "development"
|
, category = "development"
|
||||||
, name = "universal-ctags"
|
, name = "universal-ctags"
|
||||||
, homepage = Just [uri|https://ctags.io/|]
|
, homepage = [uri|https://ctags.io/|]
|
||||||
, requires = pure "%README%"
|
, requires = pure "%README%"
|
||||||
, reupload = True
|
, reupload = True
|
||||||
}
|
}
|
||||||
@ -69,7 +61,7 @@ autoUpdatable =
|
|||||||
in Package.Updater latest' template
|
in Package.Updater latest' template
|
||||||
, category = "development"
|
, category = "development"
|
||||||
, name = "composer"
|
, name = "composer"
|
||||||
, homepage = Just [uri|https://getcomposer.org/|]
|
, homepage = [uri|https://getcomposer.org/|]
|
||||||
, requires = mempty
|
, requires = mempty
|
||||||
, reupload = False
|
, reupload = False
|
||||||
}
|
}
|
||||||
@ -88,7 +80,7 @@ autoUpdatable =
|
|||||||
in Package.Updater latest' template
|
in Package.Updater latest' template
|
||||||
, category = "network"
|
, category = "network"
|
||||||
, name = "jitsi-meet-desktop"
|
, name = "jitsi-meet-desktop"
|
||||||
, homepage = Just [uri|https://jitsi.org/|]
|
, homepage = [uri|https://jitsi.org/|]
|
||||||
, requires = mempty
|
, requires = mempty
|
||||||
, reupload = False
|
, reupload = False
|
||||||
}
|
}
|
||||||
@ -110,7 +102,7 @@ autoUpdatable =
|
|||||||
in Package.Updater latest' template
|
in Package.Updater latest' template
|
||||||
, category = "development"
|
, category = "development"
|
||||||
, name = "php82"
|
, name = "php82"
|
||||||
, homepage = Just [uri|https://www.php.net/|]
|
, homepage = [uri|https://www.php.net/|]
|
||||||
, requires = ["postgresql"]
|
, requires = ["postgresql"]
|
||||||
, reupload = False
|
, reupload = False
|
||||||
}
|
}
|
||||||
@ -131,23 +123,12 @@ updatePackageIfRequired package@Package{..} version = do
|
|||||||
infoContents <- liftIO $ ByteString.readFile $ repository' </> packagePath
|
infoContents <- liftIO $ ByteString.readFile $ repository' </> packagePath
|
||||||
|
|
||||||
case parse parseInfoFile packagePath infoContents of
|
case parse parseInfoFile packagePath infoContents of
|
||||||
Right _parsedInfoFile -> updatePackage package version
|
Right parsedInfoFile -> updatePackage package parsedInfoFile version
|
||||||
Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
|
Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
|
||||||
|
|
||||||
updatePackage :: Package -> Text -> SlackBuilderT ()
|
updatePackage :: Package -> PackageInfo -> Text -> SlackBuilderT ()
|
||||||
updatePackage Package{..} version = do
|
updatePackage Package{..} info version = do
|
||||||
maintainer' <- SlackBuilderT $ asks $ getField @"maintainer"
|
|
||||||
let packagePath = category <> "/" <> name
|
let packagePath = category <> "/" <> name
|
||||||
package' = Package.PackageInfo
|
|
||||||
{ version = version
|
|
||||||
, requires = requires
|
|
||||||
, path = Text.unpack packagePath
|
|
||||||
, homepage = maybe "" URI.render homepage
|
|
||||||
, maintainer = Package.Maintainer
|
|
||||||
{ name = getField @"name" maintainer'
|
|
||||||
, email = getField @"email" maintainer'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Package.Updater _ downloadTemplate = latest
|
Package.Updater _ downloadTemplate = latest
|
||||||
|
|
||||||
repository' <- SlackBuilderT $ asks repository
|
repository' <- SlackBuilderT $ asks repository
|
||||||
@ -162,9 +143,15 @@ updatePackage Package{..} version = do
|
|||||||
download' <- handleReupload uri' relativeTarball downloadFileName
|
download' <- handleReupload uri' relativeTarball downloadFileName
|
||||||
let infoFilePath = repository' </> Text.unpack packagePath
|
let infoFilePath = repository' </> Text.unpack packagePath
|
||||||
</> (Text.unpack name <.> "info")
|
</> (Text.unpack name <.> "info")
|
||||||
|
package' = info
|
||||||
|
{ version = version
|
||||||
|
, requires = Text.Encoding.encodeUtf8 <$> requires
|
||||||
|
, homepage = URI.render homepage
|
||||||
|
, downloads = [download']
|
||||||
|
, checksums = [checksum]
|
||||||
|
}
|
||||||
|
|
||||||
liftIO $ Text.IO.writeFile infoFilePath
|
liftIO $ Text.IO.writeFile infoFilePath $ generate package'
|
||||||
$ Package.infoTemplate package' [Package.Download download' checksum False]
|
|
||||||
updateSlackBuildVersion packagePath version
|
updateSlackBuildVersion packagePath version
|
||||||
|
|
||||||
commit packagePath version
|
commit packagePath version
|
||||||
@ -176,7 +163,6 @@ updatePackage Package{..} version = do
|
|||||||
>> liftIO (mkURI $ "https://download.dlackware.com/hosted-sources/" <> name <> "/" <> downloadFileName)
|
>> liftIO (mkURI $ "https://download.dlackware.com/hosted-sources/" <> name <> "/" <> downloadFileName)
|
||||||
| otherwise = pure uri'
|
| otherwise = pure uri'
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
programCommand <- execParser slackBuilderParser
|
programCommand <- execParser slackBuilderParser
|
||||||
|
@ -79,7 +79,7 @@ packageChecksums variableName = string (variableName <> "=\"")
|
|||||||
|
|
||||||
packageRequires :: GenParser [ByteString]
|
packageRequires :: GenParser [ByteString]
|
||||||
packageRequires = string "REQUIRES=\""
|
packageRequires = string "REQUIRES=\""
|
||||||
*> sepBy packageName space
|
*> sepBy (packageName <|> string "%README%") space
|
||||||
<* string "\"\n"
|
<* string "\"\n"
|
||||||
|
|
||||||
packageName :: GenParser ByteString
|
packageName :: GenParser ByteString
|
||||||
@ -169,11 +169,18 @@ generate pkg = Lazy.Text.toStrict $ Text.Builder.toLazyText builder
|
|||||||
hexAppender x acc
|
hexAppender x acc
|
||||||
| x > 15 = showHex x acc
|
| x > 15 = showHex x acc
|
||||||
| otherwise = '0' : showHex x acc
|
| otherwise = '0' : showHex x acc
|
||||||
builder = "PKGNAM=\"" <> Text.Builder.fromString (pkgname pkg) <> "\"\n"
|
builder = "PRGNAM=\"" <> Text.Builder.fromString (pkgname pkg) <> "\"\n"
|
||||||
<> "VERSION=\"" <> Text.Builder.fromText (version pkg) <> "\"\n"
|
<> "VERSION=\"" <> Text.Builder.fromText (version pkg) <> "\"\n"
|
||||||
<> "HOMEPAGE=\"" <> Text.Builder.fromText (homepage pkg) <> "\"\n"
|
<> "HOMEPAGE=\"" <> Text.Builder.fromText (homepage pkg) <> "\"\n"
|
||||||
<> generateMultiEntry "DOWNLOAD" (render <$> downloads pkg)
|
<> generateMultiEntry "DOWNLOAD" (render <$> downloads pkg)
|
||||||
<> generateMultiEntry "MD5SUM" (digestToText <$> checksums pkg)
|
<> generateMultiEntry "MD5SUM" (digestToText <$> checksums pkg)
|
||||||
|
<> generateMultiEntry "DOWNLOAD_x86_64" (render <$> downloads pkg)
|
||||||
|
<> generateMultiEntry "MD5SUM_x86_64" (digestToText <$> checksums pkg)
|
||||||
|
<> "REQUIRES=\"" <> fromByteStringWords (requires pkg) <> "\"\n"
|
||||||
|
<> "MAINTAINER=\"" <> Text.Builder.fromText (maintainer pkg) <> "\"\n"
|
||||||
|
<> "EMAIL=\"" <> Text.Builder.fromText (email pkg) <> "\"\n"
|
||||||
|
fromByteStringWords = Text.Builder.fromText
|
||||||
|
. Text.unwords . fmap Text.decodeUtf8
|
||||||
|
|
||||||
generateMultiEntry :: Text -> [Text] -> Text.Builder
|
generateMultiEntry :: Text -> [Text] -> Text.Builder
|
||||||
generateMultiEntry name entries = Text.Builder.fromText name
|
generateMultiEntry name entries = Text.Builder.fromText name
|
||||||
|
@ -2,10 +2,10 @@ module SlackBuilder.Package
|
|||||||
( DownloadPlaceholder(..)
|
( DownloadPlaceholder(..)
|
||||||
, Download(..)
|
, Download(..)
|
||||||
, DownloadTemplate(..)
|
, DownloadTemplate(..)
|
||||||
|
, Package(..)
|
||||||
, PackageInfo(..)
|
, PackageInfo(..)
|
||||||
, Maintainer(..)
|
, Maintainer(..)
|
||||||
, Updater(..)
|
, Updater(..)
|
||||||
, infoTemplate
|
|
||||||
, renderDownloadWithVersion
|
, renderDownloadWithVersion
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -15,12 +15,19 @@ import qualified Data.Text as Text
|
|||||||
import Text.URI (URI(..))
|
import Text.URI (URI(..))
|
||||||
import qualified Text.URI as URI
|
import qualified Text.URI as URI
|
||||||
import Crypto.Hash (Digest, MD5)
|
import Crypto.Hash (Digest, MD5)
|
||||||
import GHC.Records (HasField(..))
|
|
||||||
import System.FilePath (takeBaseName)
|
|
||||||
import Data.List (partition)
|
|
||||||
import SlackBuilder.Trans
|
import SlackBuilder.Trans
|
||||||
import Control.Monad.Catch (MonadThrow)
|
import Control.Monad.Catch (MonadThrow)
|
||||||
|
|
||||||
|
-- | Contains information how a package can be updated.
|
||||||
|
data Package = Package
|
||||||
|
{ latest :: Updater
|
||||||
|
, category :: Text
|
||||||
|
, name :: Text
|
||||||
|
, homepage :: URI
|
||||||
|
, requires :: [Text]
|
||||||
|
, reupload :: Bool
|
||||||
|
}
|
||||||
|
|
||||||
-- | Download URI with the MD5 checksum of the target.
|
-- | Download URI with the MD5 checksum of the target.
|
||||||
data Download = Download
|
data Download = Download
|
||||||
{ download :: URI
|
{ download :: URI
|
||||||
@ -73,43 +80,3 @@ renderDownloadWithVersion (DownloadTemplate components) version =
|
|||||||
|
|
||||||
-- | Function used to get the latest version of a source.
|
-- | Function used to get the latest version of a source.
|
||||||
data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate
|
data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate
|
||||||
|
|
||||||
packageName :: PackageInfo -> Text
|
|
||||||
packageName PackageInfo{ path } = Text.pack $ takeBaseName path
|
|
||||||
|
|
||||||
infoTemplate :: PackageInfo -> [Download] -> Text
|
|
||||||
infoTemplate package downloads =
|
|
||||||
let (downloads64, downloads32) = partition (getField @"is64") downloads
|
|
||||||
(download32, md5sum32, download64, md5sum64) = downloadEntries downloads64 downloads32
|
|
||||||
|
|
||||||
in Text.unlines
|
|
||||||
[ "PRGNAM=\"" <> packageName package <> "\""
|
|
||||||
, "VERSION=\"" <> getField @"version" package <> "\""
|
|
||||||
, "HOMEPAGE=\"" <> getField @"homepage" package <> "\""
|
|
||||||
, "DOWNLOAD=\"" <> download32 <> "\""
|
|
||||||
, "MD5SUM=\"" <> md5sum32 <> "\""
|
|
||||||
, "DOWNLOAD_x86_64=\"" <> download64 <> "\""
|
|
||||||
, "MD5SUM_x86_64=\"" <> md5sum64 <> "\""
|
|
||||||
, "REQUIRES=\"" <> Text.unwords (getField @"requires" package) <> "\""
|
|
||||||
, "MAINTAINER=\"" <> getField @"name" (getField @"maintainer" package) <> "\""
|
|
||||||
, "EMAIL=\"" <> getField @"email" (getField @"maintainer" package) <> "\""
|
|
||||||
]
|
|
||||||
|
|
||||||
downloadEntries :: [Download] -> [Download] -> (Text, Text, Text, Text)
|
|
||||||
downloadEntries downloads64 downloads32 =
|
|
||||||
let download32 =
|
|
||||||
if null downloads32 && not (null downloads64)
|
|
||||||
then
|
|
||||||
"UNSUPPORTED"
|
|
||||||
else
|
|
||||||
Text.intercalate " \\\n "
|
|
||||||
$ URI.render . getField @"download" <$> downloads32
|
|
||||||
|
|
||||||
md5sum32 = Text.intercalate " \\\n "
|
|
||||||
$ Text.pack . show . getField @"md5sum" <$> downloads32
|
|
||||||
download64 = Text.intercalate " \\\n "
|
|
||||||
$ URI.render . getField @"download" <$> downloads64
|
|
||||||
md5sum64 = Text.intercalate " \\\n "
|
|
||||||
$ Text.pack . show . getField @"md5sum" <$> downloads64
|
|
||||||
|
|
||||||
in (download32, md5sum32, download64, md5sum64)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user