Merge pull request #14 from pajamian/main

Various improvements
This commit is contained in:
Louis Abel 2021-05-07 17:14:25 -07:00 committed by GitHub
commit 4c2a01eb86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,8 +4,12 @@
## Rocky is RC status. Using this script means you accept all risks of system instability. ## Rocky is RC status. Using this script means you accept all risks of system instability.
( # Path to logfile
# Pass everything to a subshell so the output can be piped to /var/log/centos2rocky.log logfile=/var/log/centos2rocky.log
# Send all output to the logfile as well as stdout.
truncate -s0 "$logfile"
exec > >(tee -a "$logfile") 2> >(tee -a "$logfile" >&2)
errcolor=$(tput setaf 1) errcolor=$(tput setaf 1)
nocolor=$(tput op) nocolor=$(tput op)
@ -15,17 +19,12 @@ set -e
unset CDPATH unset CDPATH
if [[ "$(id -u)" -ne 0 ]]; then if [[ "$(id -u)" -ne 0 ]]; then
echo -e "$errcolor""\nYou must run this script as root.$nocolor" printf '%s\n' "$errcolor" "You must run this script as root.$nocolor" \
echo -e "$errcolor""Either use sudo or 'su -c ${0}'""$nocolor\n" "${errcolor}Either use sudo or 'su -c ${0}'$nocolor"
fi fi
if [[ "$(wget 2>/dev/null || echo $?)" == 127 ]]; then if ! type curl >/dev/null 2>&1; then
echo -e "$blue""Wget is not installed! Installing it...""$nocolor" printf '%s\n' "${blue}Curl is not installed! Installing it...$nocolor"
dnf -y install wget
fi
if [[ "$(curl 2>/dev/null || echo $?)" == 127 ]]; then
echo -e "$blue""Curl is not installed! Installing it...""$nocolor"
dnf -y install curl libcurl dnf -y install curl libcurl
fi fi
@ -58,30 +57,31 @@ reinstall_all_rpms=false
verify_all_rpms=false verify_all_rpms=false
usage() { usage() {
echo "Usage: ${0##*/} [OPTIONS]" printf '%s\n' \
echo "Usage: ${0##*/} [OPTIONS]" \
echo "Options:" '' \
echo "-h displays this help" 'Options:' \
echo "-r Converts to rocky" '-h displays this help' \
echo "-V Verifies switch" '-r Converts to rocky' \
echo "-R Reinstall all packages" '-V Verifies switch' \
echo " !! USE WITH CAUTION !!" '-R Reinstall all packages' \
' !! USE WITH CAUTION !!'
exit 1 exit 1
} >&2 } >&2
exit_message() { exit_message() {
echo "$1" printf '%s\n' "$1"
final_message final_message
exit 1 exit 1
} >&2 } >&2
final_message() { final_message() {
echo -e "$errcolor""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.""$nocolor" printf '%s\n' "${errcolor}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.$nocolor"
logmessage logmessage
} }
logmessage(){ logmessage(){
echo -e "$blue""A log of this installation can be found at /var/log/centos2rocky.log""$nocolor" printf '%s\n' "${blue}A log of this installation can be found at $logfile$nocolor"
} }
## The actual work ## The actual work
@ -98,9 +98,9 @@ bin_check() {
generate_rpm_info() { generate_rpm_info() {
mkdir /root/convert mkdir /root/convert
echo -e "$blue""Creating a list of RPMs installed: $1""$nocolor" printf '%s\n' "${blue}Creating a list of RPMs installed: $1$nocolor"
rpm -qa --qf "%{NAME}|%{VERSION}|%{RELEASE}|%{INSTALLTIME}|%{VENDOR}|%{BUILDTIME}|%{BUILDHOST}|%{SOURCERPM}|%{LICENSE}|%{PACKAGER}\n" | sort > "${convert_info_dir}/$(hostname)-rpm-list-$1.log" rpm -qa --qf "%{NAME}|%{VERSION}|%{RELEASE}|%{INSTALLTIME}|%{VENDOR}|%{BUILDTIME}|%{BUILDHOST}|%{SOURCERPM}|%{LICENSE}|%{PACKAGER}\n" | sort > "${convert_info_dir}/$(hostname)-rpm-list-$1.log"
echo -e "$blue""Verifying RPMs installed against RPM database: $1""$nocolor\n" printf '%s\n' "${blue}Verifying RPMs installed against RPM database: $1$nocolor" ''
rpm -Va | sort -k3 > "${convert_info_dir}/$(hostname)-rpm-list-verified-$1.log" rpm -Va | sort -k3 > "${convert_info_dir}/$(hostname)-rpm-list-verified-$1.log"
} }
@ -109,7 +109,11 @@ package_swaps() {
pushd /root/release pushd /root/release
for x in "${release_to_install[@]}"; do for x in "${release_to_install[@]}"; do
wget -q "${current_url}/${x}" || { echo -e "$errcolor""failed to download ${x}""$nocolor\n" && logmessage ; exit 20; } curl -s "${current_url}/${x}" > "$x" || {
printf '%s\n' "${errcolor}failed to download ${x}$nocolor" '' &&
logmessage
exit 20
}
done done
# Remove packages we need to swap # Remove packages we need to swap
@ -120,10 +124,13 @@ package_swaps() {
# Distrosync if the above succeeded # Distrosync if the above succeeded
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo -e "$blue""Removing dnf cache""$nocolor" printf '%s\n' "${blue}Removing dnf cache$nocolor"
rm -rf /var/cache/{yum,dnf} rm -rf /var/cache/{yum,dnf}
echo -e "$blue""Ensuring repos are enabled before the package swap""$nocolor" printf '%s\n' "${blue}Ensuring repos are enabled before the package swap$nocolor"
dnf config-manager --set-enabled ${list_enabled[@]} || { echo "Repo name missing?" ; exit 25; } dnf config-manager --set-enabled ${list_enabled[@]} || {
printf '%s\n' 'Repo name missing?'
exit 25
}
dnf distro-sync -y dnf distro-sync -y
else else
exit_message "We failed to install the release package." exit_message "We failed to install the release package."
@ -146,7 +153,7 @@ grub_swap() {
} }
module_check() { module_check() {
echo -e "$blue""Finding our modules that are enabled""$nocolor" printf '%s\n' "${blue}Finding our modules that are enabled$nocolor"
for module in "${enabled_modules[@]}"; do for module in "${enabled_modules[@]}"; do
case ${module} in case ${module} in
container-tools|go-toolset|jmc|llvm-toolset|rust-toolset|virt) container-tools|go-toolset|jmc|llvm-toolset|rust-toolset|virt)
@ -157,14 +164,12 @@ module_check() {
esac esac
done done
if [[ ${#unknown_modules[@]} -gt 0 ]]; then if [[ ${#unknown_modules[@]} -gt 0 ]]; then
for x in "${unknown_modules[@]}"; do printf '%s\n' "${unknown_modules[@]}" \
echo "${x}" "${blue}There are some modules that are unsure of how to handle. This normally shouldn't happen. Do you want to resolve this yourself (Yes) or continue (No)?$nocolor"
done
echo -e "$blue""There are some modules that are unsure of how to handle. This normally shouldn't happen. Do you want to resolve this yourself (Yes) or continue (No)?""$nocolor"
select yn in "Yes" "No"; do select yn in "Yes" "No"; do
case $yn in case $yn in
Yes) Yes)
echo -e "$errcolor""Unsure how to switch modules, so we are leaving.""$nocolor" printf '%s\n' "${errcolor}Unsure how to switch modules, so we are leaving.$nocolor"
logmessage logmessage
exit 1 exit 1
;; ;;
@ -185,7 +190,7 @@ module_fix() {
dnf module install "${module}" -y dnf module install "${module}" -y
;; ;;
*) *)
echo -e "$errcolor""Unsure how to deal with the module presented.""$nocolor" printf '%s\n' "${errcolor}Unsure how to deal with the module presented.$nocolor"
logmessage logmessage
;; ;;
esac esac
@ -212,18 +217,18 @@ while getopts "hrVR" option; do
reinstall_all_rpms=true reinstall_all_rpms=true
;; ;;
*) *)
echo -e "$errcolor""Invalid switch.""$nocolor" printf '%s\n' "${errcolor}Invalid switch.$nocolor"
usage usage
;; ;;
esac esac
done done
echo -e "$blue""Ensuring rpm, yum, and wget are here.""$nocolor" printf '%s\n' "${blue}Ensuring rpm and yum are here.$nocolor"
for pkg in rpm yum wget curl; do for pkg in rpm yum curl; do
bin_check "${pkg}" bin_check "${pkg}"
done done
echo -e "$blue""Ensuring your version of CentOS is supported""$nocolor" printf '%s\n' "${blue}Ensuring your version of CentOS is supported$nocolor"
if ! old_release=$(rpm -q --whatprovides /etc/redhat-release); then if ! old_release=$(rpm -q --whatprovides /etc/redhat-release); then
exit_message "You are not running a supported distribution." exit_message "You are not running a supported distribution."
logmessage logmessage
@ -268,30 +273,27 @@ module_fix
# Warning, this is potentially dangerous. # Warning, this is potentially dangerous.
if "${reinstall_all_rpms}"; then if "${reinstall_all_rpms}"; then
echo -e "$errcolor""!! THIS MAY CAUSE ISSUES WITH YOUR SYSTEM !!""$nocolor" printf '%s\n' "${errcolor}!! THIS MAY CAUSE ISSUES WITH YOUR SYSTEM !!$nocolor"
rpm_list=("$(rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE} %{VENDOR}\n" | grep CentOS | awk '{print $1}')") rpm_list=("$(rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE} %{VENDOR}\n" | grep CentOS | awk '{print $1}')")
if [[ -n "${rpm_list[*]}" ]]; then if [[ -n "${rpm_list[*]}" ]]; then
echo "Reinstalling rpms: ${rpm_list[*]}" printf '%s ' 'Reinstalling rpms:' "${rpm_list[@]}"
dnf reinstall "${rpm_list[@]}" -y dnf reinstall "${rpm_list[@]}" -y
fi fi
non_rocky_rpm=("$(rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}|%{VENDOR}|%{PACKAGER}\n" |grep -iv Rocky)") non_rocky_rpm=("$(rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}|%{VENDOR}|%{PACKAGER}\n" |grep -iv Rocky)")
if [[ -n ${non_rocky_rpm[*]} ]]; then if [[ -n ${non_rocky_rpm[*]} ]]; then
echo -e "$blue""Non-Rocky packages are installed. This is generally not an issue. If you see centos packages, you may need to address them and file a bug report at https://bugs.rockylinux.org""$nocolor" printf '%s\n' "${blue}Non-Rocky packages are installed. This is generally not an issue. If you see centos packages, you may need to address them and file a bug report at https://bugs.rockylinux.org$nocolor"
printf '\t%s\n' "${non_rocky_rpm[@]}" printf '\t%s\n' "${non_rocky_rpm[@]}"
fi fi
fi fi
if "${verify_all_rpms}"; then if "${verify_all_rpms}"; then
generate_rpm_info finish generate_rpm_info finish
echo -e "$blue""You may review the following files:""$nocolor" printf '%s\n' "${blue}You may review the following files:$nocolor"
find /root/convert -type f -name "$(hostname)-rpms-*.log" find /root/convert -type f -name "$(hostname)-rpms-*.log"
fi fi
echo -e "\n \n" printf '\n\n\n'
cat /etc/issue | awk 'NR<=15' cat /etc/issue | awk 'NR<=15'
echo -e "$blue\n""Done, please reboot your system.""$nocolor" printf '%s\n' "$blue" "Done, please reboot your system.$nocolor"
logmessage logmessage
) | tee /var/log/centos2rocky.log
# Pipe output to /var/log/centos2rocky.log