2021-06-29 17:23:57 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Script takes 2 arguments: SOURCEREPO and TARGETREPO (ex: ./repo_compare_html.sh RHEL8_BaseOS Rocky8_BaseOS )
|
|
|
|
# The arguments must be named dnf/yum repos on the system
|
|
|
|
#
|
|
|
|
# We will loop through the RPM names from SOURCEREPO, and attempt to find name/version/release matches in TARGETREPO
|
2022-06-15 21:26:21 +00:00
|
|
|
# An HTML table page will be sent to stdout showing the differences
|
2021-06-29 17:23:57 +00:00
|
|
|
#
|
2022-06-15 21:26:21 +00:00
|
|
|
|
2021-06-29 17:23:57 +00:00
|
|
|
|
|
|
|
REPO1="$1"
|
|
|
|
REPO2="$2"
|
|
|
|
|
2022-06-15 21:26:21 +00:00
|
|
|
pkglist1=$(dnf repoquery --latest-limit 1 --repo "${REPO1}" --queryformat "%{name} %{version} %{release}" | grep -vi " subscription ")
|
|
|
|
pkglist2=$(dnf repoquery --latest-limit 1 --repo "${REPO2}" --queryformat "%{name} %{version} %{release}" | grep -vi " subscription ")
|
2021-06-29 17:23:57 +00:00
|
|
|
|
2022-06-15 21:26:21 +00:00
|
|
|
# Strip some ending package info off like this:
|
|
|
|
# 1: moduleXYZ info comes off
|
|
|
|
# 2: If a dotrelease tag is present (like .el8_4.3), then preserve the .3 but remove the el8_* tag
|
|
|
|
# 3: If a dotrelease tag is not present, then simply take the .el8* off from the end
|
|
|
|
# 4: Remove any trailing ".rocky" tag as well from the end if a dotrelease is not present
|
|
|
|
# The moduleXYZ will never match versions, and the el8 tagging may be different (el8 vs. el8_3, el8_4, etc.)
|
|
|
|
pkglist1=$(echo "${pkglist1}" | sed -e 's/\.module.*$/\.module/g' | sed -e 's/\.el.*\.\(.*\)$/\.\1/g' | sed -e 's/\.el.*$//g' | sed 's/\.rocky$//')
|
|
|
|
pkglist2=$(echo "${pkglist2}" | sed -e 's/\.module.*$/\.module/g' | sed -e 's/\.el.*\.\(.*\)$/\.\1/g' | sed -e 's/\.el.*$//g' | sed 's/\.rocky$//')
|
2021-06-29 17:23:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Turn the first pkg list into a comma-separated list (instead of newline-separated)
|
|
|
|
# (makes it easier to use IFS=',' in all of our for loops)
|
2022-06-15 21:26:21 +00:00
|
|
|
pkglist1=$(echo "${pkglist1}" | tr '\n' ',')
|
2021-06-29 17:23:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
#echo "$pkglist1" > debug1.txt
|
|
|
|
#echo "$pkglist2" > debug2.txt
|
|
|
|
|
|
|
|
|
2022-06-15 21:26:21 +00:00
|
|
|
|
2021-06-29 17:23:57 +00:00
|
|
|
# HTML style header for table:
|
|
|
|
echo "<html><h3>Repo Version Differences for: ${REPO1} vs. ${REPO2}</h3>"
|
|
|
|
echo '
|
|
|
|
<style>
|
|
|
|
table {
|
|
|
|
border-collapse: collapse;
|
2022-06-15 21:26:21 +00:00
|
|
|
width: 90%;
|
2021-06-29 17:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
th, td {
|
|
|
|
text-align: left;
|
|
|
|
padding: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr:nth-child(even) {background-color: #d4d4d4;}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<div style="overflow-x:auto;">
|
|
|
|
'
|
|
|
|
|
|
|
|
echo "
|
2022-06-15 21:26:21 +00:00
|
|
|
<i>Generated by Repo Compare Script at: $(date +'%Y-%m-%d %H:%M:%S') </i>
|
2021-06-29 17:23:57 +00:00
|
|
|
<br />
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr><th>${REPO1} Version</th> <th>${REPO2} Version</th></tr>
|
|
|
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IFS=','
|
|
|
|
# Main loop to check all packages from our "source" repo
|
2022-06-15 21:26:21 +00:00
|
|
|
for pkg in ${pkglist1}; do
|
2021-06-29 17:23:57 +00:00
|
|
|
|
|
|
|
# Extract name/version/tag info from package (filtering out modular + el8* info from tag)
|
2022-06-15 21:26:21 +00:00
|
|
|
_name=$(echo "$pkg" | awk '{print $1}')
|
|
|
|
_version=$(echo "$pkg" | awk '{print $2}')
|
|
|
|
_tag=$(echo "$pkg" | awk '{print $3}')
|
2021-06-29 17:23:57 +00:00
|
|
|
|
|
|
|
# every package match is false by default, until we match it
|
|
|
|
isPkgMatched=0
|
|
|
|
|
|
|
|
|
|
|
|
# Find any packages in the target repo with the same name as the one we're interested in from the source repo:
|
|
|
|
# (easy to match the exact name if we include a space separator in our grep)
|
|
|
|
# (We turn it into a comma separated list as well so we can do another for loop against the result set)
|
2022-06-15 21:26:21 +00:00
|
|
|
pkgmatches=$(echo "${pkglist2}" | grep "^${_name} ")
|
2021-06-29 17:23:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
# If there are no matches, we output a DOES NOT EXIST and don't bother with searching the results
|
|
|
|
if [[ -z "${pkgmatches}" ]]; then
|
|
|
|
echo "<tr> <td>${_name}-${_version}-${_tag}</td> <td>(DOES NOT EXIST)</td> </tr>"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Loop through each result (name matches) and look for an exact version match:
|
2022-06-15 21:26:21 +00:00
|
|
|
for match in ${pkgmatches}; do
|
|
|
|
_name2=$(echo "$match" | awk '{print $1}')
|
|
|
|
_version2=$(echo "$match" | awk '{print $2}')
|
|
|
|
_tag2=$(echo "$match" | awk '{print $3}')
|
2021-06-29 17:23:57 +00:00
|
|
|
#echo "DEBUG :: _tag2 == $_tag2"
|
|
|
|
|
|
|
|
# If we find a match, then exit this loop and set the flag to found:
|
|
|
|
if [ "${_name}-${_version}-${_tag}" == "${_name2}-${_version2}-${_tag2}" ]; then
|
|
|
|
isPkgMatched=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Get pkgmatches into name-version-release format:
|
2022-06-15 21:26:21 +00:00
|
|
|
pkgmatches=$(echo "${pkgmatches}" | sed 's/ /\-/g' | sed 's/,$//')
|
2021-06-29 17:23:57 +00:00
|
|
|
|
|
|
|
# If package is not matched, then we need to output an HTML row:
|
|
|
|
if [ "$isPkgMatched" == "0" ]; then
|
|
|
|
echo "<tr> <td>${_name}-${_version}-${_tag}</td> <td>${pkgmatches}</td> </tr>"
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
echo "</table></html>"
|
|
|
|
|