summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2020-09-22 01:41:48 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2021-01-05 22:24:56 -0500
commit41ca916b592b44d0855a568c3688382b46b2a5f7 (patch)
tree0af94b37c4d4c0d2899e16fc7aef6cb1a9ac26b3
parent51f7a5a6943d209c919237daf653b1ae57310957 (diff)
[parabola-dependents]: create dummy for missing dependency package
-rwxr-xr-xsrc/maintenance-tools/parabola-dependents146
1 files changed, 120 insertions, 26 deletions
diff --git a/src/maintenance-tools/parabola-dependents b/src/maintenance-tools/parabola-dependents
index 8947dbf..0e0f619 100755
--- a/src/maintenance-tools/parabola-dependents
+++ b/src/maintenance-tools/parabola-dependents
@@ -1,43 +1,137 @@
#!/bin/bash
+readonly BE_VERBOSE=$( [[ "$1" == '-v' ]] && echo 1 || echo 0 )
+readonly DB_DIR="$(su $(logname) -c 'mktemp -d -t parabola-dependents-XXXXXXXXXX')"
+readonly CFG_FILE=${DB_DIR}/pacman-all.conf
+readonly OPTS="--dbpath=${DB_DIR} --config=${CFG_FILE}"
+readonly REPOS=( nonprism{-testing,} nonsystemd{-testing,} libre{-testing,}
+ kernels{-testing,} testing core extra community{-testing,}
+ pcr{-testing,} nonprism-multilib{-testing,} nonsystemd-multilib
+ libre-multilib{-testing,} multilib{-testing,} pcr-multilib{-testing,} )
+readonly DUMMY_PKGBUILD='pkgname=%s
+pkgver=0.0.0
+pkgrel=42
+pkgdesc="dummy PKGBUILD for experimentation"
+arch=(armv7h i686 x86_64)
+url=https://nowhere.man
+license=(GPL)
+source=(PKGBUILD)
+sha256sums=(SKIP)
+package() { echo "created '"'\${pkgname}'"' package" ; }'
+readonly USAGE='USAGE:
+ parabola-dependents [-v] <PACKAGE_NAME>
-IsArchRepo()
+ List all parabola packages which are dependents of a specified package.
+
+ If <PACKAGE_NAME> does not exist, a dummy package will be created,
+ in memory, for pactree to reflect upon.
+
+ Options:
+ -v
+ Display 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'
+readonly CRED='\033[0;31m'
+readonly CEND='\033[0m'
+
+
+Log() # (log_fmt [args]*)
{
- local repo=$1 ; [[ "$repo" =~ ^(community|core|extra|multilib|testing)$ ]]
+ local log_fmt=$1 ; shift ;
+ local args="$@"
+
+ printf "${CBLUE}${log_fmt}${CEND}\n" ${args}
}
-ListParabolaDependents()
+LogError() # (source_file func_name line_n)
{
- readonly BE_VERBOSE=$( [[ "$1" == '-v' ]] && echo 1 || echo 0 ) ; (( $BE_VERBOSE )) && shift ;
- readonly DEP_PKG=$1
- readonly CFG_FILE=/etc/pacman-all.conf
- readonly CFG="--config=$CFG_FILE"
- read -r -d '' USAGE <<-'USAGE_MSG'
-USAGE:
- parabola-dependents [ -v ] <PACKAGE_NAME>
+ local source_file="$1"
+ local func_name=$2
+ local line_n=$3
- list all parabola packages which are dependents of a specified package
- by default, only first-order dependents are listed, with counts of higher-order dependents
- verbose mode (-v) will itemize all higher-order dependents
-USAGE_MSG
+ printf "${CRED}ERROR: in ${func_name}\n${line_n}: %s${CEND}\n" \
+ "$(awk "(( NR == ${line_n} )) { print }" ${source_file})"
+}
+Init() # (dep_pkgname)
+{
+ local dep_pkgname=$1
+ local dummy_pkg=${dep_pkgname}-0.0.0-42-$(uname -m).pkg.tar.xz
- [[ -z "$DEP_PKG" ]] && echo -e "no dependency package specified\n\n$USAGE" && return 1
- [[ ! -f "$CFG_FILE" ]] && echo "can not find pacman config: $CFG_FILE" && return 1
+ printf "[options]\nArchitecture = auto\n" > ${CFG_FILE}
+ for repo in ${REPOS[@]}
+ do printf "[${repo}]\nInclude = /etc/pacman.d/mirrorlist\n" >> ${CFG_FILE}
+ done
+ printf "[parabola-dependents]\nServer = file://${DB_DIR}\n" >> ${CFG_FILE}
- sudo pacman $CFG -Sy ; echo -e "\nsearching ...\n\n" ;
+ Log "updating database ...."
+ pacman ${OPTS} -Sy &> /dev/null || true
- local dependency_chain pkg repos repo
- while read dependency_chain
- do pkg=$(sed 's|.*<- ||' <<<$dependency_chain)
- repos=$(pacman $CFG -Si $pkg | grep Repository | cut -d ':' -f 2)
- for repo in $repos
- do IsArchRepo $repo && echo "$repo skip $pkg" && continue
+ # create dummy for missing dependency package
+ if ! pacman ${OPTS} -Ss ^${dep_pkgname}$ &> /dev/null
+ then Log "package '${dep_pkgname}' not found - creating dummy"
+ cd ${DB_DIR}
+ printf "${DUMMY_PKGBUILD}\n" ${dep_pkgname} > ./PKGBUILD
+ su $(logname) -c 'makepkg --force &> /dev/null'
- echo "$repo/$pkg $( (( $BE_VERBOSE )) && echo "[ $dependency_chain ]" )"
+ [[ -f ./${dummy_pkg} ]]
+
+ repo-add --new parabola-dependents.db.tar ./${dummy_pkg} &> /dev/null
+
+ Log "dummy package '${dep_pkgname}' created"
+ fi
+ pacman ${OPTS} -Sy&> /dev/null
+}
+
+IsArchRepo() # (repo)
+{
+ local repo=$1 ; [[ "${repo}" =~ ^(community|core|extra|multilib|testing)$ ]]
+}
+
+ListParabolaDependents() # (dep_pkgname)
+{
+ local dep_pkgname=$1
+ local dep_chain pkg repos
+
+# TODO: --chain is a custom pactree feature
+export PATH="/code/pacman-contrib/src:${PATH}"
+
+ Log "searching ...." ; echo ;
+ # TODO: --chain is a custom pactree feature
+ pactree ${OPTS} --sync --reverse --unique --chain ${dep_pkgname} | sort | \
+ while read dep_chain
+ do pkg=$(sed 's|.*<- ||' <<<${dep_chain})
+ repos=$(pacman ${OPTS} -Si ${pkg} | grep Repository | cut -d ':' -f 2)
+
+ for repo in ${REPOS}
+ do if IsArchRepo ${repo}
+ then echo "${repo}/${pkg} (ignoring)" >&2
+ else echo -n "${repo}/${pkg}"
+ (( $BE_VERBOSE )) && echo " [ ${dep_chain} ]" || echo ''
+ fi
done
- done < <(/usr/bin/pactree $CFG --sync --reverse --unique --chain $DEP_PKG) | sort
+ done
+}
+
+Cleanup()
+{
+ if [[ -d "${DB_DIR}" && "${DB_DIR}" =~ parabola-dependents ]]
+ then rm --force --recursive ${DB_DIR} ;
+ fi
}
-ListParabolaDependents $@ || exit 1
+set -o errexit -o errtrace
+trap 'Cleanup' EXIT INT TERM
+trap 'LogError "${BASH_SOURCE[0]}" "${FUNCNAME[0]}" "${LINENO}"' ERR
+
+
+(( $BE_VERBOSE )) && shift || true
+(( ! EUID )) || ! echo -e "${UNPRIVILEGED_MSG}" || false
+(( $# )) || ! echo -e "${INVALID_ARG_MSG}" || false
+
+
+Init $1
+ListParabolaDependents $1
+Cleanup