Skip to content

Instantly share code, notes, and snippets.

@rjhowe
Last active September 25, 2025 14:29
Show Gist options
  • Save rjhowe/cdd1f8e10f401037bb32eb7d880ebe4b to your computer and use it in GitHub Desktop.
Save rjhowe/cdd1f8e10f401037bb32eb7d880ebe4b to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o pipefail
# Simple Script that will display RHCOS rpms and kernel versions based on OCP version
# USAGE:
# ./ocpkg 4.8.34
# ./ocpkg 4.8 # (latest Y release will be chosen)
DEPENDENCIES=("oc" "jq")
IFS=. read -r Ver4 VerX VerY <<< "${1:-}"
STREAM="fast"
CHANNEL="${STREAM}-4.${VerX}"
# URLs
UPGRADE_API_URL="https://api.openshift.com/api/upgrades_info/v1/graph?channel=${CHANNEL}&arch=amd64"
RHCOS_RELEASE_URL="https://releases-rhcos--prod-pipeline.apps.int.prod-stable-spoke1-dc-iad2.itup.redhat.com"
# ---------------- FUNCTIONS ---------------- #
_check_dependencies () {
local dep="$1"
if ! command -v "$dep" >/dev/null 2>&1; then
echo "Error: $dep is not installed." >&2
exit 1
fi
}
_set_latest_version () {
version=$(curl -skH 'Accept: application/json' "$UPGRADE_API_URL" \
| jq -rS '
.nodes
| sort_by(.version | gsub("[a-z,A-Z,-]";"") | split(".") | map(tonumber))
| last
| .version
')
}
_main () {
export VERSION="${version}"
RELEASE_IMAGE=$(curl -skH 'Accept: application/json' "$UPGRADE_API_URL" \
| jq -r --arg VERSION "$VERSION" -S '
.nodes
| sort_by(.version | gsub("[a-z,A-Z,-]";"") | split(".") | map(tonumber))
| .[] | select(.version == $VERSION)
| .payload
')
RHCOS_VERSION=$(oc adm release info "$RELEASE_IMAGE" -o json 2>/dev/null \
| jq -r '.displayVersions."machine-os".Version')
KUBE_VERSION=$(oc adm release info "$RELEASE_IMAGE" -o json 2>/dev/null \
| jq -r '.displayVersions.kubernetes.Version')
# Base path for commitmeta.json
case $VerX in
''|*[!0-9]*)
echo "Error: VerX must be a number" >&2
exit 1
;;
[0-9]|1[0-2]) # 0–9 and 10–12
RHCOS_META_URL="${RHCOS_RELEASE_URL}/storage/prod/streams/4.${VerX}/builds/${RHCOS_VERSION}/x86_64/commitmeta.json"
;;
1[3-5]) # 13–15
RHCOS_META_URL="${RHCOS_RELEASE_URL}/storage/prod/streams/4.${VerX}-9.2/builds/${RHCOS_VERSION}/x86_64/commitmeta.json"
RHCOS_IMAGE=$(oc adm release info "$VERSION" --image-for=rhel-coreos 2>/dev/null)
;;
*) # 16+
RHCOS_META_URL="${RHCOS_RELEASE_URL}/storage/prod/streams/4.${VerX}-9.4/builds/${RHCOS_VERSION}/x86_64/commitmeta.json"
RHCOS_IMAGE=$(oc adm release info "$VERSION" --image-for=rhel-coreos 2>/dev/null)
;;
esac
PACKAGES=$(curl -skS "$RHCOS_META_URL" \
| jq -r '."rpmostree.rpmdb.pkglist"| .[] | @csv' \
| awk -F ',' '{print $1,$3,$4,$5}' \
| tr -d '",')
KERNEL_VERSION=$(awk '/kernel /' <<< "$PACKAGES")
# ---------------- OUTPUT ---------------- #
echo -e "Package List\n\n${PACKAGES}\n"
echo -e "OpenShift Version: ${VERSION}"
echo -e "Kubernetes Version: ${KUBE_VERSION}"
echo -e "RHCOS Version: rhcos-4.${VerX} ${RHCOS_VERSION}"
echo -e "Kernel Version: ${KERNEL_VERSION}"
echo -e "Release Image: ${RELEASE_IMAGE}"
echo -e "\nView list here: ${RHCOS_META_URL}"
}
# ---------------- MAIN ---------------- #
for dep in "${DEPENDENCIES[@]}"; do
_check_dependencies "$dep"
done
if [ -z "${VerY:-}" ]; then
_set_latest_version
else
version="4.${VerX}.${VerY}"
fi
_main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment