module FedoraDists
(Dist(..),
dists,
distBranch,
distContainer,
distRepo,
distUpdates,
distOverride,
kojicmd,
mockConfig,
releaseVersion,
rawhide,
rawhideRelease,
rpkg,
rpmDistTag) where
import Data.Version
import Text.Read
#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-" ++ show v
instance Read Dist where
readPrec = choice [pFedora, pEPEL, pRHEL] where
pChar c = do
c' <- get
if c == c'
then return c
else pfail
pFedora = Fedora <$> (pChar 'f' *> readPrec)
pEPEL = EPEL <$> (traverse pChar "epel" *> readPrec)
pRHEL = RHEL <$> (traverse pChar "rhel-" *> readPrec)
readListPrec = readListPrecDefault
dists :: [Dist]
dists = [rawhide, Fedora 31, Fedora 30, Fedora 29, EPEL 8, EPEL 7, EPEL 6]
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 =
distRepo dist ++ "-" ++ 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"