Skip to content

Instantly share code, notes, and snippets.

@carlwgeorge
Created September 24, 2024 19:55
Show Gist options
  • Save carlwgeorge/8eaade20b212efbe580b8e0df7501973 to your computer and use it in GitHub Desktop.
Save carlwgeorge/8eaade20b212efbe580b8e0df7501973 to your computer and use it in GitHub Desktop.
script to count the number of packages in a yum repo
#!/usr/bin/bash
set -eou pipefail
# TODO: loop multiple
if [[ $# -ne 1 ]]; then
echo "usage: $(basename $0) <baseurl>"
exit 1
fi
repo="$1"
repomd="${repo}repodata/repomd.xml"
primary_href=$(curl -s $repomd | xq -x '/repomd/data[@type="primary"]/location/@href')
case $primary_href in
*.xml.gz) compcat=zcat;;
*.xml.xz) compcat=xzcat;;
esac
primary="$repo/$primary_href"
packages=$(curl -s $primary | $compcat | xq -x '/metadata/@packages')
echo "$packages packages in $repo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment