module FedoraDists
(Dist(..),
dists,
distBranch,
distContainer,
distRepo,
distUpdates,
distOverride,
kojicmd,
mockConfig,
releaseVersion,
rawhide,
rawhideRelease,
rpkg,
rpmDistTag) where
import Data.Version
import Text.Read
import Text.ParserCombinators.ReadP (char, eof, string)
#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,0))
#else
import Control.Applicative ((<$>), (*>))
import Data.Traversable (traverse)
#endif
data Dist = Fedora Int
| EPEL Int
| RHEL Version
deriving (Eq)
instance Show Dist where
show (Fedora n) = "f" ++ show n
show (EPEL n) = (if n <= 6 then "el" else "epel") ++ show n
show (RHEL v) = "rhel-" ++ showVersion v
instance Read Dist where
readPrec = choice [pFedora, pEPEL, pRHEL] where
pFedora = Fedora <$> (lift (char 'f') *> readPrec)
pEPEL = EPEL <$> (lift (string "epel") *> readPrec)
pRHEL = RHEL <$> lift (do
v <- string "rhel-" >> parseVersion
eof
return v)
dists :: [Dist]
dists = [rawhide, Fedora 31, Fedora 30, EPEL 8, EPEL 7]
rawhideRelease :: Int
rawhideRelease = 32
rawhide :: Dist
rawhide = Fedora rawhideRelease
distBranch :: Dist -> String
distBranch (Fedora n) | n >= rawhideRelease = "master"
distBranch d = show d
distRepo :: Dist -> String
distRepo (Fedora n) | n >= rawhideRelease = "rawhide"
| otherwise = "fedora"
distRepo (EPEL _) = "epel"
distRepo (RHEL _) = "rhel"
distUpdates :: Dist -> Maybe String
distUpdates (Fedora n) | n >= rawhideRelease = Nothing
distUpdates (Fedora _) = Just "updates"
distUpdates _ = Nothing
distOverride :: Dist -> Bool
distOverride d = d `notElem` [rawhide, Fedora 32 , EPEL 9]
releaseVersion :: Dist -> String
releaseVersion (Fedora n) | n >= rawhideRelease = "rawhide"
releaseVersion (Fedora n) = show n
releaseVersion (EPEL n) = show n
releaseVersion (RHEL n) = show n
rpmDistTag :: Dist -> String
rpmDistTag (Fedora n) = ".fc" ++ show n
rpmDistTag (RHEL v) = ".el" ++ (show . head . versionBranch) v
rpmDistTag d = '.' : show d
kojicmd :: Dist -> String
kojicmd (RHEL _) = "brew"
kojicmd _ = "koji"
rpkg :: Dist -> String
rpkg (RHEL _) = "rhpkg"
rpkg _ = "fedpkg"
mockConfig :: Dist -> String -> String
mockConfig dist arch =
let prefix =
case dist of
Fedora _ -> "fedora"
_ -> distRepo dist
in
prefix ++ "-" ++ releaseVersion dist ++ "-" ++ arch
distContainer :: Dist -> String
distContainer (Fedora n) = "fedora:" ++ show n
distContainer (EPEL n) = "centos:" ++ show n
distContainer (RHEL n) = "ubi" ++ show n ++ "/ubi"