Skip to content

Commit 0e3f132

Browse files
authored
Switch distro-specific module streams (#15)
Test for any modules that cannot be replaced by Oracle Linux equivalents before starting the switch to allow the user to stop and get advice before continuing. Signed-off-by: Mark Cram <[email protected]> Reviewed-by: Avi Miller <[email protected]>
1 parent 79c0732 commit 0e3f132

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

centos2ol.sh

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ unset CDPATH
1111

1212
yum_url=https://yum.oracle.com
1313
14+
github_url=https://github.com/oracle/centos2ol/
1415
bad_packages=(centos-backgrounds centos-logos centos-release centos-release-cr desktop-backgrounds-basic \
1516
centos-release-advanced-virtualization centos-release-ansible26 centos-release-ansible-27 \
1617
centos-release-ansible-28 centos-release-ansible-29 centos-release-azure \
@@ -158,6 +159,45 @@ case "$os_version" in
158159
;;
159160
esac
160161

162+
if [[ "$os_version" =~ 8.* ]]; then
163+
echo "Identifying dnf modules that are enabled"
164+
# There are a few dnf modules that are named after the distribution
165+
# for each steam named 'rhel' or 'rhel8' we need to make alterations to 'ol' or 'ol8'
166+
# Before we start the switch, identify if there are any present we don't know how to handle
167+
mapfile -t modules_enabled < <(dnf module list --enabled | grep rhel | awk '{print $1}')
168+
if [[ "${modules_enabled[*]}" ]]; then
169+
# Create an array of modules we don't know how to manage
170+
unknown_modules=()
171+
for module in "${modules_enabled[@]}"; do
172+
case ${module} in
173+
container-tools|go-toolset|jmc|llvm-toolset|rust-toolset|virt)
174+
;;
175+
*)
176+
# Add this module name to our array of modules we don't know how to manage
177+
unknown_modules+=("${module}")
178+
;;
179+
esac
180+
done
181+
# If we have any modules we don't know how to manage, ask the user how to proceed
182+
if [ ${#unknown_modules[@]} -gt 0 ]; then
183+
echo "This tool is unable to automatically switch module(s) '${unknown_modules[*]}' from a CentOS 'rhel' stream to
184+
an Oracle Linux equivalent. Do you want to continue and resolve it manually?
185+
You may want select No to stop and raise an issue on ${github_url} for advice."
186+
select yn in "Yes" "No"; do
187+
case $yn in
188+
Yes )
189+
break
190+
;;
191+
No )
192+
echo "Unsure how to switch module(s) '${unknown_modules[*]}'. Exiting as requested"
193+
exit 1
194+
;;
195+
esac
196+
done
197+
fi
198+
fi
199+
fi
200+
161201
echo "Finding your repository directory..."
162202
case "$os_version" in
163203
8*)
@@ -416,11 +456,24 @@ case "$os_version" in
416456
fi
417457
;;
418458
8*)
419-
# Workaround for qemu-guest-agent packages installed from virt modules
420-
if rpm -q qemu-guest-agent; then
421-
dnf module reset -y virt
422-
dnf module enable -y virt
423-
dnf install -y --allowerasing qemu-guest-agent
459+
# There are a few dnf modules that are named after the distribution
460+
# for each steam named 'rhel' or 'rhel8' perform a module reset and install
461+
if [[ "${modules_enabled[*]}" ]]; then
462+
for module in "${modules_enabled[@]}"; do
463+
dnf module reset -y "${module}"
464+
case ${module} in
465+
container-tools|go-toolset|jmc|llvm-toolset|rust-toolset)
466+
dnf module install -y "${module}":ol8
467+
;;
468+
virt)
469+
dnf module install -y "${module}":ol
470+
;;
471+
*)
472+
echo "Unsure how to transform module ${module}"
473+
;;
474+
esac
475+
done
476+
dnf --assumeyes --disablerepo "*" --enablerepo "ol8_appstream" update
424477
fi
425478

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

0 commit comments

Comments
 (0)