Skip to content

Instantly share code, notes, and snippets.

@juhp
Last active April 25, 2019 11:50
Show Gist options
  • Save juhp/4d67070e3a4f0f52b8bc6ae07ddbcd11 to your computer and use it in GitHub Desktop.
Save juhp/4d67070e3a4f0f52b8bc6ae07ddbcd11 to your computer and use it in GitHub Desktop.
haskell turtle shell script to check NVRs of epel7 packages
{-# LANGUAGE OverloadedStrings #-}
import Turtle
import Data.Text (words)
rpmspecSrc qf spec = do
(_res, out) <- procStrict "rpmspec" ["-q", "--srpm", "--undefine=dist", "--qf", qf, spec] empty
return out
nvr = "%{name}-%{version}-%{release}"
checkPkg :: Turtle.FilePath -> Text -> Shell ()
checkPkg top p = do
el7 <- testdir $ branchDir "epel7"
when el7 $ do
hasSpec <- testfile $ specfile "epel7"
when hasSpec $ do
arch <- rpmspecSrc "%{arch}" $ specfile_ "epel7"
unless (arch == "noarch") $ do
el7 <- rpmspecSrc nvr (specfile_ "epel7")
(_, out) <- procStrict "koji" ["latest-pkg", "--quiet", "epel7", p] empty
when (out /= "") $ do
let cur = (head . Data.Text.words) out
when (cur == el7 <> ".el7") $ do
hasf20 <- testfile $ specfile "f20"
when hasf20 $ do
f20 <- rpmspecSrc nvr (specfile_ "f20")
if (el7 < f20)
then echo $ el7 <> " < F20 " <> f20
else do
f21 <- rpmspecSrc nvr (specfile_ "f21")
when (el7 < f21) $
echo $ el7 <> "< F21 " <> f21
where
branchDir brch = top </> fromText p </> brch
branchDir_ brch = format fp $ branchDir brch
spec = fromText p <.> "spec"
specfile brch = branchDir brch </> spec
specfile_ brch = format fp $ specfile brch
main = sh $ do
top <- pwd
arguments >>= mapM_ (checkPkg top)
@juhp
Copy link
Author

juhp commented Nov 16, 2016

not particularly pretty or clever - just putting it here for future reference

@juhp
Copy link
Author

juhp commented Nov 16, 2016

There ought to be a simple way to do awk '{print $1}' in turtle I am sure.

@miguel-negrao
Copy link

There ought to be a simple way to do awk '{print $1}' in turtle I am sure.

What about something like this ?

fmap ((!!0).Data.Text.words) myshell

@juhp
Copy link
Author

juhp commented Nov 18, 2016

Thanks

I had to use procStrict otherwise the script inproc would terminate prematurely on packages not built yet in koji!?!

@juhp
Copy link
Author

juhp commented Nov 28, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment