1414#
1515# Output is:
1616# - just a minor version in case of subscription RHOCP repository, e.g.: 15
17- # - or an URL to beta mirror followed by comma and minor version, e.g.:
18- # https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rpms/4.16-el9-beta/,16
19- # https://mirror.openshift.com/pub/openshift-v5/x86_64/dependencies/rpms/5.0-el9-beta/,0
17+ # - or an URL to beta mirror followed by comma, major, comma, and minor version, e.g.:
18+ # https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rpms/4.16-el9-beta/,4, 16
19+ # https://mirror.openshift.com/pub/openshift-v5/x86_64/dependencies/rpms/5.0-el9-beta/,5, 0
2020
2121set -euo pipefail
2222
2323SCRIPTDIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
2424REPOROOT=" $( cd " ${SCRIPTDIR} /.." && pwd) "
2525
26+ # Map of last minor version for each major (for cross-major transitions)
27+ declare -A LAST_MINOR_FOR_MAJOR=([4]=22)
28+
29+ # Calculate previous version handling cross-major boundaries.
30+ # Sets prev_major and prev_minor variables in the caller's scope.
31+ get_prev_version () {
32+ local major=$1
33+ local minor=$2
34+ if (( minor > 0 )) ; then
35+ prev_major=" ${major} "
36+ prev_minor=$(( minor - 1 ))
37+ else
38+ prev_major=$(( major - 1 ))
39+ prev_minor=" ${LAST_MINOR_FOR_MAJOR[${prev_major}]:- } "
40+ fi
41+ }
42+
2643if ! sudo subscription-manager status >& /dev/null; then
2744 >&2 echo " System must be subscribed"
2845 exit 1
@@ -44,39 +61,45 @@ if [[ "$#" -ge 2 ]]; then
4461 # Both minor and major provided as arguments
4562 current_minor=" ${1} "
4663 current_major=" ${2} "
47- stop= " ${current_minor} "
64+ max_steps=1
4865elif [[ " $# " -eq 1 ]]; then
4966 # Only minor provided, get major from Makefile
5067 current_minor=" ${1} "
5168 current_major=$( grep ' ^OCP_VERSION' " ${make_version} " | cut -d' =' -f2 | tr -d ' ' | cut -d' .' -f1)
52- stop= " ${current_minor} "
69+ max_steps=1
5370else
5471 # No arguments, get both from Makefile
5572 current_major=$( grep ' ^OCP_VERSION' " ${make_version} " | cut -d' =' -f2 | tr -d ' ' | cut -d' .' -f1)
5673 current_minor=$( grep ' ^OCP_VERSION' " ${make_version} " | cut -d' =' -f2 | tr -d ' ' | cut -d' .' -f2)
57- stop=$(( current_minor - 3 ))
58- if (( stop < 0 )) ; then
59- stop=0
60- fi
74+ max_steps=4
6175fi
6276
63- # Go through minor versions, starting from current_minor counting down
64- # to get latest available rhocp repository.
65- # For example, if current version is 4.16, the code will try to access
66- # rhocp-4.15 (which may not be released yet) and then rhocp-4.14 (which
67- # will be returned if it's usable). Works similarly for version 5.x.
68- for ver in $( seq " ${current_minor} " -1 " ${stop} " ) ; do
69- repository=" rhocp-${current_major } .${ver } -for-rhel-9-$( uname -m) -rpms"
77+ # Go through versions, starting from current version counting down
78+ # to get latest available rhocp repository. Handles cross-major
79+ # boundaries (e.g. from 5.0 back to 4.22).
80+ check_major= " ${current_major} "
81+ check_minor= " ${current_minor} "
82+ for (( step = 0 ; step < max_steps; step ++ ) ); do
83+ repository=" rhocp-${check_major } .${check_minor } -for-rhel-9-$( uname -m) -rpms"
7084 if sudo dnf repository-packages --showduplicates " ${repository} " info cri-o 1>&2 ; then
71- echo " ${ver } "
85+ echo " ${check_minor } "
7286 exit 0
7387 fi
7488
75- rhocp_beta_url=" https://mirror.openshift.com/pub/openshift-v${current_major } /$( uname -m) /dependencies/rpms/${current_major } .${ver } -el9-beta/"
89+ rhocp_beta_url=" https://mirror.openshift.com/pub/openshift-v${check_major } /$( uname -m) /dependencies/rpms/${check_major } .${check_minor } -el9-beta/"
7690 if sudo dnf repository-packages --showduplicates --disablerepo ' *' --repofrompath " this,${rhocp_beta_url} " this info cri-o 1>&2 ; then
77- echo " ${rhocp_beta_url} ,${ver } "
91+ echo " ${rhocp_beta_url} ,${check_major} , ${check_minor }"
7892 exit 0
7993 fi
94+
95+ prev_major=" "
96+ prev_minor=" "
97+ get_prev_version " ${check_major} " " ${check_minor} "
98+ if [[ -z " ${prev_minor} " ]]; then
99+ break
100+ fi
101+ check_major=" ${prev_major} "
102+ check_minor=" ${prev_minor} "
80103done
81104
82105>&2 echo " Failed to get latest rhocp repository!"
0 commit comments