YumRepoXmlParsing

18th October 2016 at 10:55am
TechnicalNotes

The following snippet will output the package group / components XML filename:

curl -s "http://server/centos-7-x86_64/repomod/repomd.xml" \
  | xmlstarlet sel \
      -N _="http://linux.duke.edu/metadata/repo" \
      -t -m '//_:data[@type="group"]/_:location[@href]' \
      -v @href

Which should look something like this:

repodata/e6ace3f46288a007c9ea04010040534b1767f5a4ab306769f86a7ef2461d3192-comps.xml

Older versions of xmlstarlet do not seem to understand what the default namespace of a document is, and/or assign it to the same name. Some versions bind it to _, while others bind it to DEFAULT. To work around this, you can explicitly bind the namespace by hand with the -N argument.

See http://xmlstar.sourceforge.net/doc/UG/ch05.html for more details.

Alternatively, you can flatten the repomd.xml XML data using the xml2 command, and then simply grep for the full path that you are interested in.

curl -s "http://server/centos-7-x86_64/repomod/repomd.xml" | xml2
/repomd/@xmlns=http://linux.duke.edu/metadata/repo
/repomd/@xmlns:rpm=http://linux.duke.edu/metadata/rpm
/repomd/revision=1475847433
/repomd/data/@type=filelists
/repomd/data/location/@href=repodata/d30f9924ab4a416de683d3bbce1b8bcea5ded61e19d3877b7e64afbe5c63f77a-filelists.xml.gz
/repomd/data/timestamp=1475847433
/repomd/data/size=6419912
/repomd/data/checksum/@type=sha256
/repomd/data/checksum=d30f9924ab4a416de683d3bbce1b8bcea5ded61e19d3877b7e64afbe5c63f77a
/repomd/data/open-size=89994014
/repomd/data/open-checksum/@type=sha256
/repomd/data/open-checksum=3b8c214704d121078aee644405314e3ca7e6f90c1808f2f7b4853f35bd9f9b0c
...
...
...
/repomd/data
/repomd/data/@type=group
/repomd/data/location/@href=repodata/e6ace3f46288a007c9ea04010040534b1767f5a4ab306769f86a7ef2461d3192-comps.xml
/repomd/data/timestamp=1475847433
/repomd/data/size=704185
/repomd/data/checksum/@type=sha256
/repomd/data/checksum=e6ace3f46288a007c9ea04010040534b1767f5a4ab306769f86a7ef2461d3192

The example repomd.xml XML used here was:

<?xml version="1.0" encoding="UTF-8"?>
<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm"><revision>1474317202</revision>
<data type="filelists"><location href="repodata/ec27578a5c6c57926eb94229b67f31b909928c71d177cdb6566b589e94f85062-filelists.xml.gz" /><timestamp>1474317212</timestamp><size>6419912</size><checksum type="sha256">ec27578a5c6c57926eb94229b67f31b909928c71d177cdb6566b589e94f85062</checksum><open-size>89994014</open-size><open-checksum type="sha256">3b8c214704d121078aee644405314e3ca7e6f90c1808f2f7b4853f35bd9f9b0c</open-checksum></data>
<data type="other"><location href="repodata/d74f64bdab16c71cc9f24e9d13986a99166cd70450a1f668828af926c25e0fa1-other.xml.gz" /><timestamp>1474317214</timestamp><size>1538268</size><checksum type="sha256">d74f64bdab16c71cc9f24e9d13986a99166cd70450a1f668828af926c25e0fa1</checksum><open-size>18373785</open-size><open-checksum type="sha256">4a0b87466a00a00bf020cb2f7a74577e0c9e36a2bfcafaffb331eaccb4eab9f0</open-checksum></data>
<data type="primary"><location href="repodata/c8b494f1d9159695bc80b39f7846418e9357aeb2a87d51a615f2fc4bbcf94412-primary.xml.gz" /><timestamp>1474317214</timestamp><size>2631025</size><checksum type="sha256">c8b494f1d9159695bc80b39f7846418e9357aeb2a87d51a615f2fc4bbcf94412</checksum><open-size>24288660</open-size><open-checksum type="sha256">dc9fde042ab8958c1f3a1516450fa2136a7ca14d306a44056bc384d30c2acfd9</open-checksum></data>
<data type="updateinfo"><location href="repodata/129d2078d0876bc8d1900c70e0e537031222a523c6366af69bebdeec8c375932-updateinfo.xml.gz" /><timestamp>1474317215</timestamp><size>93</size><checksum type="sha256">129d2078d0876bc8d1900c70e0e537031222a523c6366af69bebdeec8c375932</checksum><open-size>60</open-size><open-checksum type="sha256">c12d66b45503fbedd6f6211054309902124b1e254cdc7634961025d5d7aaa1ed</open-checksum></data>
<data type="group"><location href="repodata/e6ace3f46288a007c9ea04010040534b1767f5a4ab306769f86a7ef2461d3192-comps.xml" /><timestamp>1474317215</timestamp><size>704185</size><checksum type="sha256">e6ace3f46288a007c9ea04010040534b1767f5a4ab306769f86a7ef2461d3192</checksum></data>
</repomd>