From c5aeffa0a6718c5bc86384e435432f08b31008e1 Mon Sep 17 00:00:00 2001 From: Gregory Giguashvili Date: Wed, 14 Aug 2024 06:27:04 +0000 Subject: [PATCH] Add ci-includes functions.sh script --- scripts/ci-includes/functions.sh | 100 +++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 scripts/ci-includes/functions.sh diff --git a/scripts/ci-includes/functions.sh b/scripts/ci-includes/functions.sh new file mode 100644 index 0000000000..6e1f45b3cf --- /dev/null +++ b/scripts/ci-includes/functions.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +# +# Note that CI-specific functions have 'ci_' name prefix. +# The rest should be generic functionality. +# +function ci_script_prologue() { + IP_ADDRESS="$(cat "${SHARED_DIR}/public_address")" + export IP_ADDRESS + HOST_USER="$(cat "${SHARED_DIR}/ssh_user")" + export HOST_USER + CACHE_REGION="$(cat "${SHARED_DIR}/cache_region")" + export CACHE_REGION + INSTANCE_PREFIX="${HOST_USER}@${IP_ADDRESS}" + export INSTANCE_PREFIX + + echo "Using Host $IP_ADDRESS" + + mkdir -p "${HOME}/.ssh" + cat >"${HOME}/.ssh/config" <>"${HOME}/.aws/config" <>"${HOME}/.aws/credentials" <&/dev/null; then + return + fi + + if [ ! -e /tmp/subscription-manager-org ] || [ ! -e /tmp/subscription-manager-act-key ] ; then + echo "ERROR: The subscription files do not exist in /tmp directory" + return 1 + fi + sudo subscription-manager register \ + --org="$(cat /tmp/subscription-manager-org)" \ + --activationkey="$(cat /tmp/subscription-manager-act-key)" +} + +function trap_subprocesses_on_term() { + # Call wait regardless of the outcome of the kill command, in case some of + # the subprocesses are finished by the time we try to kill them. + trap 'PIDS=$(jobs -p); if test -n "${PIDS}"; then kill ${PIDS} || true && wait; fi' TERM +} + +# +# Unconditionally enable tracing after loading the functions +# +export PS4='+ $(date "+%T.%N") \011'