Skip to content

Instantly share code, notes, and snippets.

@jflemer-ndp
Created December 6, 2019 19:12
Show Gist options
  • Save jflemer-ndp/0426fe40d09a35b1699c14cf73ba9846 to your computer and use it in GitHub Desktop.
Save jflemer-ndp/0426fe40d09a35b1699c14cf73ba9846 to your computer and use it in GitHub Desktop.
#!/bin/bash
# test each redhat subscription key against a given (repo) url
if [ -z "$1" ]; then
echo "usage: $0 <url>"
echo ""
echo "example:"
echo " $0 'https://cdn.redhat.com/content/dist/rhel/server/7/\$releasever/\$basearch/os/repodata/repomd.xml'"
exit 1
fi
url() {
local x="${1//\$basearch/x86_64}"
case "$x" in
*releasever*)
echo "${x//\$releasever/7Server}/repodata/repomd.xml"
echo "${x//\$releasever/7Server}"
echo "${x//\$releasever/7Workstation}/repodata/repomd.xml"
echo "${x//\$releasever/7Workstation}"
;;
*)
echo "$x/repodata/repomd.xml"
echo "$x"
;;
esac
}
for u in $(url "$1"); do
for i in /etc/pki/entitlement/*key.pem; do
id=$(basename "${i%%-key.pem}")
echo "==> $id $u"
curl --fail --cert /etc/pki/entitlement/${id}.pem --key /etc/pki/entitlement/${id}-key.pem -k $u >/dev/null 2>&1 && echo "$id $u" && exit 0
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment