commit: ebbdcf28214532dc78f46b3f5b1c730f02a8ce1f Author: Andrew Ammerlaan <andrewammerlaan <AT> riseup <DOT> net> AuthorDate: Thu Feb 18 11:09:58 2021 +0000 Commit: Andrew Ammerlaan <andrewammerlaan <AT> riseup <DOT> net> CommitDate: Thu Feb 18 11:09:58 2021 +0000 URL: https://gitweb.gentoo.org/proj/sci.git/commit/?id=ebbdcf28
scripts/check-duplicates.sh: backport improvements from ::guru Signed-off-by: Andrew Ammerlaan <andrewammerlaan <AT> riseup.net> scripts/check-duplicates.sh | 113 ++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/scripts/check-duplicates.sh b/scripts/check-duplicates.sh index 47a4a12f1..85af7839c 100755 --- a/scripts/check-duplicates.sh +++ b/scripts/check-duplicates.sh @@ -1,76 +1,77 @@ -#!/usr/bin/env bash +#! /usr/bin/env bash # Maintainer: Andrew Ammerlaan <[email protected]> +# Maintainer: Theo Anderson <[email protected]> # -# This checks if packages in ::science are also in ::gentoo -# +# This checks for potential and exact package matches within an overlay & ::gentoo # Note that this is not going to be 100% accurate # -# - -printf "\nChecking for duplicates....\n" -gentoo_location="/var/db/repos/gentoo" -science_location="." +GENTOO_DIR="/var/db/repos/gentoo" +GENTOO_PACKAGES=( + $(find ${GENTOO_DIR} -mindepth 2 -maxdepth 2 -printf "%P\n" \ + | sort | grep -Ev "^(.git|.github|metadata|profiles|scripts)/" + ) +) +REPO_PACKAGES=( + $(find . -mindepth 2 -maxdepth 2 -printf "%P\n" \ + | sort | grep -Ev "^(.git|.github|metadata|profiles|scripts)/" + ) +) -gentoo_packs=$(find ${gentoo_location} -mindepth 2 -maxdepth 2 -printf "%P\n" | sort | grep -Ev "^(.git|.github|metadata|profiles|scripts)/") -science_packs=$(find ${science_location} -mindepth 2 -maxdepth 2 -printf "%P\n" | sort | grep -Ev "^(.git|.github|metadata|profiles|scripts)/") +REPO_NAME="$(cat profiles/repo_name)" -pack_overrides="" pack_close_match_in_cat="" pack_close_match="" -for science_pack in ${science_packs}; do - # separate category and packages - science_pack_cat="${science_pack%%/*}" - science_pack_name="${science_pack##*/}" +printf "\nChecking for duplicates...\n" - # convert all to lowercase - science_pack_name="${science_pack_name,,}" - - # stip all numbers, dashes, underscores and pluses - science_pack_name="${science_pack_name/[0-9-_+]}" - - for gentoo_pack in ${gentoo_packs}; do - # separate category and packages - gentoo_pack_cat="${gentoo_pack%%/*}" - gentoo_pack_name="${gentoo_pack##*/}" +for GENTOO_PKG in ${GENTOO_PACKAGES[@]}; do + GENTOO_CATEGORIES+=( ${GENTOO_PKG%%/*} ) # Separate category + GENTOO_PKG_NAME=${GENTOO_PKG##*/} # Separate name + GENTOO_PKG_NAME=${GENTOO_PKG_NAME,,} # Force lower case, e.g. to match foobar and FooBar + GENTOO_PKG_NAME=${GENTOO_PKG_NAME/[-_]} # Remove underscores and dashes, e.g. to match foo-bar and foo_bar + GENTOO_PKG_NAMES+=( ${GENTOO_PKG_NAME} ) +done - # convert all to lowercase - gentoo_pack_name="${gentoo_pack_name,,}" +printf "Testing ${#REPO_PACKAGES[@]} ${REPO_NAME^} packages against ${#GENTOO_PKG_NAMES[@]} Gentoo packages\n" - # stip all numbers, dashes, underscores and pluses - gentoo_pack_name="${gentoo_pack_name/[0-9-_+]}" +for REPO_PKG in ${REPO_PACKAGES[@]}; do + REPO_PKG_CATEGORY=${REPO_PKG%%/*} + REPO_PKG_NAME=${REPO_PKG##*/} + REPO_PKG_NAME=${REPO_PKG_NAME,,} + REPO_PKG_NAME=${REPO_PKG_NAME/[-_]} - #TODO: check DESCRIPTION, HOMEPAGE and SRC_URI for close matches + if [[ ${GENTOO_PKG_NAMES[@]} =~ " ${REPO_PKG_NAME} " ]]; then # Check for a matcing name in the Gentoo tree, + for (( i=0; i<${#GENTOO_PKG_NAMES[@]}; i++ )); do # otherwise there is no need to continue + [[ ${GENTOO_PKG_NAMES[$i]} == ${REPO_PKG_NAME} ]] && index+=( $i ) # Find the category/index for multiple matching names + done - if [[ "${gentoo_pack_name}" == "${science_pack_name}" ]]; then - if [[ "${gentoo_pack_cat}" == "${science_pack_cat}" ]]; then - if [[ "${gentoo_pack}" == "${science_pack}" ]]; then - pack_overrides+="\t${science_pack}::science exact match of ${gentoo_pack}::gentoo\n" - else - pack_close_match_in_cat+="\t${science_pack}::science possible duplicate of ${gentoo_pack}::gentoo\n" - fi - else - pack_close_match+="\t${science_pack}::science possible duplicate of ${gentoo_pack}::gentoo\n" + for i in ${index[@]}; do # For each possible match + if [[ ${GENTOO_PACKAGES[$i]} == ${REPO_PKG} ]]; then + PKG_EXACT_MATCH+="\t${REPO_PKG}::${REPO_NAME} exact match of ${GENTOO_PACKAGES[$i]}::gentoo\n" + break # An exact match is fatal, no need to continue + elif [[ ${GENTOO_CATEGORIES[$i]} == ${REPO_PKG_CATEGORY} ]]; then # Possible match within the same category + PKG_CATEGORY_MATCH+="\t${REPO_PKG}::${REPO_NAME} possible duplicate of ${GENTOO_PACKAGES[$i]}::gentoo\n" + else # Possible match in a different category + PKG_SPECULATIVE_MATCH+="\t${REPO_PKG}::${REPO_NAME} possible duplicate of ${GENTOO_PACKAGES[$i]}::gentoo\n" fi - fi - done + done + unset index + fi done -if [ -n "${pack_close_match}" ]; then - printf "\nWARNING: The following packages closely match packages in the main Gentoo repository\n" - printf "${pack_close_match}" - printf "Please check these manually\n" +if [[ -n ${PKG_SPECULATIVE_MATCH} ]]; then + printf "\nWARNING: The following packages closely match packages in the main Gentoo repository:\n" + printf "${PKG_SPECULATIVE_MATCH}" + printf "Please check these manually.\n" fi -if [ -n "${pack_close_match_in_cat}" ]; then - printf "\nWARNING: The following packages closely match packages in the main Gentoo repository in the same category\n" - printf "${pack_close_match_in_cat}" - printf "Please check these manually\n" +if [[ -n ${PKG_CATEGORY_MATCH} ]]; then + printf "\nWARNING: The following packages closely match packages in the main Gentoo repository, in the same category:\n" + printf "${PKG_CATEGORY_MATCH}" + printf "Please check these manually.\n" fi -if [ -n "${pack_overrides}" ]; then - printf "\nERROR: The following packages override packages in the main Gentoo repository\n" - printf "${pack_overrides}" - printf "Please remove these packages\n" - # do not exit fatally on ::science - # exit 1 +if [[ -n ${PKG_EXACT_MATCH} ]]; then + printf "\nERROR: The following packages override packages in the main Gentoo repository:\n" + printf "${PKG_EXACT_MATCH}" + printf "Please remove these packages.\n" + exit 1 fi -exit 0
