mirror of
https://github.com/gentoo-mirror/guru.git
synced 2026-04-07 03:10:15 -04:00
.github/workflows/duplicates.yml: update/reformat
- add self as maintainer - update variable names - un-nest for loops - check for matching package name before starting loops - speed improvements: ~3s vs 5m Package-Manager: Portage-3.0.14, Repoman-3.0.2 Signed-off-by: Theo Anderson <telans@posteo.de>
This commit is contained in:
@@ -1,75 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
#! /usr/bin/env bash
|
||||
# Maintainer: Andrew Ammerlaan <andrewammerlaan@riseup.net>
|
||||
# Maintainer: Theo Anderson <telans@posteo.de>
|
||||
#
|
||||
# This checks if packages in ::guru are also in ::gentoo
|
||||
#
|
||||
# This checks for potential and exact package matches within ::guru & ::gentoo
|
||||
# Note that this is not going to be 100% accurate
|
||||
#
|
||||
#
|
||||
|
||||
printf "\nChecking for duplicates....\n"
|
||||
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)/"
|
||||
)
|
||||
)
|
||||
GURU_PACKAGES=(
|
||||
$(find . -mindepth 2 -maxdepth 2 -printf "%P\n" \
|
||||
| sort | grep -Ev "^(.git|.github|metadata|profiles|scripts)/"
|
||||
)
|
||||
)
|
||||
|
||||
gentoo_location="/var/db/repos/gentoo"
|
||||
guru_location="."
|
||||
printf "\nChecking for duplicates...\n"
|
||||
|
||||
gentoo_packs=$(find ${gentoo_location} -mindepth 2 -maxdepth 2 -printf "%P\n" | sort | grep -Ev "^(.git|.github|metadata|profiles|scripts)/")
|
||||
guru_packs=$(find ${guru_location} -mindepth 2 -maxdepth 2 -printf "%P\n" | sort | grep -Ev "^(.git|.github|metadata|profiles|scripts)/")
|
||||
|
||||
pack_overrides="" pack_close_match_in_cat="" pack_close_match=""
|
||||
for guru_pack in ${guru_packs}; do
|
||||
# separate category and packages
|
||||
guru_pack_cat="${guru_pack%%/*}"
|
||||
guru_pack_name="${guru_pack##*/}"
|
||||
|
||||
# convert all to lowercase
|
||||
guru_pack_name="${guru_pack_name,,}"
|
||||
|
||||
# stip all numbers, dashes, underscores and pluses
|
||||
guru_pack_name="${guru_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##*/}"
|
||||
|
||||
# convert all to lowercase
|
||||
gentoo_pack_name="${gentoo_pack_name,,}"
|
||||
|
||||
# stip all numbers, dashes, underscores and pluses
|
||||
gentoo_pack_name="${gentoo_pack_name/[0-9-_+]}"
|
||||
|
||||
#TODO: check DESCRIPTION, HOMEPAGE and SRC_URI for close matches
|
||||
|
||||
if [[ "${gentoo_pack_name}" == "${guru_pack_name}" ]]; then
|
||||
if [[ "${gentoo_pack_cat}" == "${guru_pack_cat}" ]]; then
|
||||
if [[ "${gentoo_pack}" == "${guru_pack}" ]]; then
|
||||
pack_overrides+="\t${guru_pack}::guru exact match of ${gentoo_pack}::gentoo\n"
|
||||
else
|
||||
pack_close_match_in_cat+="\t${guru_pack}::guru possible duplicate of ${gentoo_pack}::gentoo\n"
|
||||
fi
|
||||
else
|
||||
pack_close_match+="\t${guru_pack}::guru possible duplicate of ${gentoo_pack}::gentoo\n"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
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
|
||||
GENTOO_PKG_NAMES+=( ${GENTOO_PKG_NAME} )
|
||||
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"
|
||||
printf "Testing ${#GURU_PACKAGES[@]} GURU packages against ${#GENTOO_PKG_NAMES[@]} Gentoo packages\n"
|
||||
|
||||
for GURU_PKG in ${GURU_PACKAGES[@]}; do
|
||||
GURU_PKG_CATEGORY=${GURU_PKG%%/*}
|
||||
GURU_PKG_NAME=${GURU_PKG##*/}
|
||||
GURU_PKG_NAME=${GURU_PKG_NAME,,}
|
||||
|
||||
if [[ ${GENTOO_PKG_NAMES[@]} =~ " ${GURU_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]} == ${GURU_PKG_NAME} ]] && index+=( $i ) # Find the category/index for multiple matching names
|
||||
done
|
||||
|
||||
for i in ${index[@]}; do # For each possible match
|
||||
if [[ ${GENTOO_PACKAGES[$i]} == ${GURU_PKG} ]]; then
|
||||
PKG_EXACT_MATCH+="\t${GURU_PKG}::guru exact match of ${GENTOO_PACKAGES[$i]}::gentoo\n"
|
||||
break # An exact match is fatal, no need to continue
|
||||
elif [[ ${GENTOO_CATEGORIES[$i]} == ${GURU_PKG_CATEGORY} ]]; then # Possible match within the same category
|
||||
PKG_CATEGORY_MATCH+="\t${GURU_PKG}::guru possible duplicate of ${GENTOO_PACKAGES[$i]}::gentoo\n"
|
||||
else # Possible match in a different category
|
||||
PKG_SPECULATIVE_MATCH+="\t${GURU_PKG}::guru possible duplicate of ${GENTOO_PACKAGES[$i]}::gentoo\n"
|
||||
fi
|
||||
done
|
||||
unset index
|
||||
fi
|
||||
done
|
||||
|
||||
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"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user