From 5dc03bc40d1c574b0ceb04a18b0d54eceffcc707 Mon Sep 17 00:00:00 2001 From: Peter Ajamian Date: Mon, 21 Jun 2021 05:10:24 +1200 Subject: [PATCH] Fix subscription-manger issues. After a RHEL conversion any attempt to run subscription-manager would result in an error. this was due to the RedHat certs having been replaced on the system during the migration. To fix this we now copy any subscription-manager certs to a temporary directory and if they have been removed during the migration we copy them back at the finish. This means that subscription-manager now won't stop working after a migration from RHEL. --- migrate2rocky/migrate2rocky.sh | 82 +++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/migrate2rocky/migrate2rocky.sh b/migrate2rocky/migrate2rocky.sh index d03ed9f..6213ec7 100644 --- a/migrate2rocky/migrate2rocky.sh +++ b/migrate2rocky/migrate2rocky.sh @@ -114,6 +114,9 @@ ARCH=$(arch) gpg_key_url="https://dl.rockylinux.org/pub/rocky/RPM-GPG-KEY-rockyofficial" gpg_key_sha512="88fe66cf0a68648c2371120d56eb509835266d9efdf7c8b9ac8fc101bdf1f0e0197030d3ea65f4b5be89dc9d1ef08581adb068815c88d7b1dc40aa1c32990f6a" +sm_ca_dir=/etc/rhsm/ca +unset tmp_sm_ca_dir + # all repos must be signed with the same key given in $gpg_key_url declare -A repo_urls repo_urls=( @@ -165,6 +168,25 @@ pkg_ver() ( return 0 ) +# Set up a temporary directory. +pre_setup () { + if ! tmp_dir=$(mktemp -d) || [[ ! -d "$tmp_dir" ]]; then + exit_message "Error creating temp dir" + fi + # failglob makes pathname expansion fail if empty, dotglob adds files + # starting with . to pathname expansion + if ( shopt -s failglob dotglob; : "$tmp_dir"/* ) 2>/dev/null ; then + exit_message "Temp dir not empty" + fi +} + +# Cleanup function gets rid of the temporary directory. +exit_clean () { + if [[ -d "$tmp_dir" ]]; then + rm -rf "$tmp_dir" + fi +} + pre_check () { if [[ -e /etc/rhsm/ca/katello-server-ca.pem ]]; then exit_message "Migration from Katello-modified systems is not supported by migrate2rocky." @@ -524,6 +546,15 @@ generate_rpm_info() { } package_swaps() { + # Save off any subscription-manger keys, just in case. + if ( shopt -s failglob dotglob; : "$sm_ca_dir"/* ) 2>/dev/null ; then + tmp_sm_ca_dir=$tmp_dir/sm-certs + mkdir "$tmp_sm_ca_dir" || + exit_message "Could not create directory: $tmp_sm_ca_dir" + cp -f -dR --preserve=all "$sm_ca_dir"/* "$tmp_sm_ca_dir/" || + exit_message "Could not copy certs to $tmp_sm_ca_dir" + fi + # prepare repo parameters local -a dnfparameters for repo in "${!repo_urls[@]}"; do @@ -660,6 +691,52 @@ EOF infomsg $'\nSyncing packages\n\n' dnf -y distro-sync || exit_message "Error during distro-sync." + + if rpm --quiet -q subscription-manager; then + infomsg $'Subscription Manager found on system.\n' + cat <