Skip to content

Commit 79c0732

Browse files
authored
Automatically enable additional repositories to match CentOS equivalent (#13)
Replace CentOS Repos with equivalent Oracle repos (if possible) or alert the user. User can chose whether to continue or not. Signed-off-by: Mark Cram <[email protected]> Reviewed-by: Avi Miller <[email protected]>
1 parent d4313e7 commit 79c0732

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

centos2ol.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ unset CDPATH
1212
yum_url=https://yum.oracle.com
1313
1414
bad_packages=(centos-backgrounds centos-logos centos-release centos-release-cr desktop-backgrounds-basic \
15+
centos-release-advanced-virtualization centos-release-ansible26 centos-release-ansible-27 \
16+
centos-release-ansible-28 centos-release-ansible-29 centos-release-azure \
17+
centos-release-ceph-jewel centos-release-ceph-luminous centos-release-ceph-nautilus \
18+
centos-release-ceph-octopus centos-release-configmanagement centos-release-dotnet centos-release-fdio \
19+
centos-release-gluster40 centos-release-gluster41 centos-release-gluster5 \
20+
centos-release-gluster6 centos-release-gluster7 centos-release-gluster8 \
21+
centos-release-gluster-legacy centos-release-messaging centos-release-nfs-ganesha28 \
22+
centos-release-nfs-ganesha30 centos-release-nfv-common \
23+
centos-release-nfv-openvswitch centos-release-openshift-origin centos-release-openstack-queens \
24+
centos-release-openstack-rocky centos-release-openstack-stein centos-release-openstack-train \
25+
centos-release-openstack-ussuri centos-release-opstools centos-release-ovirt42 centos-release-ovirt43 \
26+
centos-release-ovirt44 centos-release-paas-common centos-release-qemu-ev centos-release-qpid-proton \
27+
centos-release-rabbitmq-38 centos-release-samba411 centos-release-samba412 \
28+
centos-release-scl centos-release-scl-rh centos-release-storage-common \
29+
centos-release-virt-common centos-release-xen centos-release-xen-410 \
30+
centos-release-xen-412 centos-release-xen-46 centos-release-xen-48 centos-release-xen-common \
1531
libreport-centos libreport-plugin-mantisbt libreport-plugin-rhtsupport python3-syspurpose \
1632
python-oauth sl-logos yum-rhn-plugin)
1733

@@ -167,6 +183,31 @@ for dir in yum.YumBase().doConfigSetup(init_plugins=False).reposdir:
167183
;;
168184
esac
169185

186+
echo "Learning which repositories are enabled..."
187+
case "$os_version" in
188+
8*)
189+
enabled_repos=$(/usr/libexec/platform-python -c "
190+
import dnf
191+
192+
base = dnf.Base()
193+
base.read_all_repos()
194+
for repo in base.repos.iter_enabled():
195+
print(repo.id)
196+
")
197+
;;
198+
*)
199+
enabled_repos=$(python2 -c "
200+
import yum
201+
202+
base = yum.YumBase()
203+
base.doConfigSetup(init_plugins=False)
204+
for repo in base.repos.listEnabled():
205+
print repo
206+
")
207+
;;
208+
esac
209+
echo -e "Repositories enabled before update include:\n${enabled_repos}"
210+
170211
if [ -z "${reposdir}" ]; then
171212
exit_message "Could not locate your repository directory."
172213
fi
@@ -237,7 +278,12 @@ if [[ $old_release =~ ^centos-release-8.* ]] || [[ $old_release =~ ^centos-linux
237278
fi
238279

239280
echo "Backing up and removing old repository files..."
281+
# Identify repo files from the base OS
240282
rpm -ql "$old_release" | grep '\.repo$' > repo_files
283+
# Identify repo files from 'CentOS extras'
284+
if [ "$(rpm -qa "centos-release-*" | wc -l)" -gt 0 ] ; then
285+
rpm -qla "centos-release-*" | grep '\.repo$' >> repo_files
286+
fi
241287
while read -r repo; do
242288
if [ -f "$repo" ]; then
243289
cat - "$repo" > "$repo".disabled <<EOF
@@ -272,6 +318,73 @@ rm -f "${reposdir}/switch-to-oraclelinux.repo"
272318
# At this point, the switch is completed.
273319
trap - ERR
274320

321+
# When an additional enabled CentOS repository has a match with Oracle Linux
322+
# then automatically enable the OL repository to ensure the RPM is maintained
323+
#
324+
# Create an associate array where the key is the CentOS reponame and the value
325+
# contains the method of getting the content (Enable a repo or install an RPM)
326+
# and the details of the repo or RPM
327+
case "$os_version" in
328+
6*)
329+
declare -A repositories=(
330+
[base-debuginfo]="REPO https://oss.oracle.com/ol6/debuginfo/"
331+
[updates]="REPO ol6_latest"
332+
)
333+
;;
334+
7*)
335+
declare -A repositories=(
336+
[base-debuginfo]="REPO https://oss.oracle.com/ol7/debuginfo/"
337+
[updates]="REPO ol7_latest"
338+
[centos-ceph-jewel]="RPM oracle-ceph-release-el7"
339+
[centos-gluster41]="RPM oracle-gluster-release-el7"
340+
[centos-gluster5]="RPM oracle-gluster-release-el7"
341+
[centos-gluster46]="RPM oracle-gluster-release-el7"
342+
[centos-nfs-ganesha30]="RPM oracle-gluster-release-el7"
343+
[centos-ovirt42]="RPM oracle-ovirt-release-el7"
344+
[centos-ovirt43]="RPM oracle-ovirt-release-el7"
345+
[centos-sclo-sclo]="RPM oracle-softwarecollection-release-el7"
346+
[centos-sclo-rh]="RPM oracle-softwarecollection-release-el7"
347+
)
348+
;;
349+
8*)
350+
declare -A repositories=(
351+
[AppStream]="REPO ol8_appstream"
352+
[BaseOS]="REPO ol8_baseos_latest"
353+
[HighAvailability]="REPO ol8_addons"
354+
[PowerTools]="REPO ol8_codeready_builder"
355+
[centos-release-nfs-ganesha28]="RPM oracle-gluster-release-el8"
356+
[centos-gluster6-test]="RPM oracle-gluster-release-el8"
357+
[centos-gluster7]="RPM oracle-gluster-release-el8"
358+
[centos-gluster8]="RPM oracle-gluster-release-el8"
359+
)
360+
;;
361+
esac
362+
363+
# For each entry in the list, enable it
364+
for reponame in ${enabled_repos}; do
365+
# action[0] will be REPO or RPM
366+
# action[1] will be the repos details or the RPMs name
367+
IFS=" " read -r -a action <<< "${repositories[${reponame}]}"
368+
if [[ -n ${action[0]} ]]; then
369+
if [ "${action[0]}" == "REPO" ] ; then
370+
matching_repo=${action[1]}
371+
echo "Enabling ${matching_repo} which replaces ${reponame}"
372+
# An RPM that describes debuginfo repository does not exist
373+
# check to see if the repo id starts with https, if it does then
374+
# create a new repo pointing to the repository
375+
if [[ ${matching_repo} =~ https.* ]]; then
376+
yum-config-manager --add-repo "${matching_repo}"
377+
else
378+
yum-config-manager --enable "${matching_repo}"
379+
fi
380+
elif [ "${action[0]}" == "RPM" ] ; then
381+
matching_rpm=${action[1]}
382+
echo "Installing ${matching_rpm} to get content that replaces ${reponame}"
383+
yum --assumeyes --disablerepo "*" --enablerepo "ol*_latest" install "${matching_rpm}"
384+
fi
385+
fi
386+
done
387+
275388
echo "Installing base packages for Oracle Linux..."
276389
if ! yum shell -y <<EOF
277390
remove ${bad_packages[@]}

0 commit comments

Comments
 (0)