From 1c25367f8b95ff9b506f7a5c429949605a57a312 Mon Sep 17 00:00:00 2001 From: Peter Ajamian Date: Fri, 14 May 2021 02:26:20 +1200 Subject: [PATCH] Various RHEL fixes Various fixes to allow RHEL conversions to work: - adding additional commands to bin_check - Fixed awk command to parse out the gpgkey for a repo. - provides_pkg() which returns a package name for a given provides. - allow additional packages to be removed without replacing them with rocky equivalents. - Don't bother checkign the exit status of dnf shell, it doesn't return a valid fail status anyways. - Instead check to make sure that the appropriate packages have been removed and installed. If not attempt to fix with rpm. --- migrate2rocky.sh | 125 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 15 deletions(-) diff --git a/migrate2rocky.sh b/migrate2rocky.sh index 60a8c8d..613fbcf 100644 --- a/migrate2rocky.sh +++ b/migrate2rocky.sh @@ -21,6 +21,7 @@ blue=$(tput setaf 4) nocolor=$(tput op) export LANG=en_US.UTF-8 +shopt -s nullglob SUPPORTED_MAJOR="8" SUPPORTED_PLATFORM="platform:el$SUPPORTED_MAJOR" @@ -78,7 +79,7 @@ bin_check() { fi local -a missing - for bin in rpm dnf awk column tee tput mkdir cat arch; do + for bin in rpm dnf awk column tee tput mkdir cat arch sort uniq rmdir rm; do if ! type "$bin" >/dev/null 2>&1; then missing+=("$bin") fi @@ -134,15 +135,32 @@ repoinfo () { # dnf repoinfo doesn't return the gpgkey, but we need that so we have to get # it from the repo file itself. + # "end_of_file" is a hack here. Since it is not a valid dnf setting we know + # it won't appear in a .repo file on a line by itself, so it's safe to + # search for the string to make the awk parser look all the way to the end + # of the file. repoinfo_results[Repo-gpgkey]=$( awk ' - $1=="['"${repoinfo_results[Repo-id]}"']" {next} - {if (/^\[.*\]$/) {nextfile} - else if (sub(/^gpgkey=file:\/\//,"")) print - }' < "${repoinfo_results[Repo-filename]}" + $0=="['"${repoinfo_results[Repo-id]}"']",$0=="end_of_file" { + if (l++ < 1) {next} + else if (/^\[.*\]$/) {nextfile} + else if (sub(/^gpgkey\s*=\s*file:\/\//,"")) {print; nextfile} + else {next} + } + ' < "${repoinfo_results[Repo-filename]}" ) } +provides_pkg () ( + set -o pipefail + provides=$(dnf -q provides "$1" | awk '{print $1; nextfile}') || + return 1 + set +o pipefail + pkg=$(dnf -q repoquery --queryformat '%{NAME}' "$provides") || + exit_message "Can't get package name for $provides." + printf '%s\n' "$pkg" +) + collect_system_info () { # We need to map rockylinux repository names to the equivalent repositories # in the source distro. To do that we look for known packages in each @@ -185,6 +203,7 @@ collect_system_info () { # First get info for the baseos repo repoinfo "${repo_map[baseos]}" declare -g -A pkg_map provides_pkg_map + declare -g -a addl_provide_removes addl_pkg_removes provides_pkg_map=( [rocky-backgrounds]=system-backgrounds [rocky-indexhtml]=redhat-indexhtml @@ -193,17 +212,21 @@ collect_system_info () { [rocky-gpg-keys]="${repoinfo_results[Repo-gpgkey]}" [rocky-release]=system-release ) + addl_provide_removes=( + redhat-release-eula + ) for pkg in "${!provides_pkg_map[@]}"; do printf '.' prov=${provides_pkg_map[$pkg]} - local provides - set -o pipefail - provides=$(dnf -q provides "$prov" | awk '{print $1; nextfile}') || + pkg_map[$pkg]=$(provides_pkg $prov) || exit_message "Can't get package that provides $prov." - set +o pipefail - pkg_map[$pkg]=$(dnf -q repoquery --queryformat '%{NAME}' "$provides") || - exit_message "Can't get package name for $provides." + done + for prov in "${addl_provide_removes[@]}"; do + printf '.' + local pkg; + pkg=$(provides_pkg $prov) || continue + addl_pkg_removes+=("$pkg") done printf '%s\n' '' '' "Found the following system packages which map from $PRETTY_NAME to Rocky Linux 8:" @@ -230,6 +253,11 @@ collect_system_info () { done ) + if (( ${#addl_pkg_removes[@]} )); then + printf '%s\n' '' "In addition to the above the following system packages will be removed:" \ + "${addl_pkg_removes[@]}" + fi + # Release packages that are part of SIG's should be listed below when they # are available. # UPDATE: We may or may not do something with SIG's here, it could just be @@ -278,16 +306,83 @@ generate_rpm_info() { } package_swaps() { +set -x # Use dnf shell to swap the system packages out. - if dnf -y shell --nogpg --disablerepo=\* \ + dnf -y shell --nogpg --disablerepo=\* --noautoremove \ + --setopt=protected_packages= --setopt=keepcache=True \ "${repo_urls[@]/#/--repofrompath=}" <