From: Frank Brehm Date: Mon, 16 Oct 2023 10:39:15 +0000 (+0200) Subject: Hopefully finished postinstall-scripts/register-rhel X-Git-Tag: 1.8.0^2~37 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=18b2b8718c37889f9131f9e4f5836cafa9d67ed8;p=pixelpark%2Fcreate-terraform.git Hopefully finished postinstall-scripts/register-rhel --- 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 }