Skip to content

Switch distro-specific module streams #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 16, 2020
63 changes: 58 additions & 5 deletions centos2ol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ unset CDPATH

yum_url=https://yum.oracle.com
[email protected]
github_url=https://github.com/oracle/centos2ol/
bad_packages=(centos-backgrounds centos-logos centos-release centos-release-cr desktop-backgrounds-basic \
libreport-centos libreport-plugin-mantisbt libreport-plugin-rhtsupport python3-syspurpose \
python-oauth sl-logos yum-rhn-plugin)
Expand Down Expand Up @@ -142,6 +143,45 @@ case "$os_version" in
;;
esac

if [[ "$os_version" =~ 8.* ]]; then
echo "Identifying dnf modules that are enabled"
# There are a few dnf modules that are named after the distribution
# for each steam named 'rhel' or 'rhel8' we need to make alterations to 'ol' or 'ol8'
# Before we start the switch, identify if there are any present we don't know how to handle
mapfile -t modules_enabled < <(dnf module list --enabled | grep rhel | awk '{print $1}')
if [[ "${modules_enabled[*]}" ]]; then
# Create an array of modules we don't know how to manage
unknown_modules=()
for module in "${modules_enabled[@]}"; do
case ${module} in
container-tools|go-toolset|jmc|llvm-toolset|rust-toolset|virt)
;;
*)
# Add this module name to our array of modules we don't know how to manage
unknown_modules+=("${module}")
;;
esac
done
# If we have any modules we don't know how to manage, ask the user how to proceed
if [ ${#unknown_modules[@]} -gt 0 ]; then
echo "This tool is unable to automatically switch module(s) '${unknown_modules[*]}' from a CentOS 'rhel' stream to
an Oracle Linux equivalent. Do you want to continue and resolve it manually?
You may want select No to stop and raise an issue on ${github_url} for advice."
select yn in "Yes" "No"; do
case $yn in
Yes )
break
;;
No )
echo "Unsure how to switch module(s) '${unknown_modules[*]}'. Exiting as requested"
exit 1
;;
esac
done
fi
fi
fi

echo "Finding your repository directory..."
case "$os_version" in
8*)
Expand Down Expand Up @@ -303,11 +343,24 @@ case "$os_version" in
fi
;;
8*)
# Workaround for qemu-guest-agent packages installed from virt modules
if rpm -q qemu-guest-agent; then
dnf module reset -y virt
dnf module enable -y virt
dnf install -y --allowerasing qemu-guest-agent
# There are a few dnf modules that are named after the distribution
# for each steam named 'rhel' or 'rhel8' perform a module reset and install
if [[ "${modules_enabled[*]}" ]]; then
for module in "${modules_enabled[@]}"; do
dnf module reset -y "${module}"
case ${module} in
container-tools|go-toolset|jmc|llvm-toolset|rust-toolset)
dnf module install -y "${module}":ol8
;;
virt)
dnf module install -y "${module}":ol
;;
*)
echo "Unsure how to transform module ${module}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either break here or get user confirmation to continue, instead of just logging the exception.

I would then rewrite this as "Cannot switch enabled module \"${module}\" to Oracle Linux. Continue switching (y/N): with "no" as the default option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point in the code the core OS has been switched and we're tidying up the edge cases. We can't easily revert the changes already made so I don't think halting would help. I appreciate it's something that should be strongly highlighted to the user to replace a line that may scroll by.

What do you think of a summary at the end indicating that a module $x couldn't be automatically switched and requires manual intervention?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move this test to before we do anything that changes the system so that users have the option to abort the switch before any damage is done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll leave this modify code at the end but I'll add a check at the start to see if there are rhel* streams enabled that we aren't familiar with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thant seems like a perfectly cromulent solution.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented change. I temporarily disabled knowledge of the virt:rhel stream and this is the output:

$ sudo bash up.sh 
Checking for required packages...
Checking your distribution...
Checking for yum lock...
Checking for required python packages...
Identifying dnf modules that are enabled
This tool is unable to automatically switch module 'virt' from a CentOS 'rhel' stream to
an Oracle Linux equivalent. Do you want to continue and resolve it manually?
You may want select No to stop and raise an issue on https://github.com/oracle/centos2ol/ or contact <[email protected]> for advice.
1) Yes
2) No
#? 2
Unsure how to switch module 'virt'. Exiting as requested
For assistance, please email <[email protected]>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are multiple unknown modules? This format seems very single-module specific.

Also, only provide the GitHub URL, not the email address.

;;
esac
done
dnf --assumeyes --disablerepo "*" --enablerepo "ol8_appstream" update
fi

# Two logo RPMs aren't currently covered by 'replaces' metadata, replace by hand.
Expand Down