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 <