diff --git a/migrate2rocky/migrate2rocky.sh b/migrate2rocky/migrate2rocky.sh index 5b523d5..744ab7c 100644 --- a/migrate2rocky/migrate2rocky.sh +++ b/migrate2rocky/migrate2rocky.sh @@ -125,6 +125,15 @@ repo_urls=( [rockyappstream]="https://dl.rockylinux.org/pub/rocky/${SUPPORTED_MAJOR}/AppStream/$ARCH/os/" ) +# The repos package for CentOS stream requires special handling. +declare -g -A stream_repos_pkgs +stream_repos_pkgs=( + [rocky-repos]=centos-stream-repos + [epel-release]=epel-next-release +) +# Prefix to add to CentOS stream repo names when renaming them. +stream_prefix=stream- + unset CDPATH exit_message() { @@ -212,8 +221,8 @@ bin_check() { local -a missing bins bins=( - rpm dnf awk column tee tput mkdir cat arch sort uniq - rmdir rm head curl sha512sum mktemp systemd-detect-virt + rpm dnf awk column tee tput mkdir cat arch sort uniq rmdir + rm head curl sha512sum mktemp systemd-detect-virt sed ) if [[ $update_efi ]]; then bins+=(findmnt grub2-mkconfig efibootmgr grep mokutil lsblk) @@ -539,6 +548,22 @@ $'because continuing with the migration could cause further damage to system.' fi done; + # Special Handling for CentOS Stream Repos + installed_sys_stream_repos_pkgs=() + installed_stream_repos_pkgs=() + for p in "${!stream_repos_pkgs[@]}"; do + if [[ ${installed_pkg_map[$p]} && + ${installed_pkg_map[$p]} == "${stream_repos_pkgs[$p]}" ]] + then + # System package that needs to be swapped / disabled + installed_pkg_map[$p]= + installed_sys_stream_repos_pkgs+=( ${stream_repos_pkgs[$p]} ) + elif rpm --quiet -q "${stream_repos_pkgs[$p]}"; then + # Non-system package, repos just need to be disabled. + installed_stream_repos_pkgs+=( ${stream_repos_pkgs[$p]} ) + fi + done + printf '%s\n' '' "We will replace the following $PRETTY_NAME packages with their Rocky Linux 8 equivalents" column -t -s $'\t' -N "Packages to be Removed,Packages to be Installed" < <( for p in "${!installed_pkg_map[@]}"; do @@ -546,8 +571,24 @@ $'because continuing with the migration could cause further damage to system.' done ) + if (( ${#installed_sys_stream_repos_pkgs[@]} )); then + printf '%s\n' '' \ +'Also to aid the transition from CentOS Stream the following packages will be '\ +'removed from the rpm database but the included repos will be renamed and '\ +'retained but disabled:' \ + "${installed_sys_stream_repos_pkgs[@]}" + fi + + if (( ${#installed_stream_repos_pkgs[@]} )); then + printf '%s\n' '' \ +'Also to aid the transition from CentOS Stream the repos included in the '\ +'following packages will be renamed and retained but disabled:' \ + "${installed_stream_repos_pkgs[@]}" + fi + if (( ${#addl_pkg_removes[@]} )); then - printf '%s\n' '' "In addition to the above the following system packages will be removed:" \ + printf '%s\n' '' \ +"In addition to the above the following system packages will be removed:" \ "${addl_pkg_removes[@]}" fi @@ -661,6 +702,25 @@ package_swaps() { dnfparameters+=( "--setopt=${repo}.gpgkey=file://${gpg_key_file}" ) done + # CentOS Stream specific processing + if (( ${#installed_stream_repos_pkgs[@]} )); then + # Get a list of the repo files. + local -a repos_files + readarray -t repos_files < <( + saferpm -ql "${installed_sys_stream_repos_pkgs[@]}" \ + "${installed_stream_repos_pkgs[@]}" | + grep '^/etc/yum\.repos\.d/.\+\.repo$' + ) + + # Remove the package from the rpm db. + saferpm -e --justdb --nodeps -a "${installed_sys_stream_repos_pkgs[@]}" || + exit_message \ +"Could not remove packages from the rpm db: ${installed_sys_stream_repos_pkgs[@]}" + + # Rename the stream repos with a prefix. + sed -i 's/^\[/['"$stream_prefix"'/' "${repos_files[@]}" + fi + # Use dnf shell to swap the system packages out. safednf -y shell --disablerepo=\* --noautoremove \ --setopt=protected_packages= --setopt=keepcache=True \ @@ -757,7 +817,7 @@ EOF # Distrosync infomsg $'Ensuring repos are enabled before the package swap\n' - safednf -y --enableplugin=config-manager config-manager \ + safednf -y --enableplugin=config_manager config-manager \ --set-enabled "${!repo_map[@]}" || { printf '%s\n' 'Repo name missing?' exit 25 @@ -788,7 +848,7 @@ EOF exit_message "Can't enable modules ${enabled_modules[*]}" fi - # Make sure that excluded repos are disabled. + # Make sure that excluded modules are disabled. infomsg $'Disabling excluded modules\n\n' safednf -y module disable "${module_excludes[@]}" || exit_message "Can't disable modules ${module_excludes[*]}" @@ -796,8 +856,39 @@ EOF infomsg $'\nSyncing packages\n\n' dnf -y distro-sync || exit_message "Error during distro-sync." + # Disable Stream repos. + if (( ${#installed_sys_stream_repos_pkgs[@]} || + ${#installed_stream_repos_pkgs[@]} )); then + dnf -y --enableplugin=config_manager config-manager --set-disabled \ + "$stream_prefix*" || + errmsg \ +$'Failed to disable CentOS Stream repos, please check and disable manually.\n' + + infomsg $'\nCentOS Stream Migration Notes:\n\n' + cat <