mirror of
https://github.com/rocky-linux/rocky-tools.git
synced 2024-11-25 06:31:24 +00:00
Merge pull request #18 from pajamian/main
Various fixes based on feedback
This commit is contained in:
commit
69de45d490
@ -9,16 +9,17 @@
|
|||||||
## instability.
|
## instability.
|
||||||
|
|
||||||
# Path to logfile
|
# Path to logfile
|
||||||
logfile=/var/log/centos2rocky.log
|
logfile=/var/log/migrate2rocky.log
|
||||||
|
|
||||||
# Send all output to the logfile as well as stdout.
|
# Send all output to the logfile as well as stdout.
|
||||||
truncate -s0 "$logfile"
|
truncate -s0 "$logfile"
|
||||||
exec > >(tee -a "$logfile") 2> >(tee -a "$logfile" >&2)
|
exec > >(tee -a "$logfile") 2> >(tee -a "$logfile" >&2)
|
||||||
|
|
||||||
# List nocolor last here so that -x doesn't bork the display.
|
# List nocolor last here so that -x doesn't bork the display.
|
||||||
errcolor=$(tput setaf 1)
|
#errcolor=$(tput setaf 1)
|
||||||
blue=$(tput setaf 4)
|
#blue=$(tput setaf 4)
|
||||||
nocolor=$(tput op)
|
#nocolor=$(tput op)
|
||||||
|
unset errcolor blue nocolor
|
||||||
|
|
||||||
export LANG=en_US.UTF-8
|
export LANG=en_US.UTF-8
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
@ -57,6 +58,19 @@ os-release () (
|
|||||||
printf '%s\n' "${!1}"
|
printf '%s\n' "${!1}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 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
|
||||||
|
if [[ $(sort -V <<<"$ver"$'\n'"$2" | head -1) != $2 ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
)
|
||||||
|
|
||||||
# All of the binaries used by this script are available in a EL8 minimal install
|
# 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
|
# and are in /bin, so we should not encounter a system where the script doesn't
|
||||||
# work unless it's severly broken. This is just a simple check that will cause
|
# work unless it's severly broken. This is just a simple check that will cause
|
||||||
@ -78,13 +92,24 @@ bin_check() {
|
|||||||
exit_message "bash >= 4.0 is required for this script."
|
exit_message "bash >= 4.0 is required for this script."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -a missing
|
local -a missing bins
|
||||||
for bin in rpm dnf awk column tee tput mkdir cat arch sort uniq rmdir rm; do
|
bins=(
|
||||||
|
rpm dnf awk column tee tput mkdir
|
||||||
|
cat arch sort uniq rmdir rm head
|
||||||
|
)
|
||||||
|
if [[ $update_efi ]]; then
|
||||||
|
bins+=(findmnt grub2-mkconfig efibootmgr)
|
||||||
|
fi
|
||||||
|
for bin in "${bins[@]}"; do
|
||||||
if ! type "$bin" >/dev/null 2>&1; then
|
if ! type "$bin" >/dev/null 2>&1; then
|
||||||
missing+=("$bin")
|
missing+=("$bin")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if ! pkg_ver dnf 4.2; then
|
||||||
|
exit_message 'dnf >= 4.2 is required for this script. Please run "dnf update" first.'
|
||||||
|
fi
|
||||||
|
|
||||||
if (( ${#missing[@]} )); then
|
if (( ${#missing[@]} )); then
|
||||||
exit_message "Commands not found: ${missing[@]}. Possible bad PATH setting or corrupt installation."
|
exit_message "Commands not found: ${missing[@]}. Possible bad PATH setting or corrupt installation."
|
||||||
fi
|
fi
|
||||||
@ -175,6 +200,15 @@ provides_pkg () (
|
|||||||
)
|
)
|
||||||
|
|
||||||
collect_system_info () {
|
collect_system_info () {
|
||||||
|
# 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
|
||||||
|
declare -g efi_mount
|
||||||
|
efi_mount=$(findmnt --mountpoint /boot/efi --output SOURCE \
|
||||||
|
--noheadings) ||
|
||||||
|
exit_message "Can't find EFI mount. No EFI boot detected."
|
||||||
|
fi
|
||||||
|
|
||||||
# Don't enable these module streams, even if they are enabled in the source
|
# Don't enable these module streams, even if they are enabled in the source
|
||||||
# distro.
|
# distro.
|
||||||
declare -g -a module_excludes
|
declare -g -a module_excludes
|
||||||
@ -341,16 +375,17 @@ collect_system_info () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convert_info_dir=/root/convert
|
convert_info_dir=/root/convert
|
||||||
unset convert_to_rocky reinstall_all_rpms verify_all_rpms
|
unset convert_to_rocky reinstall_all_rpms verify_all_rpms update_efi
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
"Usage: ${0##*/} [OPTIONS]" \
|
"Usage: ${0##*/} [OPTIONS]" \
|
||||||
'' \
|
'' \
|
||||||
'Options:' \
|
'Options:' \
|
||||||
'-h displays this help' \
|
'-e Update EFI boot sector when done' \
|
||||||
'-r Converts to rocky' \
|
'-h Display this help' \
|
||||||
'-V Verifies switch' \
|
'-r Convert to rocky' \
|
||||||
|
'-V Verify switch' \
|
||||||
' !! USE WITH CAUTION !!'
|
' !! USE WITH CAUTION !!'
|
||||||
exit 1
|
exit 1
|
||||||
} >&2
|
} >&2
|
||||||
@ -482,6 +517,14 @@ EOF
|
|||||||
dnf -y distro-sync || exit_message "Error during distro-sync."
|
dnf -y distro-sync || exit_message "Error during distro-sync."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Called to update the EFI boot.
|
||||||
|
fix_efi () (
|
||||||
|
grub2-mkconfig -o /boot/efi/EFI/rocky/grub.cfg ||
|
||||||
|
exit_message "Error updating the grub config."
|
||||||
|
efibootmgr -c -d "$efi_mount" -L "Rocky Linux" -I /EFI/rocky/grubx64.efi ||
|
||||||
|
exit_message "Error updating uEFI firmware."
|
||||||
|
)
|
||||||
|
|
||||||
## End actual work
|
## End actual work
|
||||||
|
|
||||||
noopts=0
|
noopts=0
|
||||||
@ -497,6 +540,9 @@ while getopts "hrVR" option; do
|
|||||||
V)
|
V)
|
||||||
verify_all_rpms=true
|
verify_all_rpms=true
|
||||||
;;
|
;;
|
||||||
|
e)
|
||||||
|
update_efi=true
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
printf '%s\n' "${errcolor}Invalid switch.$nocolor"
|
printf '%s\n' "${errcolor}Invalid switch.$nocolor"
|
||||||
usage
|
usage
|
||||||
@ -524,6 +570,10 @@ if [[ $verify_all_rpms && $convert_to_rocky ]]; then
|
|||||||
find /root/convert -type f -name "$HOSTNAME-rpms-*.log"
|
find /root/convert -type f -name "$HOSTNAME-rpms-*.log"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $update_efi && $convert_to_rocky ]]; then
|
||||||
|
fix_efi
|
||||||
|
fi
|
||||||
|
|
||||||
printf '\n\n\n'
|
printf '\n\n\n'
|
||||||
if [[ $convert_to_rocky ]]; then
|
if [[ $convert_to_rocky ]]; then
|
||||||
cat /etc/issue | awk 'NR<=15'
|
cat /etc/issue | awk 'NR<=15'
|
||||||
|
Loading…
Reference in New Issue
Block a user