From be49af95252f7fb5eb58232dcf80e8a3510e0bf2 Mon Sep 17 00:00:00 2001 From: Scott Little Date: Thu, 17 Dec 2020 16:14:49 -0500 Subject: [PATCH] Add layer awareness to mirror-check.sh This tool was missed when layered builds were introduced. It looks for lst files under the wrong path. I've added a layer arguement and fixed the path. It also needs to ignore commented lines within lst files. I also add dnf support. Cloned from pkg-manager-utils.sh since stx-tools is sometimes expected to stand on it's own. One gap that I'm not addressing in this update. It only looks at the upstream repo, never at the cengn mirror. If a package has been dropped by upstream, it reports as missing. Closes-Bug: 1908751 Signed-off-by: Scott Little Change-Id: Idf4c9010c195f2fe8f7d0432c41c94fab00aec2c --- .gitignore | 1 + centos-mirror-tools/mirror-check.sh | 58 ++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cad81b6e..20552688 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ localrc toCOPY/.gitconfig centos-mirror-tools/logs/ centos-mirror-tools/output/ +centos-mirror-tools/mirror-check-failures.log # Sphinx documentation doc/build/ diff --git a/centos-mirror-tools/mirror-check.sh b/centos-mirror-tools/mirror-check.sh index 29df5823..68516fab 100755 --- a/centos-mirror-tools/mirror-check.sh +++ b/centos-mirror-tools/mirror-check.sh @@ -40,14 +40,43 @@ ERROR_LOG_FILE="mirror-check-failures.log" truncate -s 0 $ERROR_LOG_FILE retcode=0 extra_opts="" +layer="$LAYER" +valid_layers=('compiler' 'distro' 'flock') + + +# Cloned from cgcs-root/build-tools/pkg-manager-utils.sh +# Ideally this can still be used when tools is the only git +# that has been cloned. + +# Yum vs DNF compatibility +YUM=$(which yum 2>> /dev/null) +DNF=$(which dnf 2>> /dev/null) +PKG_MANAGER="" +REPOQUERY=$(which repoquery 2>> /dev/null) +REPOQUERY_SUB_COMMAND="" +REPOQUERY_RESOLVE="--resolve" +REPOQUERY_WHATPROVIDES_DELIM=" " +if [ ! -z ${DNF} ]; then + PKG_MANAGER="dnf" + REPOQUERY=${DNF} + REPOQUERY_SUB_COMMAND="repoquery --disable-modular-filtering" + REPOQUERY_RESOLVE="" + REPOQUERY_WHATPROVIDES_DELIM="," +elif [ ! -z ${YUM} ]; then + PKG_MANAGER="yum" +else + >&2 echo "ERROR: Couldn't find a supported package manager" + exit 1 +fi usage() { - echo "$0 [-c ]" + echo "$0 [-c ] [-l ]" echo "" echo "Options:" echo " -c: Use an alternate yum.conf rather than the system file (option passed" echo " on to subscripts when appropriate)" + echo " -l: Check specific layer (one of 'all ${valid_layers[@]}')" echo "" } @@ -79,8 +108,10 @@ get_repoquery_info() { else repoquery_opts= fi - repoquery $extra_opts ${RELEASEVER} -C --qf '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}' \ - $repoquery_opts "$_package_name" + $REPOQUERY $REPOQUERY_SUB_COMMAND \ + $extra_opts ${RELEASEVER} -C \ + --qf '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}' \ + $repoquery_opts "$_package_name" } _check_rpms() { @@ -113,12 +144,27 @@ check_rpms() { done } -while getopts "c:" opt; do +while getopts "c:l:" opt; do case $opt in c) extra_opts="-c ${OPTARG}" grep -q "releasever=" $OPTARG && RELEASEVER="--$(grep releasever= ${OPTARG})" ;; + l) + layer="${OPTARG}" + if [ "$layer" == "all" ]; then + layer="" + else + case " ${valid_layers[@]} " in + *" $layer "* ) echo "found layer $layer" + ;; + *) echo "'$layer' is invalid" + usage + exit 1 + ;; + esac + fi + ;; \?) echo "Invalid option: -$OPTARG" >&2 usage @@ -133,11 +179,11 @@ if ! yum $extra_opts ${RELEASEVER} makecache; then exit 1 fi -for rpm_list in "$RPMS_CENTOS_LIST" "$RPMS_3RD_PARTY_LIST"; do +for rpm_list in $(find config/centos/$layer -name "$RPMS_CENTOS_LIST" -o -name "$RPMS_3RD_PARTY_LIST"); do info "Reading $rpm_list..." for arch in "src" "noarch" "x86_64"; do info "Getting info for $arch packages..." - rpms=$(echo "$(grep -F "$arch.rpm" < $rpm_list)") + rpms=$(echo "$(grep -v '^#' $rpm_list | grep -F "$arch.rpm")") check_rpms "$rpms" done done