From 18b2b8718c37889f9131f9e4f5836cafa9d67ed8 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 16 Oct 2023 12:39:15 +0200 Subject: [PATCH] Hopefully finished postinstall-scripts/register-rhel --- postinstall-scripts/register-rhel | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/postinstall-scripts/register-rhel b/postinstall-scripts/register-rhel index 09b40cc..3d52709 100755 --- a/postinstall-scripts/register-rhel +++ b/postinstall-scripts/register-rhel @@ -137,6 +137,46 @@ register_rhel() { } +#------------------------------------------------------------------------------ +mangle_repos() { + + local serial=$( ${SM_BIN} list --consumed --no-progress-messages | \ + grep -i '^Serial:' | \ + sed -e 's/^Serial:[ ]*//i' -e 's/[ ]*$//' ) + + if [[ -z "${serial}" ]] ; then + error "Did not found the serial of the RHEL subscription." + return 0 + fi + debug "Found serial of the RHEL subscription: '${CYAN}${serial}${NORMAL}'." + + local -a cmd=() + local repo_file= + local do_mangle= + + for repo_file in /etc/yum.repos.d/*.repo ; do + if [[ ! -f "${repo_file}" ]] ; then + continue + fi + debug "Trying to mangle '${CYAN}${repo_file}${NORMAL}' ..." + do_mangle= + if grep -P -q '^sslclient(key|cert)\s*=\s*/etc/pki/entitlement/' "${repo_file}"; then + do_mangle="y" + fi + if [[ "${do_mangle}" != "y" ]] ; then + continue + fi + info "Mangling repo file '${CYAN}${repo_file}${NORMAL}' ..." + cmd=( 'sed' '-i' ) + cmd+=( "-e" "'s|^sslclientkey[ ]*=[ ]*/etc/pki/entitlement/.*|sslclientkey=/etc/pki/entitlement/${serial}-key.pem|'" ) + cmd+=( "-e" "'s|^sslclientcert[ ]*=[ ]*/etc/pki/entitlement/.*|sslclientkey=/etc/pki/entitlement/${serial}.pem|'" ) + cmd+=( "'${repo_file}'" ) + + exec_cmd "${cmd[@]}" + done + +} + ################################################################################ ## ## Main @@ -150,7 +190,7 @@ main() { set_locale "en_US.utf8" check_for_root register_rhel - # mangle_repos + mangle_repos } -- 2.39.5