]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Hopefully finished postinstall-scripts/register-rhel
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 16 Oct 2023 10:39:15 +0000 (12:39 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 16 Oct 2023 10:39:15 +0000 (12:39 +0200)
postinstall-scripts/register-rhel

index 09b40cc4097d52798d790b15f12867c438e846dd..3d527091bccbda1f3fb6bab3a491c73837c07e0d 100755 (executable)
@@ -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
 
 }