diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2022-09-10 18:18:20 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2023-12-14 17:13:11 -0500 |
commit | 06e742c8dc54a1f77d7a4758410e4bfe414a7f0b (patch) | |
tree | e1102eadf0e980167e83296e4b142fa1282e7708 | |
parent | d6b98eb80f9c92a9dd524e43cb112e25c6f14a16 (diff) |
[parabola-dependents]: accept param in multiple forms
-rwxr-xr-x | parabola-dependents | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/parabola-dependents b/parabola-dependents index 397dc94..fd61a56 100755 --- a/parabola-dependents +++ b/parabola-dependents @@ -3,6 +3,9 @@ readonly ABS_DIR=/packages/abslibre readonly BE_VERBOSE=$( [[ "${1}" == '-v' ]] && echo 1 || echo 0 ) ; (( $BE_VERBOSE )) && shift ; +readonly PKGBUILD_SED_RX='s|/PKGBUILD$|| ; s|([^/]*/)?([^/]+)/([^/]+)$|\2 \3|' +readonly DEP=$( sed -E "${PKGBUILD_SED_RX}" <<<${1} | cut -d ' ' -f 2 ) + # readonly REPOS=( nonprism nonsystemd{-testing,} libre{-testing,} readonly REPOS=( nonprism{-testing,} nonsystemd{-testing,} libre{-testing,} @@ -19,26 +22,30 @@ license=(GPL) source=(PKGBUILD) sha256sums=(SKIP) package() { echo "created '"'\${pkgname}'"' package" ; }' -readonly USAGE='USAGE: - parabola-dependents [-v] <PACKAGE_NAME> +readonly USAGE="USAGE: + parabola-dependents [-v] <PACKAGE_BASE> + parabola-dependents [-v] <PKGBUILD> List all parabola packages which are dependents of a specified package. This includes direct dependents, transitive dependents, and makedepends dependents. NOTE: The verbose report does not account for makedepends of packages not in abslibre. + The positional argument: <PACKAGE_BASE> or <PKGBUILD> may be a 'pkgbase' name, + or a path to an abslibre 'pkgbase' directory, or a path to a PKGBUILD. + Paths may be absolute or relative. They will all resolve to a 'pkgbase' name. + + If 'pkgbase' does not exist in any database, a dummy package will be created, + in memory, upon which for pactree to reflect. + By default, only first-order dependents are listed, with counts of higher-order dependents. - If <PACKAGE_NAME> does not exist, a dummy package will be created, - in memory, for pactree to reflect upon. - - Note: this script can take several minutes to complete, - if the dependency-tree for <PACKAGE_NAME> is large. + Note: this script can take several minutes to complete, if the dependency-tree is large. Options: -v - Itemize all higher-order dependents, displaying the dependency-chain.' + Itemize all higher-order dependents, displaying the dependency-chain." readonly INVALID_ARG_MSG="no dependency package specified\n\n${USAGE}" readonly UNPRIVILEGED_MSG="this script requires super-user privileges" readonly CBLUE='\033[0;36m' @@ -73,10 +80,9 @@ LogError() # (source_file func_name line_n) printf "${CRED}ERROR: in ${func_name}\n${line_n}: %s${CEND}\n" "${err_loc=}" >&2 } -Init() # (dep_pkgname) +Init() { - local dep_pkgname=$1 - local dummy_pkg=${dep_pkgname}-0.0.0-42-$(uname -m).pkg.tar.xz + local dummy_pkg=${DEP}-0.0.0-42-$(uname -m).pkg.tar.xz readonly DB_DIR="$(su $(logname) -c 'mktemp -d -t parabola-dependents-XXXXXXXXXX')" readonly CFG_FILE=${DB_DIR}/pacman-all.conf @@ -91,17 +97,17 @@ Init() # (dep_pkgname) pacman ${OPTS} -Sy &> /dev/null || true # create dummy for missing dependency package - if ! pacman ${OPTS} -Ss ^${dep_pkgname}$ &> /dev/null - then Log "package '${dep_pkgname}' not found - creating dummy" + if ! pacman ${OPTS} -Ss ^${DEP}$ &> /dev/null + then Log "package '${DEP}' not found - creating dummy" cd ${DB_DIR} - printf "${DUMMY_PKGBUILD}\n" ${dep_pkgname} > ./PKGBUILD + printf "${DUMMY_PKGBUILD}\n" ${DEP} > ./PKGBUILD su $(logname) -c 'makepkg --force &> /dev/null' [[ -f ./${dummy_pkg} ]] repo-add --new parabola-dependents.db.tar ./${dummy_pkg} &> /dev/null - Log "dummy package '${dep_pkgname}' created" + Log "dummy package '${DEP}' created" printf "[parabola-dependents]\nServer = file://${DB_DIR}\n" >> ${CFG_FILE} fi pacman ${OPTS} -Sy &> /dev/null @@ -112,9 +118,8 @@ IsArchRepo() # (repo) local repo=$1 ; [[ "${repo}" =~ ^(community|core|extra|multilib|testing)$ ]] } -CollectResults() # (dep_pkgname) +CollectResults() { - local dep_pkgname=$1 local dep_chains dep_chain dep_pkg via_pkg repos repo pkgbase # TODO: --chain is a custom pactree feature @@ -123,19 +128,18 @@ export PATH="/code/pacman-contrib/src:${PATH}" # query database for dependents Log "querying database ...." mapfile -t dep_chains < <(pactree ${OPTS} --sync --reverse --unique --chain \ - ${dep_pkgname} | sort ) + ${DEP} | sort ) # parse PKGBUILDs for makedepends Log "searching abslibre ...." cd ${ABS_DIR} for pkgbuild in $(find . -name PKGBUILD) - do if git ls-tree master ${pkgbuild} | grep -E '/PKGBUILD$' > /dev/null && - ( source ${pkgbuild} ; grep ${dep_pkgname} <<<${makedepends[*]} > /dev/null ) - then repo=$( dirname $( dirname ${pkgbuild} )) - pkgbase=$( dirname ${pkgbuild} ) + do if git ls-tree master ${pkgbuild} | grep -E '/PKGBUILD$' > /dev/null && + ( source ${pkgbuild} ; grep ${DEP} <<<${makedepends[*]} > /dev/null ) + then repo=$( sed -E "${PKGBUILD_SED_RX}" <<<${pkgbuild} | cut -d ' ' -f 1) + pkgbase=$(sed -E "${PKGBUILD_SED_RX}" <<<${pkgbuild} | cut -d ' ' -f 2) Makedependents+=( ${repo}/${pkgbase} ) fi - done # compile results @@ -208,6 +212,6 @@ trap 'LogError "${BASH_SOURCE[0]}" "${FUNCNAME[0]}" "${LINENO}"' ERR LANG=C -Init $1 -CollectResults $1 +Init +CollectResults PrintReport |