Most distro uses the distroverpkg version to get the releasever and basearch.
If you look at /etc/yum.conf, you will see that distrover is set to redhat-release (for RHEL), enterpriselinux-release (for OEL), and others.
To get the package name:
distro=$(sed -n 's/^distroverpkg=//p' /etc/yum.conf)
To get the releasever:
releasever=$(rpm -q --qf "%{version}" -f /etc/$distro)
To get the basearch:
basearch=$(rpm -q --qf "%{arch}" -f /etc/$distro)
The new code above will try to get the package associated with a file /etc/$distro
. Some Linux adds /etc/redhat-release
to their package release.
If you get file not owned by any package
then use the /etc/*-release
file that came with your distro. It is probably /etc/centos-release
.
You can check the appropriate /etc/*-release
appropriate for this code by checking which file is packaged with centos.
rpm -qf /etc/*-release
Then use this file instead of the first line above.
distro=/etc/centos-release
Here's an example from OEL where /etc/redhat-release
is packaged as enterprise-release
.
rpm -q --qf "%{name}" -f /etc/redhat-release
Output:
enterprise-release