#!/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 "

Repo Requires Differences for: ${REPO1} vs. ${REPO2}

" echo '
' echo " Generated by Repo Requires Compare Script at: $(date +'%Y-%m-%d %H:%M:%S')
" # 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 "" 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 "" 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 "
", to make friendly html output: pkgdiff1=$(echo "${pkgdiff1}" | sed 's/$/
/') pkgdiff2=$(echo "${pkgdiff2}" | sed 's/$/
/') # Output table data with differences: echo "" fi # No package diff detected == don't print anything, go to the next package done echo "
${REPO1} Package ${REPO2} Package Diff -${REPO1} Diff +${REPO2})
${pkg}-${version1}-${release1} (DOES NOT EXIST) N/A N/A
${pkg}-${version1}-${release1} ${pkg}-${version2}-${release2} DIFFERENT VERSIONS - Comparison not valid N/A
${pkg}-${version1}-${release1} ${pkg}-${version2}-${release2} ${pkgdiff1} ${pkgdiff2}
"