I'm trying to find a portable command line way to get the full configuration of a single yum repo -- without relying necessarily on the name/id of the repo or what file it's in.

I'd like to just have a pretty straight forward command -- but this is what I've cobbled together.

Let's use epel as an example, I've come up with something like: (forgive the ugly prototype)

$ yum repolist -v "$(yum info epel-release | 
   perl -ne 'print if s/^From repo\s*:\s//')" |
   perl -ne 'print if s/^Repo-filename\s*:\s//'

So, using epel-release as a way to identify which repo I care about and then finding the repo file associated with that repo.

How do I grab just the stanza in that repo file that is for epel -- no debug, no source, no other random repos appended to the file. I can imagine some beginning and ending regex magic -- starting with [<Repo-id>] and until I see the next [<Next Repo-id>] -- that's pretty easy. /start regex/../end regex/

Is there a better way?

  • Quick and dirty code would be something like ... repo=epel; sed -n "/[$repo]/,/^$/p" /etc/yum.repos.d/epel.repo but that's fragile and likely to break in the face of small changes to input file. Better would be to use something like the Perl Config::IniFiles module to parse the file properly. Perhaps depends what your end goal is. – Paul Haldane Aug 26 '16 at 15:14
  • @PaulHaldane Agreed, I was playing around with something very similar to your regex -- I was hoping to find some yum utility/command that would make this just work. Perl Config::IniFiles is a good starting point for a more robust solution. Thanks – John Westlund Aug 26 '16 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.