From 78baa0b95418408c909e882f71f97903368c07ee Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 23 Aug 2023 18:01:53 +0200 Subject: [PATCH] Continued with installation of RHEL 9 --- files/repos-el9/epel.repo | 8 ++++ kickstart/profile.rhel-9.2.develop.ks | 17 ++++++++ snippets/tpl.110.register-rhel.sh | 57 +++++++++++++++++++++++++++ snippets/tpl.190.repos_rhel9.sh | 48 ++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 files/repos-el9/epel.repo create mode 100644 snippets/tpl.110.register-rhel.sh create mode 100644 snippets/tpl.190.repos_rhel9.sh diff --git a/files/repos-el9/epel.repo b/files/repos-el9/epel.repo new file mode 100644 index 0000000..688b33d --- /dev/null +++ b/files/repos-el9/epel.repo @@ -0,0 +1,8 @@ +[epel] +name=Extra Packages for Enterprise Linux 9 - $basearch +baseurl=https://repo02.pixelpark.com/Linux/yum/epel/9/Everything/$basearch +enabled=1 +gpgcheck=1 +repo_gpgcheck=0 +gpgkey=https://repo02.pixelpark.com/repo/gpg/RPM-GPG-KEY-EPEL-9 + diff --git a/kickstart/profile.rhel-9.2.develop.ks b/kickstart/profile.rhel-9.2.develop.ks index 847ff42..eace506 100644 --- a/kickstart/profile.rhel-9.2.develop.ks +++ b/kickstart/profile.rhel-9.2.develop.ks @@ -214,6 +214,10 @@ export mac_address_eth0="$mac_address_eth0" export system_status="${SYSTEM_STATUS}" export ws_rel_filesdir="${WS_REL_FILESDIR}" export cobbler_url="${COBBLER_URL}" +export rhsm_user="${RHSM_USER}" +export rhsm_pwd="${RHSM_PWD}" +export rhsm_system_id="${RHSM_SYSTEM_ID}" +export rhsm_registred='' #raw echo @@ -228,6 +232,9 @@ echo "MAC address eth0: '${mac_address_eth0}'" echo "System status: '${system_status}'" echo "Ws relative filesdir: '${ws_rel_filesdir}'" echo "Cobbler URL: '${cobbler_url}'" +echo +echo "RedHat SubscriptionManager User: '${rhsm_user}'" +echo "RedHat SubscriptionManager System ID: '${rhsm_system_id}'" #end raw ############################################################################### @@ -283,6 +290,16 @@ echo echo "Using snippet $this_snippet" $SNIPPET($this_snippet) +#set $this_snippet= "per_status/" + $SYSTEM_STATUS + "/tpl.110.register-rhel.sh" +echo +echo "Using snippet $this_snippet" +$SNIPPET($this_snippet) + +#set $this_snippet= "per_status/" + $SYSTEM_STATUS + "/tpl.190.repos_rhel9.sh" +echo +echo "Using snippet $this_snippet" +$SNIPPET($this_snippet) + #set $this_snippet= "per_status/" + $SYSTEM_STATUS + "/tpl.195.repos_el9.sh" echo echo "Using snippet $this_snippet" diff --git a/snippets/tpl.110.register-rhel.sh b/snippets/tpl.110.register-rhel.sh new file mode 100644 index 0000000..77ea16d --- /dev/null +++ b/snippets/tpl.110.register-rhel.sh @@ -0,0 +1,57 @@ +## !/bin/bash +#raw + +#----------------------------------------------------------- +register_rhel() { + + echo -e "\e[0Ksection_start:$( date +%s ):ks_register_rhel[collapsed=true]\r\e[0KRegistering at RedHat Subscription Management ..." + echo + echo "${HASH_LINE}" + echo + log "Registring system at RedHat Subscription Management ..." + + local rhsm='/usr/sbin/subscription-manager' + local err_msg= + local fqdn=$( hostname -f ) + local cmd="${rhsm} register --no-progress-messages --username '${rhsm_user}' --password '${rhsm_pwd}' " + cmd+="--auto-attach --name '${fqdn}'" + + if [[ -z "${rhsm_user}" || -z "${rhsm_pwd}" ]] ; then + err_msg="Either RHSM_USER or RHSM_PWD are not defined as meta variables." + else + if [[ -x "${rhsm}" ]] ; then + if [[ -n "${rhsm_system_id}" ]] ; then + if eval ${cmd} --consumerid "${rhsm_system_id}" ; then + rhsm_registred='y' + fi + fi + if [[ -z "${rhsm_registred}" ]] ; then + if eval ${cmd} ; then + rhsm_registred='y' + else + err_msg="Unexpected error." + fi + fi + else + err_msg="Did not found executable '${rhsm}'." + fi + fi + + if [[ "${rhsm_registred}" ]] ; then + log "System '${fqdn}' successful registred at RedHat Subscription Management." + echo + echo "Subscription Management Idendity:" + ${rhsm} identity + echo + ${rhsm} list --consumed + else + log "Could not register system '$( hostname -f )' at RedHat Subscription Management: ${err_msg}" + fi + + echo -e "\e[0Ksection_end:$( date +%s ):ks_register_rhel\r\e[0K" +} + +register_rhel + +#end raw +## vim: ts=4 et list diff --git a/snippets/tpl.190.repos_rhel9.sh b/snippets/tpl.190.repos_rhel9.sh new file mode 100644 index 0000000..6dcb1fb --- /dev/null +++ b/snippets/tpl.190.repos_rhel9.sh @@ -0,0 +1,48 @@ +## !/bin/bash +#raw + +#----------------------------------------------------------- +get_repos_rhel9() { + + echo + echo "${HASH_LINE}" + echo "Calling get_repos_rhel9() ..." + echo + # local base_url="${cobbler_url}/${ws_rel_filesdir}/${system_status}/repos/el9" + local rhsm='/usr/sbin/subscription-manager' + + log "Installing repositories for RHEL 9." + + if [[ -z "${rhsm_registred}" ]] ; then + echo "Cannot generate RedHat repo, system is not registred at RedHat Subscription Management." + return + fi + + local serial=$( ${rhsm} list --no-progress-messages --consumed | grep -i '^Serial:' | awk '{print $2}' ) + if [[ -z "${serial}" ]] ; then + echo "Cannot generate RedHat repo, did not found subscription serial number." + return + fi + + log "Found subscription serial number: '${serial}'." + +# local -a repos=('pixelpark' 'puppet') + +# local repo= +# local url= +# local tmp_file= +# for repo in "${repos[@]}" ; do +# echo "Ensuring repo '${repo}.repo'..." +# url="${base_url}/${repo}.repo" +# tmp_file=$( mktemp ) +# wget -O "${tmp_file}" --dns-timeout=2 --connect-timeout=3 --read-timeout=3 "${url}" || true +# if [[ -s "${tmp_file}" ]] ; then +# mv -v "${tmp_file}" "/etc/yum.repos.d/${repo}.repo" +# fi +# rm -fv "${tmp_file}" +# done + +} +get_repos_rhel9 + +#end raw -- 2.39.5