130 lines
4.8 KiB
Bash
130 lines
4.8 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
REPO1="$1"
|
||
|
REPO2="$2"
|
||
|
|
||
|
rm -rf /tmp/repocompare
|
||
|
mkdir -p /tmp/repocompare/{${REPO1},${REPO2}}
|
||
|
|
||
|
|
||
|
dnf repoquery --repo ${REPO1} --latest-limit 1 --queryformat '# %{name} %{version} %{release}\n%{requires}|' | grep -v " Subscription " > /tmp/repocompare/${REPO1}.txt
|
||
|
dnf repoquery --repo ${REPO2} --latest-limit 1 --queryformat '# %{name} %{version} %{release}\n%{requires}|' | grep -v " Subscription " > /tmp/repocompare/${REPO2}.txt
|
||
|
|
||
|
IFS='|'
|
||
|
for i in $(echo "${REPO1}|${REPO2}"); do
|
||
|
for pkg in $(cat /tmp/repocompare/${i}.txt); do
|
||
|
|
||
|
# Trim the release tag and module info (.el8*, .module*) off the end of the release and requires info, they are likely never to match
|
||
|
pkg=$(echo "${pkg}" | sed -e 's/\.module.*$/\.module/g' | sed -e 's/\.el.*$//g')
|
||
|
|
||
|
# Get just the requires without the name+version+release line:
|
||
|
requires=$(echo "${pkg}" | grep -v '#' | sort)
|
||
|
|
||
|
# Isolate the line with the package name + version + releasetag on it (starts with a "#")
|
||
|
pkgline=$(echo "${pkg}" | grep '#')
|
||
|
|
||
|
|
||
|
# Get name (no version) of the package - we will make this the name of our file
|
||
|
pkgname=$(echo "${pkgline}" | awk '{print $2}')
|
||
|
|
||
|
|
||
|
# Write the requires + name/version/release combo to its own file:
|
||
|
echo "${pkgline}${requires}" > /tmp/repocompare/${i}/${pkgname}
|
||
|
|
||
|
done
|
||
|
|
||
|
# Hacky: RHEL has all its requires in the rpm-command style, which means lots of "(64bit)" lines that other el repos don't have
|
||
|
# This just removes them
|
||
|
sed -i 's/\(64bit\)//' /tmp/repocompare/${i}/*
|
||
|
|
||
|
done
|
||
|
|
||
|
# HTML Header:
|
||
|
echo "<html><h3>Repo Requires Differences for: ${REPO1} vs. ${REPO2}</h3>"
|
||
|
echo '
|
||
|
<style>
|
||
|
table {
|
||
|
border-collapse: collapse;
|
||
|
width: 90%;
|
||
|
}
|
||
|
|
||
|
th, td {
|
||
|
text-align: left;
|
||
|
padding: 8px;
|
||
|
}
|
||
|
|
||
|
tr:nth-child(even) {background-color: #d4d4d4;}
|
||
|
</style>
|
||
|
|
||
|
<div style="overflow-x:auto;">
|
||
|
'
|
||
|
|
||
|
echo "
|
||
|
<i>Generated by Repo Requires Compare Script at: $(date +'%Y-%m-%d %H:%M:%S') </i>
|
||
|
<br />
|
||
|
|
||
|
<table>
|
||
|
<tr><th width="20%">${REPO1} Package</th> <th width="20%">${REPO2} Package</th> <th width="30%">Diff -${REPO1} </th> <th width="30%">Diff +${REPO2}) </th></tr>
|
||
|
|
||
|
"
|
||
|
|
||
|
|
||
|
# Now that we have our packages, their versions and requires info all in individual files, let's compare them!
|
||
|
# Simple use of git diff program to get "+" and "-" differences and spit them to an HTML table
|
||
|
IFS='
|
||
|
'
|
||
|
for pkgfile in $(ls -1 /tmp/repocompare/${REPO1}/*); do
|
||
|
|
||
|
|
||
|
# Package name - should be same for both repos
|
||
|
pkg=$(basename ${pkgfile})
|
||
|
|
||
|
# Package version - source repo (3rd field in txt file)
|
||
|
version1=$(grep '#' ${pkgfile} | head -1 | awk '{print $3}')
|
||
|
|
||
|
# Package release - sourcerepo (4th / last field in first line of txt file)
|
||
|
release1=$(grep '#' ${pkgfile} | head -1 | awk '{print $4}')
|
||
|
|
||
|
|
||
|
# If package doesn't exist in target repo, we'll stop here: (we can't compare Requires: for a non-existent package!)
|
||
|
if [ ! -f "/tmp/repocompare/${REPO2}/${pkg}" ]; then
|
||
|
echo "<tr> <td>${pkg}-${version1}-${release1} </td> <td>(DOES NOT EXIST) </td> <td> N/A </td> <td> N/A </td> </tr>"
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
# We confirmed the other package exists, now get the version and release for the destination package/repo (REPO2):
|
||
|
version2=$(grep '#' /tmp/repocompare/${REPO2}/${pkg} | head -1 | awk '{print $3}')
|
||
|
release2=$(grep '#' /tmp/repocompare/${REPO2}/${pkg} | head -1 | awk '{print $4}')
|
||
|
|
||
|
|
||
|
# If a package has different versions, that is also a special case - we don't want to compare Requires:
|
||
|
if [[ "${version1}" != "${version2}" ]] || [[ "${release1}" != "${release2}" ]]; then
|
||
|
echo "<tr> <td>${pkg}-${version1}-${release1} </td> <td>${pkg}-${version2}-${release2} </td> <td>DIFFERENT VERSIONS - Comparison not valid </td> <td> N/A </td> </tr>"
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
|
||
|
# Do a diff of the requires files, find only the lines that show differences (lines that start with + or -):
|
||
|
pkgdiff1=$(git --no-pager diff /tmp/repocompare/${REPO1}/${pkg} /tmp/repocompare/${REPO2}/${pkg} | grep -A1000 '@@' | grep '^\-' | sort)
|
||
|
pkgdiff1=$(echo "${pkgdiff1}" | grep -v '\-libc\.so\.6(' | grep -v '^\-libc\.so\.6$' )
|
||
|
|
||
|
pkgdiff2=$(git --no-pager diff /tmp/repocompare/${REPO1}/${pkg} /tmp/repocompare/${REPO2}/${pkg} | grep -A1000 '@@' | grep '^+' | sort)
|
||
|
|
||
|
|
||
|
# If our git diff command returned something (is not empty), then we want to display that as a table row:
|
||
|
if [[ ! -z "${pkgdiff1}" ]] || [[ ! -z "${pkgdiff2}" ]]; then
|
||
|
# Swap "\n" for "<br />", to make friendly html output:
|
||
|
pkgdiff1=$(echo "${pkgdiff1}" | sed 's/$/<br \/>/')
|
||
|
pkgdiff2=$(echo "${pkgdiff2}" | sed 's/$/<br \/>/')
|
||
|
|
||
|
# Output table data with differences:
|
||
|
echo "<tr> <td>${pkg}-${version1}-${release1} </td> <td>${pkg}-${version2}-${release2} </td> <td>${pkgdiff1} </td> <td>${pkgdiff2} </tr>"
|
||
|
fi
|
||
|
|
||
|
# No package diff detected == don't print anything, go to the next package
|
||
|
|
||
|
done
|
||
|
|
||
|
echo "</table></html>"
|
||
|
|