-
-
Save nccurry/28afe27881b061e26436553b05fee739 to your computer and use it in GitHub Desktop.
OCP4: check upgrade channel for a particular release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ocp4-chk-upgrade-channel v0.0.3 last mod 2020/01/23 | |
# Copyright 2020 Ryan Sawhill Aroha <[email protected]> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
# General Public License <gnu.org/licenses/gpl.html> for more details. | |
# Colors | |
[[ ${NO_COLORS} ]] || declare -A c=([z]='\033[0;0m' [Q]='\033[0;0m\033[1;1m' [r]='\033[0;31m' [R]='\033[1;31m' [g]='\033[0;32m' [G]='\033[1;32m' [y]='\033[0;33m' [Y]='\033[1;33m' [b]='\033[0;34m' [B]='\033[1;34m' [m]='\033[0;35m' [M]='\033[1;35m' [c]='\033[0;36m' [C]='\033[1;36m') | |
print() { | |
local echo_opts= | |
while [[ $1 =~ ^- ]]; do | |
echo_opts+="$1 " | |
shift | |
done | |
echo -e $echo_opts "$@" | |
} | |
halp() { | |
rc=0 | |
if [[ $@ ]]; then | |
print "${c[R]}✘ ERROR: $@${c[z]}\n" | |
rc=1 | |
fi | |
cat <<-EOF | |
usage: ${0##*/} [-v|--verbose] OCP_VERSION | |
Figure out the highest upgrade channel in which OCP_VERSION can be found | |
Ordering: "stable", "fast", "candidate", "prerelease" | |
OCP_VERSION should be something like "4.1.15" or "4.2.2" | |
Requires: | |
• curl | |
• jq (https://github.com/stedolan/jq/releases) | |
EOF | |
exit $rc | |
} | |
verbose=0 | |
until [[ -z $1 ]]; do | |
case $1 in | |
-v|--verbose) | |
verbose=1; shift;; | |
4.*) | |
version=$1 | |
[[ $version =~ ^4\.[0-9]+\.[0-9]+$ ]] && major=${1%.*} minor=${1##*.} || halp "Invalid OCP_VERSION specified" | |
shift;; | |
-h|--help) halp;; | |
*) halp "Invalid arguments" | |
esac | |
done | |
url=https://mirror.openshift.com/pub/openshift-v4/clients/ocp/$version | |
validate_url() { | |
local errs | |
errs=$(curl --fail -o /dev/null -LSsI $1 2>&1) && return | |
print "$indent${c[R]}✘ Failed to get $1${c[z]}${c[r]}\n$indent $errs${c[z]}" | |
return 2 | |
} | |
jq_help=$(jq -h) | |
if [[ $? -gt 0 || ! $jq_help =~ "jq - commandline JSON processor" ]]; then | |
print "${c[R]}✘ Unexpected error running 'jq --help' command -- need jq from https://github.com/stedolan/jq/releases${c[z]}" | |
exit 1 | |
fi | |
# Make sure release exists | |
validate_url $url/release.txt || exit | |
print "${c[Q]}RH OCP v$major release $minor${c[z]}" | |
# Check upgrade channel | |
for channel in stable fast candidate prerelease x; do | |
verboseOutput=$(curl -sSH "Accept: application/json" "https://api.openshift.com/api/upgrades_info/v1/graph?channel=${channel}-${major}&arch=amd64" | jq -Ce --arg version $version '.nodes[] | select(.version == $version)') | |
(( $? == 0 )) && break | |
done | |
rc=0 | |
case $channel in | |
x) | |
rc=1 verbose=0 channelMsg="${c[R]} ☢️ ☣️ U N K N O W N ☣️ ☢️ \n${c[r]}WARNING: Could not find release in ANY upgrade channel!" ;; | |
stable) | |
rc=0 channelMsg="${c[G]}✔✔✔ $channel ✔✔✔" ;; | |
fast) | |
rc=3 channelMsg="${c[Y]}⚠️ ⚠️ $channel ⚠️ ⚠️ \n${c[m]}WARNING: Release has not (yet) been tagged into the stable channel" ;; | |
candidate|prerelease) | |
rc=1 channelMsg="${c[R]}⛔ ⛔ $channel ⛔ ⛔ \n${c[m]}WARNING: Release has not (yet) been tagged into the stable channel" ;; | |
esac | |
print "${c[Q]}Highest upgrade channel: $channelMsg${c[z]}" | |
(( verbose == 1 )) && echo "$verboseOutput" | |
exit $rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @nccurry
Since you're the only one that forked this, I just wanted to take a sec to let you know the original script has been completely overhauled. Ref: https://gist.github.com/ryran/072409b1b7efd5018683a8c45e019652#gistcomment-3657193