]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Starting with get-rhel-dvd-iso-image
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 14 Nov 2023 10:09:56 +0000 (11:09 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 14 Nov 2023 10:09:56 +0000 (11:09 +0100)
scripts/get-rhel-dvd-iso-image [new file with mode: 0755]

diff --git a/scripts/get-rhel-dvd-iso-image b/scripts/get-rhel-dvd-iso-image
new file mode 100755 (executable)
index 0000000..3378a76
--- /dev/null
@@ -0,0 +1,200 @@
+#!/bin/bash
+
+set -e
+set -u
+
+BASE_NAME="$( basename ${0} )"
+MY_REAL_NAME=$( readlink -f $0 )
+BIN_DIR=$( dirname "${MY_REAL_NAME}" )
+BASE_DIR=$( dirname "${BIN_DIR}" )
+LIB_DIR="${BASE_DIR}/lib"
+CONF_DIR="${BASE_DIR}/etc"
+
+if [[ -f "${BIN_DIR}/functions.rc" ]] ; then
+    . "${BIN_DIR}/functions.rc"
+else
+    echo "Bash resource file '${BIN_DIR}/functions.rc' not found" >&2
+    exit 5
+fi
+
+OFFLINE_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhZDUyMjdhMy1i"
+OFFLINE_TOKEN+="Y2ZkLTRjZjAtYTdiNi0zOTk4MzVhMDg1NjYifQ.eyJpYXQiOjE2OTE2Nzk5MDEs"
+OFFLINE_TOKEN+="Imp0aSI6IjZhODcyNThlLTEyOGEtNDUyNS04YjhkLTFjMDBkZTUwODdmNyIsIml"
+OFFLINE_TOKEN+="zcyI6Imh0dHBzOi8vc3NvLnJlZGhhdC5jb20vYXV0aC9yZWFsbXMvcmVkaGF0LW"
+OFFLINE_TOKEN+="V4dGVybmFsIiwiYXVkIjoiaHR0cHM6Ly9zc28ucmVkaGF0LmNvbS9hdXRoL3JlY"
+OFFLINE_TOKEN+="Wxtcy9yZWRoYXQtZXh0ZXJuYWwiLCJzdWIiOiJmOjUyOGQ3NmZmLWY3MDgtNDNl"
+OFFLINE_TOKEN+="ZC04Y2Q1LWZlMTZmNGZlMGNlNjpmcmFuay5icmVobSIsInR5cCI6Ik9mZmxpbmU"
+OFFLINE_TOKEN+="iLCJhenAiOiJyaHNtLWFwaSIsInNlc3Npb25fc3RhdGUiOiI2NzRkODM4OS1kZW"
+OFFLINE_TOKEN+="VhLTQwY2UtYTgyNy1mNjZiZDI5ZWEwYzUiLCJzY29wZSI6Im9mZmxpbmVfYWNjZ"
+OFFLINE_TOKEN+="XNzIiwic2lkIjoiNjc0ZDgzODktZGVlYS00MGNlLWE4MjctZjY2YmQyOWVhMGM1"
+OFFLINE_TOKEN+="In0.3LAZwTxYJO5YIt_7vqjN7zb-LCjwrb4RPAAFz-h2o0s"
+
+declare -A IMAGE_CHECKSUMS=()
+
+IMAGE_CHECKSUMS['rhel-7.9-dvd']='2cb36122a74be084c551bc7173d2d38a1cfb75c8ffbc1489c630c916d1b31b25'
+IMAGE_CHECKSUMS['rhel-8.8-dvd']='517abcc67ee3b7212f57e180f5d30be3e8269e7a99e127a3399b7935c7e00a09'
+IMAGE_CHECKSUMS['rhel-9.2-dvd']='a18bf014e2cb5b6b9cee3ea09ccfd7bc2a84e68e09487bb119a98aa0e3563ac2'
+IMAGE_CHECKSUMS['rhel-9.3-dvd']='5c802147aa58429b21e223ee60e347e850d6b0d8680930c4ffb27340ffb687a8'
+
+IMAGE_CHECKSUM=
+
+declare -a IMAGE_KEYS=(
+  'rhel-7.9-dvd'
+  'rhel-8.8-dvd'
+  'rhel-9.2-dvd'
+  'rhel-9.3-dvd'
+)
+
+SSO_REDHAT_URL='https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
+
+IMAGE_DOWNLOAD_URL="https://api.access.redhat.com/management/v1/images/@CHECKSUM@/download"
+
+IMAGE_KEY=
+OUTPUT_FILE=
+
+detect_color
+
+DESCRIPTION=$( cat <<-EOF
+       Download a Red Hat Enterprise Linux Binary DVD.
+
+       EOF
+)
+
+#------------------------------------------------------------------------------
+usage() {
+
+    local keys_out=''
+    local key
+
+    for key in "${IMAGE_KEYS[@]}" ; do
+        keys_out+="             * ${key}
+"
+    done
+
+    cat <<-EOF
+       Usage: ${BASE_NAME} [Common Options] [-O|--output OUTPUTDIR_OR_FILE] <IMAGE_KEY>
+              ${BASE_NAME} [-h|--help]
+              ${BASE_NAME} [-V|--version]
+
+           Mandatory argument:
+               IMAGE_KEY:
+                   The name of the image, which should be downloaded. Possible keys are:
+       ${keys_out}
+
+           Special Options:
+               -o|--output OUTPUTDIR_OR_FILE
+                   The filename of the ISO output image file or the directory,
+                    where to store the downloaded ISO image.
+
+           Common Options:
+       ${STD_USAGE_MSG}
+       EOF
+
+}
+
+#------------------------------------------------------------------------------
+get_options() {
+
+    local tmp=
+    local base_dir=
+    local arg=
+
+    set +e
+    tmp=$( getopt -o ${STD_SHORT_OPTIONS}O: \
+                  --long ${STD_LONG_OPTIONS},output: \
+                  -n "${BASE_NAME}" -- "$@" )
+    if [[ $? != 0 ]] ; then
+        echo "" >&2
+        usage >&2
+        exit 1
+    fi
+    set -e
+
+    # Note the quotes around `$TEMP': they are essential!
+    eval set -- "${tmp}"
+    eval_common_options "$@"
+    if [[ "${DEBUG}" == 'y' ]] ; then
+        declare -p REMAINING_OPTS
+        declare -p REMAINING_ARGS
+    fi
+
+    local len="${#REMAINING_OPTS[*]}"
+    local i="0"
+    local j=
+    local output=
+    while [[ "$i" -lt "${len}" ]] ; do
+
+        arg="${REMAINING_OPTS[$i]}"
+
+        case "${arg}" in
+            -O|--output)
+                j=$(( $i + 1 ))
+                output="${REMAINING_OPTS[$j]}"
+                i=$(( $i + 2 ))
+                ;;
+            *)  echo -e "Internal error - option '${RED}${arg}${NORMAL}' was wrong!"
+                exit 1
+                ;;
+        esac
+
+    done
+
+    if [[ "${#REMAINING_ARGS[@]}" == "0" ]] ; then
+        error "No image key given."
+        echo >&2
+        usage >&2
+        exit 1
+    fi
+
+    if [[ "${#REMAINING_ARGS[@]}" -gt "2" ]] ; then
+        error "Only one image key maybe given."
+        echo >&2
+        usage >&2
+        exit 1
+    fi
+
+    IMAGE_KEY="${REMAINING_ARGS[1]}"
+    set +u
+    IMAGE_CHECKSUM="${IMAGE_CHECKSUMS[${IMAGE_KEY}]}"
+    set -u
+
+    if [[ -z "${IMAGE_CHECKSUM}" ]] ; then
+        error "Wrong image key '${RED}${IMAGE_KEY}${NORMAL}' given."
+        echo >&2
+        usage >&2
+        exit 1
+    fi
+
+    local output_base="${IMAGE_KEY}.iso"
+    if [[ "${output}" ]] ; then
+        if [[ -d "${output}" ]] ; then
+            OUTPUT_FILE="${output}/${output_base}"
+        else
+            OUTPUT_FILE="${output}"
+        fi
+    else
+        OUTPUT_FILE="${output_base}"
+    fi
+
+    if [[ $(id -u -n) != "root" ]] ; then
+        error "You must ${RED}be root${NORMAL} to execute this script!" >&2
+        exit 1
+    fi
+
+}
+
+#------------------------------------------------------------------------------
+main() {
+
+    get_options "$@"
+
+    set_locale "en_US.utf8"
+
+}
+
+main "$@"
+exit 0
+
+
+
+# vim: et list