2021-05-11 22:55:56 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# migrate2rocky - Migrate another EL8 distribution to RockyLinux 8.
|
|
|
|
# By: Peter Ajamian <peter@pajamian.dhs.org>
|
|
|
|
# Adapted from centos2rocky.sh by label <label@rockylinux.org>
|
|
|
|
#
|
2021-05-31 15:13:33 +00:00
|
|
|
# The latest version of this script can be found at:
|
|
|
|
# https://github.com/rocky-linux/rocky-tools
|
|
|
|
#
|
2021-06-01 05:11:37 +00:00
|
|
|
# Copyright (c) 2021 Rocky Enterprise Software Foundation
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice (including the next
|
|
|
|
# paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
# Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
#
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-06-29 10:35:58 +00:00
|
|
|
## Using this script means you accept all risks of system instability.
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-06-12 12:30:05 +00:00
|
|
|
# These checks need to be right at the top because we start with bash-isms right
|
2021-06-12 11:58:38 +00:00
|
|
|
# away in this script.
|
|
|
|
if [ -n "$POSIXLY_CORRECT" ] || [ -z "$BASH_VERSION" ]; then
|
2021-07-16 04:28:33 +00:00
|
|
|
printf '%s\n' "bash >= 4.2 is required for this script." >&2
|
2021-06-12 11:58:38 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-07-16 04:28:33 +00:00
|
|
|
# We need bash version >= 4.2 for associative arrays and other features.
|
|
|
|
if (( BASH_VERSINFO[0]*100 + BASH_VERSINFO[1] < 402 )); then
|
|
|
|
printf '%s\n' "bash >= 4.2 is required for this script." >&2
|
2021-06-12 12:30:05 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-02-26 06:44:31 +00:00
|
|
|
shopt -s extglob
|
|
|
|
|
2021-06-12 12:36:43 +00:00
|
|
|
# Make sure we're root.
|
|
|
|
if (( EUID != 0 )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' \
|
|
|
|
"You must run this script as root. Either use sudo or 'su -c ${0}'" >&2
|
2021-06-12 12:36:43 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-12 11:58:38 +00:00
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
# Path to logfile
|
2021-05-29 09:22:01 +00:00
|
|
|
logfile=/var/log/migrate2rocky.log
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-12-18 04:12:11 +00:00
|
|
|
# Rotate old logs
|
|
|
|
numlogs=5
|
|
|
|
if [[ -e $logfile ]]; then
|
|
|
|
# Here we use mv before bin_check, so simply check the exit status to see if
|
|
|
|
# it worked.
|
|
|
|
if ! mv -f "$logfile" "$logfile.0"; then
|
|
|
|
printf '%s\n' "Unable to rotate logfiles, continuing without rotation." >&2
|
|
|
|
else
|
|
|
|
for ((i=numlogs;i>0;i--)); do
|
|
|
|
if [[ -e "$logfile.$((i-1))" ]]; then
|
|
|
|
if ! mv -f "$logfile.$((i-1))" "$logfile.$i"; then
|
|
|
|
printf '%s\n' \
|
|
|
|
"Unable to rotate logfiles, continuing without rotation."
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
# Send all output to the logfile as well as stdout.
|
2021-06-20 12:01:02 +00:00
|
|
|
# After the following we get:
|
|
|
|
# Output to 1 goes to stdout and the logfile.
|
|
|
|
# Output to 2 goes to stderr and the logfile.
|
|
|
|
# Output to 3 just goes to stdout.
|
|
|
|
# Output to 4 just goes to stderr.
|
|
|
|
# Output to 5 just goes to the logfile.
|
2021-12-18 04:12:11 +00:00
|
|
|
|
2021-06-20 18:54:44 +00:00
|
|
|
# shellcheck disable=SC2094
|
2021-06-20 12:01:02 +00:00
|
|
|
exec \
|
|
|
|
3>&1 \
|
|
|
|
4>&2 \
|
|
|
|
5>> "$logfile" \
|
|
|
|
> >(tee -a "$logfile") \
|
|
|
|
2> >(tee -a "$logfile" >&2)
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-05-18 12:05:01 +00:00
|
|
|
# List nocolor last here so that -x doesn't bork the display.
|
2021-06-20 12:01:02 +00:00
|
|
|
errcolor=$(tput setaf 1)
|
|
|
|
infocolor=$(tput setaf 6)
|
|
|
|
nocolor=$(tput op)
|
|
|
|
|
|
|
|
# Single arg just gets returned verbatim, multi arg gets formatted via printf.
|
|
|
|
# First arg is the name of a variable to store the results.
|
|
|
|
msg_format () {
|
|
|
|
local _var
|
|
|
|
_var="$1"
|
|
|
|
shift
|
|
|
|
if (( $# > 1 )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
# shellcheck disable=SC2059
|
|
|
|
printf -v "$_var" "$@"
|
2021-06-20 12:01:02 +00:00
|
|
|
else
|
2021-08-14 04:32:10 +00:00
|
|
|
printf -v "$_var" "%s" "$1"
|
2021-06-20 12:01:02 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Send an info message to the log file and stdout (with color)
|
|
|
|
infomsg () {
|
|
|
|
local msg
|
|
|
|
msg_format msg "$@"
|
|
|
|
printf '%s' "$msg" >&5
|
|
|
|
printf '%s%s%s' "$infocolor" "$msg" "$nocolor" >&3
|
|
|
|
}
|
|
|
|
|
|
|
|
# Send an error message to the log file and stderr (with color)
|
|
|
|
errmsg () {
|
|
|
|
local msg
|
|
|
|
msg_format msg "$@"
|
|
|
|
printf '%s' "$msg" >&5
|
|
|
|
printf '%s%s%s' "$errcolor" "$msg" "$nocolor" >&4
|
|
|
|
}
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-12-18 04:12:11 +00:00
|
|
|
infomsg 'migrate2rocky - Begin logging at %(%c)T.\n\n' -1
|
|
|
|
|
2021-08-14 04:37:40 +00:00
|
|
|
export LC_ALL=C.UTF-8
|
|
|
|
unset LANGUAGE
|
2021-05-13 14:26:20 +00:00
|
|
|
shopt -s nullglob
|
2021-05-11 22:55:56 +00:00
|
|
|
|
|
|
|
SUPPORTED_MAJOR="8"
|
|
|
|
SUPPORTED_PLATFORM="platform:el$SUPPORTED_MAJOR"
|
|
|
|
ARCH=$(arch)
|
2021-05-31 16:41:27 +00:00
|
|
|
|
|
|
|
gpg_key_url="https://dl.rockylinux.org/pub/rocky/RPM-GPG-KEY-rockyofficial"
|
|
|
|
gpg_key_sha512="88fe66cf0a68648c2371120d56eb509835266d9efdf7c8b9ac8fc101bdf1f0e0197030d3ea65f4b5be89dc9d1ef08581adb068815c88d7b1dc40aa1c32990f6a"
|
|
|
|
|
2021-06-20 17:10:24 +00:00
|
|
|
sm_ca_dir=/etc/rhsm/ca
|
|
|
|
unset tmp_sm_ca_dir
|
|
|
|
|
2021-05-31 16:41:27 +00:00
|
|
|
# all repos must be signed with the same key given in $gpg_key_url
|
|
|
|
declare -A repo_urls
|
2021-05-11 22:55:56 +00:00
|
|
|
repo_urls=(
|
2021-05-31 16:41:27 +00:00
|
|
|
[rockybaseos]="https://dl.rockylinux.org/pub/rocky/${SUPPORTED_MAJOR}/BaseOS/$ARCH/os/"
|
|
|
|
[rockyappstream]="https://dl.rockylinux.org/pub/rocky/${SUPPORTED_MAJOR}/AppStream/$ARCH/os/"
|
2021-05-11 22:55:56 +00:00
|
|
|
)
|
|
|
|
|
2021-11-24 12:19:09 +00:00
|
|
|
# These are additional packages that should always be installed.
|
|
|
|
# (currently blank, but we add to it for an EFI boot system).
|
|
|
|
always_install=()
|
|
|
|
|
2021-08-13 13:35:50 +00:00
|
|
|
# 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
|
|
|
|
)
|
2021-11-23 11:21:41 +00:00
|
|
|
|
2021-12-20 20:06:55 +00:00
|
|
|
# Map for package name suffix for shim/grub2-efi
|
|
|
|
# on x86_64: grub2-efi-x64, shim-x64
|
|
|
|
# on aarch64: grub2-efi-aa64, shim-aa64
|
|
|
|
declare -A cpu_arch_suffix_map=(
|
|
|
|
[x86_64]=x64
|
|
|
|
[aarch64]=aa64
|
|
|
|
)
|
|
|
|
|
2021-08-13 13:35:50 +00:00
|
|
|
# Prefix to add to CentOS stream repo names when renaming them.
|
|
|
|
stream_prefix=stream-
|
|
|
|
|
2021-11-23 11:21:41 +00:00
|
|
|
# Always replace these stream packages with their Rocky Linux equivalents.
|
|
|
|
stream_always_replace=(
|
|
|
|
fwupdate\*
|
|
|
|
grub2-\*
|
2021-11-24 11:29:46 +00:00
|
|
|
shim-\*
|
2021-11-23 11:21:41 +00:00
|
|
|
kernel
|
|
|
|
kernel-\*
|
|
|
|
)
|
|
|
|
|
2021-12-18 12:53:55 +00:00
|
|
|
# Directory to required space in MiB
|
|
|
|
declare -A dir_space_map
|
|
|
|
dir_space_map=(
|
|
|
|
[/usr]=250
|
|
|
|
[/var]=1536
|
|
|
|
[/boot]=50
|
|
|
|
)
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
unset CDPATH
|
|
|
|
|
|
|
|
exit_message() {
|
2021-06-20 12:01:02 +00:00
|
|
|
errmsg $'\n'"$1"$'\n\n'
|
2021-05-11 22:55:56 +00:00
|
|
|
final_message
|
|
|
|
exit 1
|
2021-06-20 12:01:02 +00:00
|
|
|
}
|
2021-05-11 22:55:56 +00:00
|
|
|
|
|
|
|
final_message() {
|
2021-06-20 12:01:02 +00:00
|
|
|
errmsg '%s ' \
|
2021-08-14 04:32:10 +00:00
|
|
|
"An error occurred while we were attempting to convert your system to" \
|
|
|
|
"Rocky Linux. Your system may be unstable. Script will now exit to" \
|
|
|
|
"prevent possible damage."$'\n\n'
|
2021-06-20 12:01:02 +00:00
|
|
|
logmessage
|
2021-05-11 22:55:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
logmessage(){
|
2021-06-20 12:01:02 +00:00
|
|
|
printf '%s%s%s\n' "$infocolor" \
|
2021-08-14 04:32:10 +00:00
|
|
|
"A log of this installation can be found at $logfile" \
|
|
|
|
"$nocolor" >&3
|
2021-05-11 22:55:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# This just grabs a field from os-release and returns it.
|
2021-05-11 23:11:36 +00:00
|
|
|
os-release () (
|
2022-01-11 08:56:51 +00:00
|
|
|
# shellcheck source=/dev/null
|
2021-05-11 22:55:56 +00:00
|
|
|
. /etc/os-release
|
|
|
|
if ! [[ ${!1} ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
return 1
|
2021-05-11 22:55:56 +00:00
|
|
|
fi
|
|
|
|
printf '%s\n' "${!1}"
|
2021-05-11 23:11:36 +00:00
|
|
|
)
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-05-29 02:17:06 +00:00
|
|
|
# Check the version of a package against a supplied version number. Note that
|
|
|
|
# this uses sort -V to compare the versions which isn't perfect for rpm package
|
|
|
|
# versions, but to do a proper comparison we would need to use rpmdev-vercmp in
|
|
|
|
# the rpmdevtools package which we don't want to force-install. sort -V should
|
|
|
|
# be adequate for our needs here.
|
|
|
|
pkg_ver() (
|
|
|
|
ver=$(rpm -q --qf '%{VERSION}\n' "$1") || return 2
|
2021-06-03 14:16:43 +00:00
|
|
|
if [[ $(sort -V <<<"$ver"$'\n'"$2" | head -1) != "$2" ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
return 1
|
2021-05-29 02:17:06 +00:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
)
|
|
|
|
|
2021-06-20 17:10:24 +00:00
|
|
|
# Set up a temporary directory.
|
|
|
|
pre_setup () {
|
|
|
|
if ! tmp_dir=$(mktemp -d) || [[ ! -d "$tmp_dir" ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message "Error creating temp dir"
|
2021-06-20 17:10:24 +00:00
|
|
|
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
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message "Temp dir not empty"
|
2021-06-20 17:10:24 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Cleanup function gets rid of the temporary directory.
|
|
|
|
exit_clean () {
|
|
|
|
if [[ -d "$tmp_dir" ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
rm -rf "$tmp_dir"
|
2021-06-20 17:10:24 +00:00
|
|
|
fi
|
2021-08-09 11:35:39 +00:00
|
|
|
if [[ -f "$container_macros" ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
rm -f "$container_macros"
|
2021-08-09 11:35:39 +00:00
|
|
|
fi
|
2021-06-20 17:10:24 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 23:51:02 +00:00
|
|
|
pre_check () {
|
|
|
|
if [[ -e /etc/rhsm/ca/katello-server-ca.pem ]]; then
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2026
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message \
|
|
|
|
'Migration from Katello-modified systems is not supported by migrate2rocky. '\
|
|
|
|
'See the README file for details.'
|
2021-06-20 21:08:30 +00:00
|
|
|
fi
|
2021-06-21 20:52:27 +00:00
|
|
|
if [[ -e /etc/salt/minion.d/susemanager.conf ]]; then
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2026
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message \
|
|
|
|
'Migration from Uyuni/SUSE Manager-modified systems is not supported by '\
|
|
|
|
'migrate2rocky. See the README file for details.'
|
2021-06-04 23:51:02 +00:00
|
|
|
fi
|
2021-12-18 12:53:55 +00:00
|
|
|
|
2022-03-04 02:37:58 +00:00
|
|
|
dnf -y check || exit_message \
|
|
|
|
'Errors found in dnf/rpm database. Please correct before running '\
|
|
|
|
'migrate2rocky.'
|
|
|
|
|
2021-12-18 12:53:55 +00:00
|
|
|
# Get available space to compare to requirements.
|
|
|
|
# If the stock kernel is not installed we don't require space in /boot
|
|
|
|
if ! rpm -q --quiet kernel; then
|
|
|
|
dir_space_map[/boot]=0
|
|
|
|
fi
|
|
|
|
local -a errs dirs=("${!dir_space_map[@]}")
|
|
|
|
local dir mount avail i=0
|
2022-01-11 08:56:51 +00:00
|
|
|
local -A mount_avail_map mount_space_map
|
2021-12-18 12:53:55 +00:00
|
|
|
while read -r mount avail; do
|
|
|
|
if [[ $mount == 'Filesystem' ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
dir=${dirs[$((i++))]}
|
|
|
|
|
|
|
|
mount_avail_map[$mount]=${avail%M}
|
|
|
|
(( mount_space_map[$mount]+=dir_space_map[$dir] ))
|
|
|
|
done < <(df -BM --output=source,avail "${dirs[@]}")
|
|
|
|
|
|
|
|
for mount in "${!mount_space_map[@]}"; do
|
|
|
|
(( avail = mount_avail_map[$mount]*95/100 ))
|
|
|
|
if (( avail < mount_space_map[$mount] )); then
|
|
|
|
errs+=("Not enough space in $mount, ${mount_space_map[$mount]}M required, ${avail}M available.")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if (( ${#errs[@]} )); then
|
|
|
|
IFS=$'\n'
|
|
|
|
exit_message "${errs[*]}"
|
|
|
|
fi
|
2021-06-04 23:51:02 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
# All of the binaries used by this script are available in a EL8 minimal install
|
|
|
|
# and are in /bin, so we should not encounter a system where the script doesn't
|
2021-08-14 04:32:10 +00:00
|
|
|
# work unless it's severely broken. This is just a simple check that will cause
|
2021-05-11 22:55:56 +00:00
|
|
|
# the script to bail if any expected system utilities are missing.
|
|
|
|
bin_check() {
|
2021-06-12 11:58:38 +00:00
|
|
|
# Check the platform.
|
|
|
|
if [[ $(os-release PLATFORM_ID) != "$SUPPORTED_PLATFORM" ]]; then
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2026
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message \
|
|
|
|
'This script must be run on an EL8 distribution. Migration from other '\
|
|
|
|
'distributions is not supported.'
|
2021-06-12 11:58:38 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-29 06:33:57 +00:00
|
|
|
local -a missing bins
|
|
|
|
bins=(
|
2021-12-18 12:53:55 +00:00
|
|
|
rpm dnf awk column tee tput mkdir cat arch sort uniq rmdir df
|
2021-11-18 01:31:33 +00:00
|
|
|
rm head curl sha512sum mktemp systemd-detect-virt sed grep
|
2021-05-29 06:33:57 +00:00
|
|
|
)
|
|
|
|
if [[ $update_efi ]]; then
|
2021-11-18 01:31:33 +00:00
|
|
|
bins+=(findmnt grub2-mkconfig efibootmgr mokutil lsblk)
|
2021-05-29 06:33:57 +00:00
|
|
|
fi
|
|
|
|
for bin in "${bins[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
if ! type "$bin" >/dev/null 2>&1; then
|
|
|
|
missing+=("$bin")
|
|
|
|
fi
|
2021-05-11 22:55:56 +00:00
|
|
|
done
|
|
|
|
|
2021-07-09 04:28:03 +00:00
|
|
|
local -A pkgs
|
|
|
|
pkgs=(
|
2021-08-14 04:32:10 +00:00
|
|
|
[dnf]=4.2
|
|
|
|
[dnf-plugins-core]=0
|
2021-07-09 04:28:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
for pkg in "${!pkgs[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
ver=${pkgs[$pkg]}
|
|
|
|
if ! pkg_ver "$pkg" "$ver"; then
|
|
|
|
# shellcheck disable=SC2140
|
|
|
|
exit_message \
|
2021-07-09 04:28:03 +00:00
|
|
|
"$pkg >= $ver is required for this script. Please run "\
|
|
|
|
"\"dnf install $pkg; dnf update\" first."
|
2021-08-14 04:32:10 +00:00
|
|
|
fi
|
2021-07-09 04:28:03 +00:00
|
|
|
done;
|
2021-05-29 02:17:06 +00:00
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
if (( ${#missing[@]} )); then
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2140
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message \
|
|
|
|
"Commands not found: ${missing[*]}. Possible bad PATH setting or corrupt "\
|
|
|
|
"installation."
|
2021-05-11 22:55:56 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# This function will overwrite the repoquery_results associative array with the
|
|
|
|
# info for the resulting package. Note that we explicitly disable the epel repo
|
|
|
|
# as a special-case below to avoid having the extras repository map to epel.
|
|
|
|
repoquery () {
|
2021-06-03 14:16:43 +00:00
|
|
|
local name val prev result
|
2022-02-11 01:46:51 +00:00
|
|
|
result=$(safednf -y -q "${dist_repourl_swaps[@]}" \
|
|
|
|
--setopt=epel.excludepkgs=epel-release repoquery -i "$1") ||
|
|
|
|
exit_message "Failed to fetch info for package $1."
|
2021-05-11 22:55:56 +00:00
|
|
|
if ! [[ $result ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
# We didn't match this package, the repo could be disabled.
|
|
|
|
return 1
|
2021-05-11 22:55:56 +00:00
|
|
|
fi
|
|
|
|
declare -gA repoquery_results=()
|
|
|
|
while IFS=" :" read -r name val; do
|
2021-08-14 04:32:10 +00:00
|
|
|
if [[ -z $name ]]; then
|
|
|
|
repoquery_results[$prev]+=" $val"
|
|
|
|
else
|
|
|
|
prev=$name
|
|
|
|
repoquery_results[$name]=$val
|
|
|
|
fi
|
2021-05-11 22:55:56 +00:00
|
|
|
done <<<"$result"
|
|
|
|
}
|
|
|
|
|
|
|
|
# This function will overwrite the repoinfo_results associative array with the
|
|
|
|
# info for the resulting repository.
|
2022-02-01 10:54:27 +00:00
|
|
|
_repoinfo () {
|
2021-05-11 22:55:56 +00:00
|
|
|
local name val result
|
2022-02-01 10:54:27 +00:00
|
|
|
result=$(
|
|
|
|
safednf -y -q --repo="$1" "${dist_repourl_swaps[@]}" repoinfo "$1"
|
|
|
|
) || return
|
2021-05-11 22:55:56 +00:00
|
|
|
if [[ $result == 'Total packages: 0' ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
# We didn't match this repo.
|
|
|
|
return 1
|
2021-05-11 22:55:56 +00:00
|
|
|
fi
|
|
|
|
declare -gA repoinfo_results=()
|
|
|
|
while IFS=" :" read -r name val; do
|
2021-08-14 04:32:10 +00:00
|
|
|
if [[ ! ( $name || $val) ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [[ -z $name ]]; then
|
|
|
|
repoinfo_results[$prev]+=" $val"
|
|
|
|
else
|
|
|
|
prev=$name
|
|
|
|
repoinfo_results[$name]=$val
|
|
|
|
fi
|
2021-05-11 22:55:56 +00:00
|
|
|
done <<<"$result"
|
|
|
|
|
2022-02-01 10:54:27 +00:00
|
|
|
# Set the enabled state
|
|
|
|
if [[ ! ${enabled_repo_check[$1]} ]]; then
|
|
|
|
repoinfo_results[Repo-status]=disabled
|
|
|
|
fi
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
# dnf repoinfo doesn't return the gpgkey, but we need that so we have to get
|
|
|
|
# it from the repo file itself.
|
2021-05-13 14:26:20 +00:00
|
|
|
# "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.
|
2021-06-20 18:54:44 +00:00
|
|
|
# shellcheck disable=SC2154
|
2021-05-11 22:55:56 +00:00
|
|
|
repoinfo_results[Repo-gpgkey]=$(
|
2021-08-14 04:32:10 +00:00
|
|
|
awk '
|
|
|
|
$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]}"
|
2021-05-11 22:55:56 +00:00
|
|
|
)
|
2021-05-14 03:18:43 +00:00
|
|
|
|
|
|
|
# Add an indicator of whether this is a subscription-manager managed
|
|
|
|
# repository.
|
2021-06-20 18:54:44 +00:00
|
|
|
# shellcheck disable=SC2154
|
2021-05-14 03:18:43 +00:00
|
|
|
repoinfo_results[Repo-managed]=$(
|
2021-08-14 04:32:10 +00:00
|
|
|
awk '
|
2021-05-14 03:18:43 +00:00
|
|
|
BEGIN {FS="[)(]"}
|
|
|
|
/^# Managed by \(.*\) subscription-manager$/ {print $2}
|
|
|
|
' < "${repoinfo_results[Repo-filename]}"
|
|
|
|
)
|
2021-05-11 22:55:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 10:54:27 +00:00
|
|
|
# We now store the repoinfo results in a cache.
|
|
|
|
declare -g -A repoinfo_results_cache=()
|
|
|
|
repoinfo () {
|
2022-02-26 06:44:31 +00:00
|
|
|
local k
|
2022-02-01 10:54:27 +00:00
|
|
|
if [[ ! ${repoinfo_results_cache[$1]} ]]; then
|
|
|
|
_repoinfo "$@" || return
|
|
|
|
repoinfo_results_cache[$1]=1
|
|
|
|
for k in "${!repoinfo_results[@]}"; do
|
|
|
|
repoinfo_results_cache[$1:$k]=${repoinfo_results[$k]}
|
|
|
|
done
|
|
|
|
else
|
|
|
|
repoinfo_results=()
|
|
|
|
for k in "${!repoinfo_results_cache[@]}"; do
|
|
|
|
local repo=${k%%:*} key=${k#*:}
|
|
|
|
if [[ $repo != "$1" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
repoinfo_results[$key]=${repoinfo_results_cache[$k]}
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-05-13 14:26:20 +00:00
|
|
|
provides_pkg () (
|
2021-05-14 03:18:43 +00:00
|
|
|
if [[ ! $1 ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
return 0
|
2021-05-14 03:18:43 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-13 14:26:20 +00:00
|
|
|
set -o pipefail
|
2022-02-01 10:54:27 +00:00
|
|
|
provides=$(
|
|
|
|
safednf -y -q "${dist_repourl_swaps[@]}" provides "$1" |
|
|
|
|
awk '{print $1; nextfile}'
|
|
|
|
) ||
|
2021-08-14 04:32:10 +00:00
|
|
|
return 1
|
2021-05-13 14:26:20 +00:00
|
|
|
set +o pipefail
|
2021-06-04 10:11:15 +00:00
|
|
|
pkg=$(rpm -q --queryformat '%{NAME}\n' "$provides") ||
|
2022-02-01 10:54:27 +00:00
|
|
|
pkg=$(
|
|
|
|
safednf -y -q "${dist_repourl_swaps[@]}" repoquery \
|
|
|
|
--queryformat '%{NAME}\n' "$provides"
|
|
|
|
) || exit_message "Can't get package name for $provides."
|
2021-05-13 14:26:20 +00:00
|
|
|
printf '%s\n' "$pkg"
|
|
|
|
)
|
|
|
|
|
2021-06-04 10:11:15 +00:00
|
|
|
# If you pass an empty arg as one of the package specs to rpm it will match
|
2021-08-14 04:32:10 +00:00
|
|
|
# every package on the system. This function simply strips out any empty args
|
2021-06-04 10:11:15 +00:00
|
|
|
# and passes the rest to rpm to avoid this side-effect.
|
|
|
|
saferpm () (
|
|
|
|
args=()
|
|
|
|
for a in "$@"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
if [[ $a ]]; then
|
|
|
|
args+=("$a")
|
|
|
|
fi
|
2021-06-04 10:11:15 +00:00
|
|
|
done
|
|
|
|
rpm "${args[@]}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# And a similar function for dnf
|
|
|
|
safednf () (
|
|
|
|
args=()
|
|
|
|
for a in "$@"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
if [[ $a ]]; then
|
|
|
|
args+=("$a")
|
|
|
|
fi
|
2021-06-04 10:11:15 +00:00
|
|
|
done
|
|
|
|
dnf "${args[@]}"
|
|
|
|
)
|
|
|
|
|
2022-02-01 10:54:27 +00:00
|
|
|
#
|
|
|
|
# Three ways we check the repourl. If dnf repoinfo fails then we assume the URL
|
|
|
|
# is bad. A missing URL is also considered bad. Lastly we check to see if we
|
|
|
|
# can fetch the repomd.xml file from the repository, and if not then the repourl
|
|
|
|
# is considered bad. In any of these cases we'll end up replacing the repourl
|
|
|
|
# with a good one from our mirror of CentOS vault.
|
|
|
|
#
|
|
|
|
check_repourl () {
|
|
|
|
repoinfo "$1" || return
|
|
|
|
if [[ ! ${repoinfo_results[Repo-baseurl]} ]]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2022-02-26 06:44:31 +00:00
|
|
|
local -a urls;
|
|
|
|
IFS=, read -r -a urls <<<"${repoinfo_results[Repo-baseurl]}"
|
|
|
|
local u
|
|
|
|
for u in "${urls[@]##*( )}"; do
|
|
|
|
curl -sfLI "${u%% *}repodata/repomd.xml" > /dev/null && return
|
|
|
|
done
|
|
|
|
return "$(( $? ? $? : 1 ))"
|
2022-02-01 10:54:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
collect_system_info () {
|
2021-07-15 06:23:36 +00:00
|
|
|
# Dump the DNF cache first so we start with a clean slate.
|
|
|
|
infomsg $'\nRemoving dnf cache\n'
|
|
|
|
rm -rf /var/cache/{yum,dnf}
|
2021-05-29 06:33:57 +00:00
|
|
|
# Check the efi mount first, so we can bail before wasting time on all these
|
|
|
|
# other checks if it's not there.
|
|
|
|
if [[ $update_efi ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
local efi_mount kname
|
|
|
|
declare -g -a efi_disk efi_partition
|
|
|
|
efi_mount=$(findmnt --mountpoint /boot/efi --output SOURCE \
|
|
|
|
--noheadings) ||
|
|
|
|
exit_message "Can't find EFI mount. No EFI boot detected."
|
|
|
|
kname=$(lsblk -dno kname "$efi_mount")
|
2022-01-11 08:56:51 +00:00
|
|
|
efi_disk=("$(lsblk -dno pkname "/dev/$kname")")
|
2021-08-14 04:32:10 +00:00
|
|
|
|
2022-01-11 08:56:51 +00:00
|
|
|
if [[ ${efi_disk[0]} ]]; then
|
|
|
|
efi_partition=("$(<"/sys/block/${efi_disk[0]}/$kname/partition")")
|
2021-08-14 04:32:10 +00:00
|
|
|
else
|
|
|
|
# This is likely an md-raid or other type of virtual disk, we need
|
|
|
|
# to dig a little deeper to find the actual physical disks and
|
|
|
|
# partitions.
|
|
|
|
kname=$(lsblk -dno kname "$efi_mount")
|
|
|
|
cd "/sys/block/$kname/slaves" || exit_message \
|
2021-07-08 02:04:18 +00:00
|
|
|
"Unable to gather EFI data: Can't cd to /sys/block/$kname/slaves."
|
2021-08-14 04:32:10 +00:00
|
|
|
if ! (shopt -s failglob; : ./*) 2>/dev/null; then
|
|
|
|
exit_message \
|
2021-07-08 02:04:18 +00:00
|
|
|
"Unable to gather EFI data: No slaves found in /sys/block/$kname/slaves."
|
2021-08-14 04:32:10 +00:00
|
|
|
fi
|
|
|
|
efi_disk=()
|
|
|
|
for d in *; do
|
|
|
|
efi_disk+=("$(lsblk -dno pkname "/dev/$d")")
|
|
|
|
efi_partition+=("$(<"$d/partition")")
|
|
|
|
if [[ ! ${efi_disk[-1]} || ! ${efi_partition[-1]} ]]; then
|
|
|
|
exit_message \
|
2021-07-08 02:04:18 +00:00
|
|
|
"Unable to gather EFI data: Can't find disk name or partition number for $d."
|
2021-08-14 04:32:10 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
cd -
|
|
|
|
fi
|
2021-11-24 12:19:09 +00:00
|
|
|
|
|
|
|
# We need to make sure that these packages are always installed in an
|
|
|
|
# EFI system.
|
|
|
|
always_install+=(
|
2021-12-20 20:06:55 +00:00
|
|
|
"shim-${cpu_arch_suffix_map[$ARCH]}"
|
|
|
|
"grub2-efi-${cpu_arch_suffix_map[$ARCH]}"
|
2021-11-24 12:19:09 +00:00
|
|
|
)
|
2021-05-29 06:33:57 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-18 11:43:58 +00:00
|
|
|
# Don't enable these module streams, even if they are enabled in the source
|
|
|
|
# distro.
|
|
|
|
declare -g -a module_excludes
|
|
|
|
module_excludes=(
|
2021-08-14 04:32:10 +00:00
|
|
|
libselinux-python:2.8
|
2021-05-18 11:43:58 +00:00
|
|
|
)
|
|
|
|
|
2021-07-15 07:16:25 +00:00
|
|
|
# Some OracleLinux modules have stream names of ol8 instead of rhel8 and ol
|
|
|
|
# instead of rhel. This is a map that does a glob match and replacement.
|
2021-07-15 11:13:07 +00:00
|
|
|
local -A module_glob_map
|
2021-07-15 07:16:25 +00:00
|
|
|
module_glob_map=(
|
2021-08-14 04:32:10 +00:00
|
|
|
['%:ol8']=:rhel8
|
|
|
|
['%:ol']=:rhel
|
2021-07-15 07:16:25 +00:00
|
|
|
);
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
# 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
|
|
|
|
# repository and see what repo they came from. We need to use repoquery for
|
|
|
|
# this which requires downloading the package, so we pick relatively small
|
|
|
|
# packages for this.
|
|
|
|
declare -g -A repo_map pkg_repo_map
|
2021-05-14 03:18:43 +00:00
|
|
|
declare -g -a managed_repos
|
2021-05-11 22:55:56 +00:00
|
|
|
pkg_repo_map=(
|
2021-08-14 04:32:10 +00:00
|
|
|
[baseos]=rootfiles.noarch
|
|
|
|
[appstream]=apr-util-ldap.$ARCH
|
|
|
|
[ha]=pacemaker-doc.noarch
|
|
|
|
[powertools]=libaec-devel.$ARCH
|
|
|
|
[extras]=epel-release.noarch
|
2022-02-01 10:54:27 +00:00
|
|
|
[devel]=quota-devel.$ARCH
|
2021-05-11 22:55:56 +00:00
|
|
|
)
|
2022-02-01 10:54:27 +00:00
|
|
|
|
|
|
|
dist_id=$(os-release ID)
|
|
|
|
# We need a different dist ID for CentOS Linux vs CentOS Stream
|
|
|
|
if [[ $dist_id == centos ]] && rpm --quiet -q centos-stream-release; then
|
|
|
|
dist_id+=-stream
|
|
|
|
fi
|
2021-05-11 22:55:56 +00:00
|
|
|
|
|
|
|
PRETTY_NAME=$(os-release PRETTY_NAME)
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg '%s' \
|
2022-02-01 10:54:27 +00:00
|
|
|
"Preparing to migrate $PRETTY_NAME to Rocky Linux 8."$'\n\n'
|
|
|
|
|
|
|
|
# Check to see if we need to change the repourl on any system repositories
|
|
|
|
# (CentOS 8)
|
|
|
|
local -A dist_repourl_map
|
|
|
|
dist_repourl_map=(
|
|
|
|
[centos:baseos]=https://dl.rockylinux.org/vault/centos/8.5.2111/BaseOS/$ARCH/os/
|
|
|
|
[centos:appstream]=https://dl.rockylinux.org/vault/centos/8.5.2111/AppStream/$ARCH/os/
|
|
|
|
[centos:ha]=https://dl.rockylinux.org/vault/centos/8.5.2111/HighAvailability/$ARCH/os/
|
|
|
|
[centos:powertools]=https://dl.rockylinux.org/vault/centos/8.5.2111/PowerTools/$ARCH/os/
|
|
|
|
[centos:extras]=https://dl.rockylinux.org/vault/centos/8.5.2111/extras/$ARCH/os/
|
|
|
|
[centos:devel]=https://dl.rockylinux.org/vault/centos/8.5.2111/Devel/$ARCH/os/
|
2024-07-07 09:29:44 +00:00
|
|
|
[centos-stream:appstream]=https://dl.rockylinux.org/vault/centos/8-stream/AppStream/$ARCH/os/
|
|
|
|
[centos-stream:baseos]=https://dl.rockylinux.org/vault/centos/8-stream/BaseOS/$ARCH/os/
|
|
|
|
[centos-stream:ha]=https://dl.rockylinux.org/vault/centos/8-stream/HighAvailability/$ARCH/os/
|
|
|
|
[centos-stream:nfv]=https://dl.rockylinux.org/vault/centos/8-stream/NFV/$ARCH/os/
|
|
|
|
[centos-stream:powertools]=https://dl.rockylinux.org/vault/centos/8-stream/PowerTools/$ARCH/os/
|
|
|
|
[centos-stream:rt]=https://dl.rockylinux.org/vault/centos/8-stream/RT/$ARCH/os/
|
|
|
|
[centos-stream:resilientstorage]=https://dl.rockylinux.org/vault/centos/8-stream/ResiliientStorage/$ARCH/os/
|
|
|
|
[centos-stream:centosplus]=https://dl.rockylinux.org/vault/centos/8-stream/centosplus/$ARCH/os/
|
|
|
|
[centos-stream:cloud]=https://dl.rockylinux.org/vault/centos/8-stream/cloud/$ARCH/os/
|
|
|
|
[centos-stream:core]=https://dl.rockylinux.org/vault/centos/8-stream/core/$ARCH/os/
|
|
|
|
[centos-stream:extras]=https://dl.rockylinux.org/vault/centos/8-stream/extras/$ARCH/os/
|
|
|
|
[centos-stream:hyperscale]=https://dl.rockylinux.org/vault/centos/8-stream/hyperscale/$ARCH/os/
|
|
|
|
[centos-stream:isos]=https://dl.rockylinux.org/vault/centos/8-stream/isos/$ARCH/os/
|
|
|
|
[centos-stream:kmods]=https://dl.rockylinux.org/vault/centos/8-stream/kmods/$ARCH/os/
|
|
|
|
[centos-stream:messaging]=https://dl.rockylinux.org/vault/centos/8-stream/messaging/$ARCH/os/
|
|
|
|
[centos-stream:opstools]=https://dl.rockylinux.org/vault/centos/8-stream/opstools/$ARCH/os/
|
|
|
|
[centos-stream:storage]=https://dl.rockylinux.org/vault/centos/8-stream/storage/$ARCH/os/
|
|
|
|
[centos-stream:virt]=https://dl.rockylinux.org/vault/centos/8-stream/virt/$ARCH/os/
|
|
|
|
[centos-stream:debuginfo]=http://debuginfo.centos.org/8-stream/$ARCH/
|
|
|
|
[centos-stream:extras-common]=https://dl.rockylinux.org/vault/centos/8-stream/extras/$ARCH/extras-common/
|
2022-02-01 10:54:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# In case migration is attempted from very old CentOS (before the repository
|
|
|
|
# names were lowercased)
|
|
|
|
for name in BaseOS AppStream PowerTools Devel; do
|
|
|
|
dist_repourl_map["centos:$name"]=${dist_repourl_map["centos:${name,,}"]}
|
|
|
|
done
|
|
|
|
|
|
|
|
# HighAvailability is different again
|
|
|
|
dist_repourl_map[centos:HighAvailability]=${dist_repourl_map[centos:ha]}
|
2024-07-07 09:29:44 +00:00
|
|
|
dist_repourl_map[centos-stream:HighAvailability]=${dist_repourl_map[centos-stream:ha]}
|
|
|
|
dist_repourl_map[centos-stream:RealTime]=${dist_repourl_map[centos-stream:rt]}
|
|
|
|
|
2022-02-01 10:54:27 +00:00
|
|
|
|
|
|
|
# We need a list of enabled repositories
|
|
|
|
local -a enabled_repos=()
|
|
|
|
declare -g -A enabled_repo_check=()
|
|
|
|
declare -g -a dist_repourl_swaps=()
|
|
|
|
readarray -s 1 -t enabled_repos < <(dnf -q -y repolist --enabled)
|
|
|
|
for r in "${enabled_repos[@]}"; do
|
|
|
|
enabled_repo_check[${r%% *}]=1
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# ...and finally set a number of dnf options to replace the baseurl of these
|
|
|
|
# repos
|
2022-02-26 06:44:31 +00:00
|
|
|
local k
|
2022-02-01 10:54:27 +00:00
|
|
|
for k in "${!dist_repourl_map[@]}"; do
|
|
|
|
local d=${k%%:*} r=${k#*:}
|
|
|
|
if [[ $d != "$dist_id" || ! ${enabled_repo_check[$r]} ]] ||
|
|
|
|
check_repourl "$r"; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
dist_repourl_swaps+=(
|
|
|
|
"--setopt=$r.mirrorlist="
|
|
|
|
"--setopt=$r.metalink="
|
|
|
|
"--setopt=$r.baseurl="
|
|
|
|
"--setopt=$r.baseurl=${dist_repourl_map[$k]}"
|
|
|
|
)
|
|
|
|
|
|
|
|
infomsg 'Baseurl for %s is invalid, setting to %s.\n' \
|
|
|
|
"$r" "${dist_repourl_map[$k]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
infomsg '%s' "Determining repository names for $PRETTY_NAME"
|
2021-05-11 22:55:56 +00:00
|
|
|
|
|
|
|
for r in "${!pkg_repo_map[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '.'
|
|
|
|
p=${pkg_repo_map[$r]}
|
|
|
|
repoquery "$p" || continue
|
|
|
|
repo_map[$r]=${repoquery_results[Repository]}
|
2021-05-11 22:55:56 +00:00
|
|
|
done
|
|
|
|
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' '' '' \
|
|
|
|
"Found the following repositories which map from $PRETTY_NAME to Rocky Linux 8:"
|
|
|
|
column -t -s $'\t' -N "$PRETTY_NAME,Rocky Linux 8" < <(
|
|
|
|
for r in "${!repo_map[@]}"; do
|
|
|
|
printf '%s\t%s\n' "${repo_map[$r]}" "$r"
|
|
|
|
done
|
|
|
|
)
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg $'\n'"Getting system package names for $PRETTY_NAME"
|
2021-05-11 22:55:56 +00:00
|
|
|
|
|
|
|
# We don't know what the names of these packages are, we have to discover
|
|
|
|
# them via various means. The most common means is to look for either a
|
|
|
|
# distro-agnostic provides or a filename. In a couple of cases we need to
|
|
|
|
# jump through hoops to get a filename that is provided specifically by the
|
|
|
|
# source distro.
|
2021-05-14 03:18:43 +00:00
|
|
|
# Get info for each repository to determine which ones are subscription
|
|
|
|
# managed.
|
|
|
|
# system-release here is a bit of a hack, but it ensures that the
|
|
|
|
# rocky-repos package will get installed.
|
|
|
|
for r in "${!repo_map[@]}"; do
|
2022-02-01 10:54:27 +00:00
|
|
|
repoinfo "${repo_map[$r]}" ||
|
|
|
|
exit_message "Failed to fetch info for repository ${repo_map[$r]}."
|
|
|
|
|
2021-08-14 04:32:10 +00:00
|
|
|
if [[ $r == "baseos" ]]; then
|
|
|
|
local baseos_filename=system-release
|
|
|
|
if [[ ! ${repoinfo_results[Repo-managed]} ]]; then
|
|
|
|
baseos_filename="${repoinfo_results[Repo-filename]}"
|
|
|
|
fi
|
|
|
|
local baseos_gpgkey="${repoinfo_results[Repo-gpgkey]}"
|
|
|
|
fi
|
|
|
|
if [[ ${repoinfo_results[Repo-managed]} ]]; then
|
|
|
|
managed_repos+=("${repo_map[$r]}")
|
|
|
|
fi
|
2021-05-14 03:18:43 +00:00
|
|
|
done
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
# First get info for the baseos repo
|
2022-02-01 10:54:27 +00:00
|
|
|
repoinfo "${repo_map[baseos]}" ||
|
|
|
|
exit_message "Failed to fetch info for repository ${repo_map[baseos]}."
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
declare -g -A pkg_map provides_pkg_map
|
2021-05-13 14:26:20 +00:00
|
|
|
declare -g -a addl_provide_removes addl_pkg_removes
|
2021-05-11 22:55:56 +00:00
|
|
|
provides_pkg_map=(
|
2021-08-14 04:32:10 +00:00
|
|
|
[rocky-backgrounds]=system-backgrounds
|
|
|
|
[rocky-indexhtml]=redhat-indexhtml
|
|
|
|
[rocky-repos]="$baseos_filename"
|
|
|
|
[rocky-logos]=system-logos
|
|
|
|
[rocky-logos-httpd]=system-logos-httpd
|
|
|
|
[rocky-logos-ipa]=system-logos-ipa
|
|
|
|
[rocky-gpg-keys]="$baseos_gpgkey"
|
|
|
|
[rocky-release]=system-release
|
2021-05-11 22:55:56 +00:00
|
|
|
)
|
2021-05-13 14:26:20 +00:00
|
|
|
addl_provide_removes=(
|
2021-08-14 04:32:10 +00:00
|
|
|
redhat-release
|
|
|
|
redhat-release-eula
|
2021-05-13 14:26:20 +00:00
|
|
|
)
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-07-01 06:55:27 +00:00
|
|
|
# Check to make sure that we don't already have a full or partial
|
|
|
|
# RockyLinux install.
|
|
|
|
if [[ $(rpm -qa "${!provides_pkg_map[@]}") ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message \
|
2021-07-01 06:55:27 +00:00
|
|
|
$'Found a full or partial RockyLinux install already in place. Aborting\n'
|
|
|
|
$'because continuing with the migration could cause further damage to system.'
|
|
|
|
fi
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
for pkg in "${!provides_pkg_map[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '.'
|
|
|
|
prov=${provides_pkg_map[$pkg]}
|
|
|
|
pkg_map[$pkg]=$(provides_pkg "$prov") ||
|
|
|
|
exit_message "Can't get package that provides $prov."
|
2021-05-13 14:26:20 +00:00
|
|
|
done
|
|
|
|
for prov in "${addl_provide_removes[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '.'
|
|
|
|
local pkg;
|
|
|
|
pkg=$(provides_pkg "$prov") || continue
|
|
|
|
addl_pkg_removes+=("$pkg")
|
2021-05-11 22:55:56 +00:00
|
|
|
done
|
|
|
|
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2140
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' '' '' \
|
|
|
|
"Found the following system packages which map from $PRETTY_NAME to Rocky "\
|
|
|
|
"Linux 8:"
|
|
|
|
column -t -s $'\t' -N "$PRETTY_NAME,Rocky Linux 8" < <(
|
|
|
|
for p in "${!pkg_map[@]}"; do
|
|
|
|
printf '%s\t%s\n' "${pkg_map[$p]}" "$p"
|
|
|
|
done
|
|
|
|
)
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg $'\n'"Getting list of installed system packages."$'\n'
|
2021-06-04 10:11:15 +00:00
|
|
|
|
2021-08-14 04:32:10 +00:00
|
|
|
readarray -t installed_packages < <(
|
|
|
|
saferpm -qa --queryformat="%{NAME}\n" "${pkg_map[@]}"
|
|
|
|
)
|
2021-05-11 22:55:56 +00:00
|
|
|
declare -g -A installed_pkg_check installed_pkg_map
|
|
|
|
for p in "${installed_packages[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
installed_pkg_check[$p]=1
|
2021-05-11 22:55:56 +00:00
|
|
|
done
|
|
|
|
for p in "${!pkg_map[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
if [[ ${pkg_map[$p]} && ${installed_pkg_check[${pkg_map[$p]}]} ]]; then
|
|
|
|
installed_pkg_map[$p]=${pkg_map[$p]}
|
|
|
|
fi
|
2021-05-11 22:55:56 +00:00
|
|
|
done;
|
|
|
|
|
2021-08-13 13:35:50 +00:00
|
|
|
# Special Handling for CentOS Stream Repos
|
|
|
|
installed_sys_stream_repos_pkgs=()
|
|
|
|
installed_stream_repos_pkgs=()
|
|
|
|
for p in "${!stream_repos_pkgs[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
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]=
|
2022-01-11 08:56:51 +00:00
|
|
|
installed_sys_stream_repos_pkgs+=( "${stream_repos_pkgs[$p]}" )
|
2021-08-14 04:32:10 +00:00
|
|
|
elif rpm --quiet -q "${stream_repos_pkgs[$p]}"; then
|
|
|
|
# Non-system package, repos just need to be disabled.
|
2022-01-11 08:56:51 +00:00
|
|
|
installed_stream_repos_pkgs+=( "${stream_repos_pkgs[$p]}" )
|
2021-08-14 04:32:10 +00:00
|
|
|
fi
|
2021-08-13 13:35:50 +00:00
|
|
|
done
|
|
|
|
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2140
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' '' \
|
|
|
|
"We will replace the following $PRETTY_NAME packages with their Rocky Linux 8 "\
|
|
|
|
"equivalents"
|
2021-06-04 10:11:15 +00:00
|
|
|
column -t -s $'\t' -N "Packages to be Removed,Packages to be Installed" < <(
|
2021-08-14 04:32:10 +00:00
|
|
|
for p in "${!installed_pkg_map[@]}"; do
|
|
|
|
printf '%s\t%s\n' "${installed_pkg_map[$p]}" "$p"
|
|
|
|
done
|
2021-05-11 22:55:56 +00:00
|
|
|
)
|
|
|
|
|
2021-08-13 13:35:50 +00:00
|
|
|
if (( ${#installed_sys_stream_repos_pkgs[@]} )); then
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2026
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' '' \
|
2021-08-13 13:35:50 +00:00
|
|
|
'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:' \
|
2021-08-14 04:32:10 +00:00
|
|
|
"${installed_sys_stream_repos_pkgs[@]}"
|
2021-08-13 13:35:50 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if (( ${#installed_stream_repos_pkgs[@]} )); then
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2026
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' '' \
|
2021-08-13 13:35:50 +00:00
|
|
|
'Also to aid the transition from CentOS Stream the repos included in the '\
|
|
|
|
'following packages will be renamed and retained but disabled:' \
|
2021-08-14 04:32:10 +00:00
|
|
|
"${installed_stream_repos_pkgs[@]}"
|
2021-08-13 13:35:50 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-13 14:26:20 +00:00
|
|
|
if (( ${#addl_pkg_removes[@]} )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' '' \
|
2021-08-13 13:35:50 +00:00
|
|
|
"In addition to the above the following system packages will be removed:" \
|
2021-08-14 04:32:10 +00:00
|
|
|
"${addl_pkg_removes[@]}"
|
2021-05-13 14:26:20 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
# 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
|
2021-08-14 04:32:10 +00:00
|
|
|
# left as a separate exercise to swap out the sig repos.
|
2021-05-11 22:55:56 +00:00
|
|
|
#sigs_to_swap=()
|
|
|
|
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg '%s' $'\n' \
|
2021-08-14 04:32:10 +00:00
|
|
|
$'Getting a list of enabled modules for the system repositories.\n'
|
2021-05-11 22:55:56 +00:00
|
|
|
|
|
|
|
# Get a list of system enabled modules.
|
|
|
|
readarray -t enabled_modules < <(
|
2021-08-14 04:32:10 +00:00
|
|
|
set -e -o pipefail
|
2022-02-01 10:54:27 +00:00
|
|
|
safednf -y -q "${repo_map[@]/#/--repo=}" "${dist_repourl_swaps[@]}" \
|
|
|
|
module list --enabled |
|
2021-08-14 04:32:10 +00:00
|
|
|
awk '
|
|
|
|
$1 == "@modulefailsafe", /^$/ {next}
|
|
|
|
$1 == "Name", /^$/ {if ($1!="Name" && !/^$/) print $1":"$2}
|
|
|
|
' | sort -u
|
|
|
|
set +e +o pipefail
|
2021-05-11 22:55:56 +00:00
|
|
|
)
|
2021-07-15 07:16:25 +00:00
|
|
|
|
|
|
|
# Map the known module name differences.
|
2021-07-15 21:50:14 +00:00
|
|
|
disable_modules=()
|
|
|
|
local i gl repl mod
|
2021-07-15 07:16:25 +00:00
|
|
|
for i in "${!enabled_modules[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
mod=${enabled_modules[$i]}
|
|
|
|
for gl in "${!module_glob_map[@]}"; do
|
|
|
|
repl=${module_glob_map[$gl]}
|
|
|
|
mod=${mod/$gl/$repl}
|
|
|
|
done
|
|
|
|
if [[ $mod != "${enabled_modules[$i]}" ]]; then
|
2022-01-11 08:56:51 +00:00
|
|
|
disable_modules+=("${enabled_modules[$i]}")
|
2021-08-14 04:32:10 +00:00
|
|
|
enabled_modules[$i]=$mod
|
|
|
|
fi
|
2021-07-15 07:16:25 +00:00
|
|
|
done
|
|
|
|
|
2021-05-18 11:43:58 +00:00
|
|
|
# Remove entries matching any excluded modules.
|
|
|
|
if (( ${#module_excludes[@]} )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' '' "Excluding modules:" "${module_excludes[@]}"
|
|
|
|
local -A module_check='()'
|
|
|
|
local -a tmparr='()'
|
|
|
|
for m in "${module_excludes[@]}"; do
|
|
|
|
module_check[$m]=1
|
|
|
|
done
|
|
|
|
for m in "${enabled_modules[@]}"; do
|
|
|
|
if [[ ! ${module_check[$m]} ]]; then
|
|
|
|
tmparr+=("$m")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
enabled_modules=("${tmparr[@]}")
|
2021-05-18 11:43:58 +00:00
|
|
|
fi
|
2021-05-11 22:55:56 +00:00
|
|
|
|
2021-05-14 03:18:43 +00:00
|
|
|
printf '%s\n' '' "Found the following modules to re-enable at completion:" \
|
2021-08-14 04:32:10 +00:00
|
|
|
"${enabled_modules[@]}" ''
|
2021-05-14 03:18:43 +00:00
|
|
|
|
|
|
|
if (( ${#managed_repos[@]} )); then
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2026
|
2021-08-14 04:32:10 +00:00
|
|
|
printf '%s\n' '' \
|
|
|
|
'In addition, since this system uses subscription-manager the following '\
|
|
|
|
'managed repos will be disabled:' \
|
|
|
|
"${managed_repos[@]}"
|
2021-05-14 03:18:43 +00:00
|
|
|
fi
|
2021-05-11 22:55:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
convert_info_dir=/root/convert
|
2021-08-09 11:35:39 +00:00
|
|
|
unset convert_to_rocky reinstall_all_rpms verify_all_rpms update_efi \
|
|
|
|
container_macros
|
2021-05-11 22:55:56 +00:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
printf '%s\n' \
|
|
|
|
"Usage: ${0##*/} [OPTIONS]" \
|
|
|
|
'' \
|
|
|
|
'Options:' \
|
2021-05-29 06:33:57 +00:00
|
|
|
'-h Display this help' \
|
|
|
|
'-r Convert to rocky' \
|
|
|
|
'-V Verify switch' \
|
2021-05-11 22:55:56 +00:00
|
|
|
' !! USE WITH CAUTION !!'
|
|
|
|
exit 1
|
|
|
|
} >&2
|
|
|
|
|
|
|
|
generate_rpm_info() {
|
2022-01-01 05:51:07 +00:00
|
|
|
mkdir -p "$convert_info_dir"
|
2021-08-14 04:32:10 +00:00
|
|
|
infomsg "Creating a list of RPMs installed: $1"$'\n'
|
2021-11-18 01:50:00 +00:00
|
|
|
# shellcheck disable=SC2140
|
2021-08-14 04:32:10 +00:00
|
|
|
rpm -qa --qf \
|
|
|
|
"%{NAME}|%{VERSION}|%{RELEASE}|%{INSTALLTIME}|%{VENDOR}|%{BUILDTIME}|"\
|
|
|
|
"%{BUILDHOST}|%{SOURCERPM}|%{LICENSE}|%{PACKAGER}\n" |
|
|
|
|
sort > "${convert_info_dir}/$HOSTNAME-rpm-list-$1.log"
|
|
|
|
infomsg "Verifying RPMs installed against RPM database: $1"$'\n\n'
|
|
|
|
rpm -Va | sort -k3 > \
|
|
|
|
"${convert_info_dir}/$HOSTNAME-rpm-list-verified-$1.log"
|
2021-05-11 22:55:56 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 09:21:33 +00:00
|
|
|
# Run a dnf update before the actual migration.
|
|
|
|
pre_update() {
|
|
|
|
infomsg '%s\n' "Running dnf update before we attempt the migration."
|
2022-02-01 10:54:27 +00:00
|
|
|
safednf -y "${dist_repourl_swaps[@]}" update || exit_message \
|
2021-06-29 09:21:33 +00:00
|
|
|
$'Error running pre-update. Stopping now to avoid putting the system in an\n'\
|
|
|
|
$'unstable state. Please correct the issues shown here and try again.'
|
|
|
|
}
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
package_swaps() {
|
2021-08-14 04:32:10 +00:00
|
|
|
# Save off any subscription-manager keys, just in case.
|
2021-06-20 17:10:24 +00:00
|
|
|
if ( shopt -s failglob dotglob; : "$sm_ca_dir"/* ) 2>/dev/null ; then
|
2021-08-14 04:32:10 +00:00
|
|
|
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"
|
2021-06-20 17:10:24 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-31 16:41:27 +00:00
|
|
|
# prepare repo parameters
|
|
|
|
local -a dnfparameters
|
|
|
|
for repo in "${!repo_urls[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
dnfparameters+=( "--repofrompath=${repo},${repo_urls[${repo}]}" )
|
|
|
|
dnfparameters+=( "--setopt=${repo}.gpgcheck=1" )
|
|
|
|
dnfparameters+=( "--setopt=${repo}.gpgkey=file://${gpg_key_file}" )
|
2021-05-31 16:41:27 +00:00
|
|
|
done
|
|
|
|
|
2021-08-13 13:35:50 +00:00
|
|
|
# CentOS Stream specific processing
|
2021-11-11 09:16:13 +00:00
|
|
|
if (( ${#installed_stream_repos_pkgs[@]} ||
|
|
|
|
${#installed_sys_stream_repos_pkgs[@]} )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
# 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$'
|
|
|
|
)
|
|
|
|
|
2021-11-23 11:21:41 +00:00
|
|
|
if (( ${#installed_sys_stream_repos_pkgs[@]} )); then
|
2021-11-11 09:16:13 +00:00
|
|
|
# Remove the package from the rpm db.
|
|
|
|
saferpm -e --justdb --nodeps -a \
|
|
|
|
"${installed_sys_stream_repos_pkgs[@]}" ||
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message \
|
2021-11-18 01:50:00 +00:00
|
|
|
"Could not remove packages from the rpm db: ${installed_sys_stream_repos_pkgs[*]}"
|
2021-11-23 11:21:41 +00:00
|
|
|
fi
|
2021-08-13 13:35:50 +00:00
|
|
|
|
2021-11-18 01:11:15 +00:00
|
|
|
# Rename the stream repos with a prefix and fix the baseurl.
|
2022-01-11 08:56:51 +00:00
|
|
|
# shellcheck disable=SC2016
|
2021-11-18 01:11:15 +00:00
|
|
|
sed -i \
|
|
|
|
-e 's/^\[/['"$stream_prefix"'/' \
|
2021-11-23 15:48:51 +00:00
|
|
|
-e 's|^mirrorlist=|#mirrorlist=|' \
|
2024-07-07 09:29:44 +00:00
|
|
|
-e 's|^#baseurl=http://mirror.centos.org/$contentdir/$stream/|baseurl=https://dl.rockylinux.org/vault/centos/8-stream/|' \
|
|
|
|
-e 's|^baseurl=http://vault.centos.org/$contentdir/$stream/|baseurl=https://dl.rockylinux.org/vault/centos/8-stream/|' \
|
2021-11-23 11:21:41 +00:00
|
|
|
"${repos_files[@]}"
|
2021-08-13 13:35:50 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
# Use dnf shell to swap the system packages out.
|
2021-06-04 10:11:15 +00:00
|
|
|
safednf -y shell --disablerepo=\* --noautoremove \
|
2022-02-01 10:54:27 +00:00
|
|
|
"${dist_repourl_swaps[@]}" \
|
2021-08-14 04:32:10 +00:00
|
|
|
--setopt=protected_packages= --setopt=keepcache=True \
|
|
|
|
"${dnfparameters[@]}" \
|
|
|
|
<<EOF
|
|
|
|
remove ${installed_pkg_map[@]} ${addl_pkg_removes[@]}
|
|
|
|
install ${!installed_pkg_map[@]}
|
|
|
|
run
|
|
|
|
exit
|
2021-05-11 22:55:56 +00:00
|
|
|
EOF
|
2021-05-13 14:26:20 +00:00
|
|
|
|
2021-08-14 04:32:10 +00:00
|
|
|
# rocky-repos and rocky-gpg-keys are now installed, so we don't need the
|
|
|
|
# key file anymore
|
2021-05-31 16:41:27 +00:00
|
|
|
rm -rf "$gpg_tmp_dir"
|
|
|
|
|
2021-05-13 14:26:20 +00:00
|
|
|
# We need to check to make sure that all of the original system packages
|
|
|
|
# have been removed and all of the new ones have been added. If a package
|
|
|
|
# was supposed to be removed and one with the same name added back then
|
|
|
|
# we're kind of screwed for this check, as we can't be certain, but all the
|
|
|
|
# packages we're adding start with "rocky-*" so this really shouldn't happen
|
|
|
|
# and we can safely not check for it. The worst that will happen is a rocky
|
|
|
|
# linux package will be removed and then installed again.
|
|
|
|
local -a check_removed check_installed
|
|
|
|
readarray -t check_removed < <(
|
2021-08-14 04:32:10 +00:00
|
|
|
saferpm -qa --qf '%{NAME}\n' "${installed_pkg_map[@]}" \
|
|
|
|
"${addl_pkg_removes[@]}" | sort -u
|
2021-05-13 14:26:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if (( ${#check_removed[@]} )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
infomsg '%s' $'\n' \
|
|
|
|
"Packages found on system that should still be removed. Forcibly" \
|
|
|
|
" removing them with rpm:"$'\n'
|
|
|
|
# Removed packages still found on the system. Forcibly remove them.
|
|
|
|
for pkg in "${check_removed[@]}"; do
|
|
|
|
# Extra safety measure, skip if empty string
|
|
|
|
if [[ -z $pkg ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
printf '%s\n' "$pkg"
|
|
|
|
saferpm -e --allmatches --nodeps "$pkg" ||
|
|
|
|
saferpm -e --allmatches --nodeps --noscripts --notriggers "$pkg"
|
|
|
|
done
|
2021-05-13 14:26:20 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check to make sure we installed everything we were supposed to.
|
|
|
|
readarray -t check_installed < <(
|
2021-08-14 04:32:10 +00:00
|
|
|
{
|
|
|
|
printf '%s\n' "${!installed_pkg_map[@]}" | sort -u
|
|
|
|
saferpm -qa --qf '%{NAME}\n' "${!installed_pkg_map[@]}" | sort -u
|
|
|
|
} | sort | uniq -u
|
2021-05-13 14:26:20 +00:00
|
|
|
)
|
|
|
|
if (( ${#check_installed[@]} )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
infomsg '%s' $'\n' \
|
|
|
|
"Some required packages were not installed by dnf. Attempting to" \
|
|
|
|
" force with rpm:"$'\n'
|
|
|
|
|
|
|
|
# Get a list of rpm packages to package names
|
|
|
|
local -A rpm_map
|
|
|
|
local -a file_list
|
|
|
|
for rpm in /var/cache/dnf/{rockybaseos,rockyappstream}-*/packages/*.rpm
|
|
|
|
do
|
|
|
|
rpm_map[$(
|
|
|
|
rpm -q --qf '%{NAME}\n' --nodigest "$rpm" 2>/dev/null
|
|
|
|
)]=$rpm
|
|
|
|
done
|
|
|
|
|
|
|
|
# Attempt to install.
|
|
|
|
for pkg in "${check_installed[@]}"; do
|
|
|
|
printf '%s\n' "$pkg"
|
|
|
|
if ! rpm -i --force --nodeps --nodigest "${rpm_map[$pkg]}" \
|
|
|
|
2>/dev/null; then
|
|
|
|
# Try to install the package in just the db, then clean it up.
|
|
|
|
rpm -i --force --justdb --nodeps --nodigest "${rpm_map[$pkg]}" \
|
|
|
|
2>/dev/null
|
|
|
|
|
|
|
|
# Get list of files that are still causing problems and donk
|
|
|
|
# them.
|
|
|
|
readarray -t file_list < <(
|
|
|
|
rpm -V "$pkg" 2>/dev/null | awk '$1!="missing" {print $2}'
|
|
|
|
)
|
|
|
|
for file in "${file_list[@]}"; do
|
|
|
|
rmdir "$file" ||
|
|
|
|
rm -f "$file" ||
|
|
|
|
rm -rf "$file"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Now try re-installing the package to replace the missing
|
|
|
|
# files. Regardless of the outcome here we just accept it and
|
|
|
|
# move on and hope for the best.
|
|
|
|
rpm -i --reinstall --force --nodeps --nodigest \
|
|
|
|
"${rpm_map[$pkg]}" 2>/dev/null
|
|
|
|
fi
|
|
|
|
done
|
2021-05-11 22:55:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Distrosync
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg $'Ensuring repos are enabled before the package swap\n'
|
2021-11-18 01:38:29 +00:00
|
|
|
safednf -y --enableplugin=config_manager config-manager \
|
2021-08-14 04:32:10 +00:00
|
|
|
--set-enabled "${!repo_map[@]}" || {
|
|
|
|
printf '%s\n' 'Repo name missing?'
|
|
|
|
exit 25
|
2021-05-11 22:55:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 03:18:43 +00:00
|
|
|
if (( ${#managed_repos[@]} )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
# Filter the managed repos for ones still in the system.
|
|
|
|
readarray -t managed_repos < <(
|
2021-08-15 08:39:26 +00:00
|
|
|
safednf -y -q repolist "${managed_repos[@]}" |
|
2021-08-14 04:32:10 +00:00
|
|
|
awk '$1!="repo" {print $1}'
|
|
|
|
)
|
|
|
|
|
|
|
|
if (( ${#managed_repos[@]} )); then
|
|
|
|
infomsg $'\nDisabling subscription managed repos\n'
|
2021-11-18 01:38:29 +00:00
|
|
|
safednf -y --enableplugin=config_manager config-manager \
|
2021-08-14 04:32:10 +00:00
|
|
|
--disable "${managed_repos[@]}"
|
|
|
|
fi
|
2021-05-14 03:18:43 +00:00
|
|
|
fi
|
|
|
|
|
2021-07-15 21:50:14 +00:00
|
|
|
if (( ${#disable_modules[@]} )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
infomsg $'Disabling modules\n\n'
|
|
|
|
safednf -y module disable "${disable_modules[@]}" ||
|
|
|
|
exit_message "Can't disable modules ${disable_modules[*]}"
|
2021-07-15 21:50:14 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-12 01:44:41 +00:00
|
|
|
if (( ${#enabled_modules[@]} )); then
|
2021-08-14 04:32:10 +00:00
|
|
|
infomsg $'Enabling modules\n\n'
|
|
|
|
safednf -y module enable "${enabled_modules[@]}" ||
|
|
|
|
exit_message "Can't enable modules ${enabled_modules[*]}"
|
2021-05-12 01:44:41 +00:00
|
|
|
fi
|
2021-05-18 11:43:58 +00:00
|
|
|
|
2021-08-13 13:35:50 +00:00
|
|
|
# Make sure that excluded modules are disabled.
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg $'Disabling excluded modules\n\n'
|
2021-06-04 10:11:15 +00:00
|
|
|
safednf -y module disable "${module_excludes[@]}" ||
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message "Can't disable modules ${module_excludes[*]}"
|
2021-05-18 11:43:58 +00:00
|
|
|
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg $'\nSyncing packages\n\n'
|
2021-05-11 22:55:56 +00:00
|
|
|
dnf -y distro-sync || exit_message "Error during distro-sync."
|
2021-06-20 17:10:24 +00:00
|
|
|
|
2021-08-13 13:35:50 +00:00
|
|
|
# Disable Stream repos.
|
|
|
|
if (( ${#installed_sys_stream_repos_pkgs[@]} ||
|
2021-08-14 04:32:10 +00:00
|
|
|
${#installed_stream_repos_pkgs[@]} )); then
|
|
|
|
dnf -y --enableplugin=config_manager config-manager --set-disabled \
|
|
|
|
"$stream_prefix*" ||
|
|
|
|
errmsg \
|
2021-08-13 13:35:50 +00:00
|
|
|
$'Failed to disable CentOS Stream repos, please check and disable manually.\n'
|
|
|
|
|
2021-11-23 11:21:41 +00:00
|
|
|
if (( ${#stream_always_replace[@]} )) &&
|
|
|
|
[[ $(saferpm -qa "${stream_always_replace[@]}") ]]; then
|
|
|
|
safednf -y distro-sync "${stream_always_replace[@]}" ||
|
|
|
|
exit_message "Error during distro-sync."
|
|
|
|
fi
|
|
|
|
|
2021-08-14 04:32:10 +00:00
|
|
|
infomsg $'\nCentOS Stream Migration Notes:\n\n'
|
|
|
|
cat <<EOF
|
2021-08-13 13:35:50 +00:00
|
|
|
Because CentOS Stream leads RockyLinux by the next point release many packages
|
|
|
|
in Stream will have higher version numbers than those in RockyLinux, some will
|
|
|
|
even be rebased to a new upstream version. Downgrading these packages to the
|
|
|
|
versions in RockyLinux carries the risk that the older version may not
|
|
|
|
recognize config files, data or other files generated by the newer version in
|
|
|
|
Stream.
|
|
|
|
|
|
|
|
To avoid issues with this the newer package versions from CentOS Stream have
|
|
|
|
been retained. Also the CentOS Stream repositories have been retained but
|
|
|
|
renamed with a prefix of "stream-" to avoid clashing with RockyLinux
|
|
|
|
repositories, but these same repos have also been disabled so that future
|
|
|
|
package installs will come from the stock RockyLinux repositories.
|
|
|
|
|
|
|
|
If you do nothing except update to the next point release of RockyLinux when it
|
|
|
|
becomes available then the packages retained from Stream should be replaced at
|
|
|
|
that time. If you need to update a package from Stream (eg: to fix a bug or
|
|
|
|
security issue) then you will need to enable the appropriate repository to do
|
|
|
|
so.
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2021-06-20 17:10:24 +00:00
|
|
|
if rpm --quiet -q subscription-manager; then
|
2021-08-14 04:32:10 +00:00
|
|
|
infomsg $'Subscription Manager found on system.\n\n'
|
|
|
|
cat <<EOF
|
2021-06-20 17:10:24 +00:00
|
|
|
If you're converting from a subscription-managed distribution such as RHEL then
|
2021-06-25 06:45:30 +00:00
|
|
|
you may no longer need subscription-manager or dnf-plugin-subscription-manager.
|
|
|
|
While it won't hurt anything to have it on your system you may be able to safely
|
|
|
|
remove it with:
|
|
|
|
|
|
|
|
"dnf remove subscription-manager dnf-plugin-subscription-manager".
|
|
|
|
|
|
|
|
Take care that it doesn't remove something that you want to keep.
|
2021-06-20 17:10:24 +00:00
|
|
|
|
|
|
|
The subscription-manager dnf plugin may be enabled for the benefit of
|
|
|
|
Subscription Management. If no longer desired, you can use
|
|
|
|
"subscription-manager config --rhsm.auto_enable_yum_plugins=0" to block this
|
|
|
|
behavior.
|
|
|
|
EOF
|
|
|
|
fi
|
2021-11-24 12:19:09 +00:00
|
|
|
|
|
|
|
if (( ${#always_install[@]} )); then
|
|
|
|
safednf -y install "${always_install[@]}" || exit_message \
|
|
|
|
"Error installing required packages: ${always_install[*]}"
|
|
|
|
fi
|
|
|
|
|
2021-06-20 17:10:24 +00:00
|
|
|
if [[ $tmp_sm_ca_dir ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
# Check to see if there's Subscription Manager certs which have been
|
|
|
|
# removed
|
|
|
|
local -a removed_certs
|
|
|
|
readarray -t removed_certs < <((
|
|
|
|
shopt -s nullglob dotglob
|
|
|
|
local -a certs
|
|
|
|
cd "$sm_ca_dir" && certs=(*)
|
|
|
|
cd "$tmp_sm_ca_dir" && certs+=(*)
|
|
|
|
IFS=$'\n'
|
|
|
|
printf '%s' "${certs[*]}"
|
|
|
|
) | sort | uniq -u)
|
|
|
|
|
|
|
|
if (( ${#removed_certs[@]} )); then
|
|
|
|
cp -n -dR --preserve=all "$tmp_sm_ca_dir"/* "$sm_ca_dir/" ||
|
|
|
|
exit_message "Could not copy certs back to $sm_ca_dir"
|
|
|
|
|
|
|
|
infomsg '%s' \
|
|
|
|
$'Some Subscription Manager certificates ' \
|
|
|
|
"were restored to $sm_ca_dir after"$'\n' \
|
|
|
|
$'migration so that the subscription-manager ' \
|
|
|
|
$'command will continue to work:\n\n'
|
|
|
|
printf '%s\n' "${removed_certs[@]}" ''
|
|
|
|
cat <<EOF
|
2021-06-20 17:10:24 +00:00
|
|
|
If you no longer need to use the subscription-manager command then you may
|
|
|
|
safely remove these files.
|
|
|
|
EOF
|
2021-08-14 04:32:10 +00:00
|
|
|
fi
|
2021-06-20 17:10:24 +00:00
|
|
|
fi
|
2021-05-11 22:55:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 12:15:59 +00:00
|
|
|
# Check if this system is running on EFI
|
|
|
|
# If yes, we'll need to run fix_efi() at the end of the conversion
|
|
|
|
efi_check () {
|
|
|
|
# Check if we have /sys mounted and it is looking sane
|
|
|
|
if ! [[ -d /sys/class/block ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message "/sys is not accessible."
|
2021-05-30 12:15:59 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-09 11:35:39 +00:00
|
|
|
# Now that we know /sys is reliable, use it to check if we are running on
|
|
|
|
# EFI or not
|
|
|
|
if systemd-detect-virt --quiet --container; then
|
2021-08-14 04:32:10 +00:00
|
|
|
declare -g container_macros
|
|
|
|
container_macros=$(mktemp /etc/rpm/macros.zXXXXXX)
|
|
|
|
printf '%s\n' '%_netsharedpath /sys:/proc' > "$container_macros"
|
2021-08-09 11:35:39 +00:00
|
|
|
elif [[ -d /sys/firmware/efi/ ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
declare -g update_efi
|
|
|
|
update_efi=true
|
2021-05-30 12:15:59 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-05-29 06:33:57 +00:00
|
|
|
# Called to update the EFI boot.
|
|
|
|
fix_efi () (
|
|
|
|
grub2-mkconfig -o /boot/efi/EFI/rocky/grub.cfg ||
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message "Error updating the grub config."
|
2021-07-08 02:04:18 +00:00
|
|
|
for i in "${!efi_disk[@]}"; do
|
2021-08-14 04:32:10 +00:00
|
|
|
efibootmgr -c -d "/dev/${efi_disk[$i]}" -p "${efi_partition[$i]}" \
|
2021-12-20 20:06:55 +00:00
|
|
|
-L "Rocky Linux" -l "/EFI/rocky/shim${cpu_arch_suffix_map[$ARCH]}.efi" ||
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message "Error updating uEFI firmware."
|
2021-07-08 02:04:18 +00:00
|
|
|
done
|
2021-05-29 06:33:57 +00:00
|
|
|
)
|
|
|
|
|
2021-05-31 16:41:27 +00:00
|
|
|
# Download and verify the Rocky Linux package signing key
|
|
|
|
establish_gpg_trust () {
|
2021-08-14 04:32:10 +00:00
|
|
|
# create temp dir and verify it is really created and empty, so we are sure
|
|
|
|
# deleting it afterwards won't cause any harm
|
2021-05-31 16:41:27 +00:00
|
|
|
declare -g gpg_tmp_dir
|
2021-06-20 17:10:24 +00:00
|
|
|
gpg_tmp_dir=$tmp_dir/gpg
|
|
|
|
if ! mkdir "$gpg_tmp_dir" || [[ ! -d "$gpg_tmp_dir" ]]; then
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message "Error creating temp dir"
|
2021-05-31 16:41:27 +00:00
|
|
|
fi
|
2021-08-14 04:32:10 +00:00
|
|
|
# failglob makes pathname expansion fail if empty, dotglob adds files
|
|
|
|
# starting with . to pathname expansion
|
2021-05-31 16:41:27 +00:00
|
|
|
if ( shopt -s failglob dotglob; : "$gpg_tmp_dir"/* ) 2>/dev/null ; then
|
2021-08-14 04:32:10 +00:00
|
|
|
exit_message "Temp dir not empty"
|
2021-05-31 16:41:27 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# extract the filename from the url, use the temp dir just created
|
|
|
|
declare -g gpg_key_file="$gpg_tmp_dir/${gpg_key_url##*/}"
|
|
|
|
|
2021-07-16 05:31:54 +00:00
|
|
|
if ! curl -L -o "$gpg_key_file" --silent --show-error "$gpg_key_url"; then
|
2021-08-14 04:32:10 +00:00
|
|
|
rm -rf "$gpg_tmp_dir"
|
|
|
|
exit_message "Error downloading the Rocky Linux signing key."
|
2021-05-31 16:41:27 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! sha512sum --quiet -c <<<"$gpg_key_sha512 $gpg_key_file"; then
|
2021-08-14 04:32:10 +00:00
|
|
|
rm -rf "$gpg_tmp_dir"
|
|
|
|
exit_message "Error validating the signing key."
|
2021-05-31 16:41:27 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
## End actual work
|
|
|
|
|
|
|
|
noopts=0
|
|
|
|
while getopts "hrVR" option; do
|
|
|
|
(( noopts++ ))
|
|
|
|
case "$option" in
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
r)
|
|
|
|
convert_to_rocky=true
|
|
|
|
;;
|
|
|
|
V)
|
|
|
|
verify_all_rpms=true
|
|
|
|
;;
|
|
|
|
*)
|
2021-06-20 12:01:02 +00:00
|
|
|
errmsg $'Invalid switch\n'
|
2021-05-11 22:55:56 +00:00
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
if (( ! noopts )); then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2021-06-20 17:10:24 +00:00
|
|
|
pre_setup
|
|
|
|
trap exit_clean EXIT
|
2021-06-04 23:55:09 +00:00
|
|
|
pre_check
|
2021-05-30 12:15:59 +00:00
|
|
|
efi_check
|
2021-05-11 22:55:56 +00:00
|
|
|
bin_check
|
|
|
|
|
|
|
|
if [[ $verify_all_rpms ]]; then
|
|
|
|
generate_rpm_info begin
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $convert_to_rocky ]]; then
|
|
|
|
collect_system_info
|
2021-05-31 16:41:27 +00:00
|
|
|
establish_gpg_trust
|
2021-06-29 09:21:33 +00:00
|
|
|
pre_update
|
2021-05-11 22:55:56 +00:00
|
|
|
package_swaps
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $verify_all_rpms && $convert_to_rocky ]]; then
|
|
|
|
generate_rpm_info finish
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg $'You may review the following files:\n'
|
2022-01-01 05:51:07 +00:00
|
|
|
printf '%s\n' "$convert_info_dir/$HOSTNAME-rpm-list-"*.log
|
2021-05-11 22:55:56 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-29 06:33:57 +00:00
|
|
|
if [[ $update_efi && $convert_to_rocky ]]; then
|
|
|
|
fix_efi
|
|
|
|
fi
|
|
|
|
|
2021-05-11 22:55:56 +00:00
|
|
|
printf '\n\n\n'
|
|
|
|
if [[ $convert_to_rocky ]]; then
|
2021-06-20 12:01:02 +00:00
|
|
|
infomsg $'\nDone, please reboot your system.\n'
|
2021-05-11 22:55:56 +00:00
|
|
|
fi
|
|
|
|
logmessage
|