From d82de38816f6035696bb9f1e3aad74aa4db6ec79 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 16 Oct 2023 15:05:53 +0200 Subject: [PATCH] Adding generating password file for postinstall-scripts/register-rhel --- example/prd-repo03.yaml | 4 ++-- postinstall-scripts/register-rhel | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/example/prd-repo03.yaml b/example/prd-repo03.yaml index cdafa37..947fbeb 100644 --- a/example/prd-repo03.yaml +++ b/example/prd-repo03.yaml @@ -2,7 +2,7 @@ defaults: vsphere: live cluster: vmcc-l105-01 - vm_folder: Pixelpark/Tools + vm_folder: Pixelpark/Tools/live num_cpus: 2 memory: 4GB boot_delay: 5 @@ -34,7 +34,7 @@ defaults: dns_options: 'timeout:1 attempts:2 use-vc' vms: - - name: repo03.pixelpark.com + - name: prd-repo03.pixelpark.com interfaces: - address_v4: 217.66.55.69 diff --git a/postinstall-scripts/register-rhel b/postinstall-scripts/register-rhel index 3d52709..2204e14 100755 --- a/postinstall-scripts/register-rhel +++ b/postinstall-scripts/register-rhel @@ -19,6 +19,7 @@ export PATH='/sbin:/bin:/usr/sbin:/usr/bin' RHSM_USER='dpx-subscriber' RHSM_PWD= +RHSM_PWD_FILE="${BIN_DIR}/rhsm-user-passwd" SM_BIN='subscription-manager' detect_color @@ -33,7 +34,7 @@ DESCRIPTION=$( cat <<-EOF #------------------------------------------------------------------------------ usage() { cat <<-EOF - Usage: ${BASE_NAME} [-U USER ] [-P PASSWORD ] ${STD_USAGE} + Usage: ${BASE_NAME} [-U USER ] [-P PASSWORD ] [-y PASSWORD_FILE] ${STD_USAGE} ${BASE_NAME} [-h|--help] ${BASE_NAME} [-V|--version] @@ -41,6 +42,8 @@ usage() { -U|--user USER Gives the username for the account which is registering the system. -P|--password PASSWORD Gives the user account password. + -y|--password-file PASSWORD_FILE + A file containing the user account password. EOF echo "${STD_USAGE_MSG}" @@ -50,8 +53,8 @@ usage() { get_options() { local tmp= - local short_options="U:P:${STD_SHORT_OPTIONS}" - local long_options="user:,password:,${STD_LONG_OPTIONS}" + local short_options="U:P:y:${STD_SHORT_OPTIONS}" + local long_options="user:,password:,password-file:,${STD_LONG_OPTIONS}" set +e tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASE_NAME}" -- "$@" ) @@ -89,6 +92,11 @@ get_options() { RHSM_PWD="${REMAINING_OPTS[$j]}" i=$(( $i + 2 )) ;; + -y|--password-file) + j=$(( $i + 1 )) + RHSM_PWD_FILE="${REMAINING_OPTS[$j]}" + i=$(( $i + 2 )) + ;; *) echo -e "Internal error - option '${RED}${arg}${NORMAL} was wrong!" exit 1 ;; @@ -115,6 +123,10 @@ get_options() { exit 1 fi + if [[ -n "${RHSM_PWD_FILE}" && -f "${RHSM_PWD_FILE}" ]] ; then + RHSM_PWD=$( cat "${RHSM_PWD_FILE}" | head -n 1 ) + fi + if [[ -z "${RHSM_PWD}" ]] ; then error "No password of the user for registring at RedHat subscription management given." exit 1 -- 2.39.5