-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-package-version.sh
executable file
·75 lines (56 loc) · 2.39 KB
/
get-package-version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#set -x
if [ $# -lt 2 ]
then
echo "Usage: $0 <OpenShift-Version> <package-name>"
echo "Example: $0 4.15.30 openssl"
exit 0
fi
if ! [ -f ./ocp-pull-secret.json ]
then
echo "Ensure to store the pull secret in `pwd`/ocp-pull-secret.json"
exit 0
fi
if [ -z "$REGISTRY_AUTH_FILE" ]
then
export REGISTRY_AUTH_FILE=`pwd`/ocp-pull-secret.json
fi
set -euo pipefail
readonly RHCOS_ART_BASE_DOMAIN="releases-rhcos-art.apps.ocp-virt.prod.psi.redhat.com"
#ARCH="$(arch)"
ARCH="x86_64"
readonly ARCH
function get-rhelver {
local RHCOS_VERSION
RHCOS_VERSION="${1}"
local RHELVER_FOUND
RHELVER_FOUND="$(echo "${RHCOS_VERSION}" | gawk -F. '{version=gensub("^([89])([0-9]*)$","\\1.\\2","g",$2);print version}')"
echo -n "${RHELVER_FOUND}"
}
function get-commitmeta-url {
local OCP_MAJOR="${1}"
local RHCOS_VERSION="${2}"
local RHELVER
RHELVER="$(get-rhelver "${RHCOS_VERSION}")"
if (curl -s -k "https://${RHCOS_ART_BASE_DOMAIN}/storage/releases/rhcos-${OCP_MAJOR}/builds.json" | jq '.builds[]|.id' -r 2>/dev/null | grep "${RHCOS_VERSION}" > /dev/null 2>/dev/null)
then
echo -n "https://${RHCOS_ART_BASE_DOMAIN}/storage/releases/rhcos-${OCP_MAJOR}/${RHCOS_VERSION}/${ARCH}/commitmeta.json"
elif (curl -s -k "https://${RHCOS_ART_BASE_DOMAIN}/storage/releases/rhcos-${OCP_MAJOR}-custom/builds.json" | jq '.builds[]|.id' -r 2>/dev/null | grep "${RHCOS_VERSION}" > /dev/null 2>/dev/null)
then
echo -n "https://${RHCOS_ART_BASE_DOMAIN}/storage/releases/rhcos-${OCP_MAJOR}-custom/${RHCOS_VERSION}/${ARCH}/commitmeta.json"
elif [[ "$(echo "${RHELVER}" | awk -F. '{print $1}')" == "8" ]]
then
echo -n "https://${RHCOS_ART_BASE_DOMAIN}/storage/prod/streams/${OCP_MAJOR}/builds/${RHCOS_VERSION}/${ARCH}/commitmeta.json"
else
echo -n "https://${RHCOS_ART_BASE_DOMAIN}/storage/prod/streams/${OCP_MAJOR}-${RHELVER}/builds/${RHCOS_VERSION}/${ARCH}/commitmeta.json"
fi
}
function get-package-version {
OCP_RELEASE="${1}"
PACKAGE="${2}"
OCP_MAJOR="$(echo "${OCP_RELEASE}" | awk -F. '{print $1"."$2}')"
RHCOS_VERSION="$(oc adm release info "${OCP_RELEASE}" -o jsonpath='{.displayVersions.machine-os.Version}')"
RHCOS_COMMITMETA_URL="$(get-commitmeta-url "${OCP_MAJOR}" "${RHCOS_VERSION}")"
curl -sk "${RHCOS_COMMITMETA_URL}" | jq -r '.["rpmostree.rpmdb.pkglist"]|map(select(.[0]=="'"${PACKAGE}"'"))[0]|.[0]+"-"+.[2]+"-"+.[3]+"."+.[4]'
}
[[ "${BASH_SOURCE[0]}" != "${0}" ]] || get-package-version "${@}"