From 64b7d995040fc670aaed5fbd048157b3feba0574 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Fri, 13 Sep 2019 01:32:57 +0200 Subject: zsh_completion: add sogrep completions Transform sogrep into an in-prog so we can benefit from the m4 macro to specify valid repos in a single place of truth. Signed-off-by: Levente Polyak --- .gitignore | 1 + Makefile | 4 +- lib/valid-repos.sh | 31 +++++++++++ sogrep | 149 ----------------------------------------------------- sogrep.in | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++ zsh_completion.in | 11 +++- 6 files changed, 191 insertions(+), 152 deletions(-) create mode 100644 lib/valid-repos.sh delete mode 100755 sogrep create mode 100755 sogrep.in diff --git a/.gitignore b/.gitignore index b63587b..6a1d1e4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ zsh_completion find-libdeps crossrepomove arch-nspawn +sogrep doc/*.1 diff --git a/Makefile b/Makefile index 8d54ed4..82bc4c1 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,12 @@ IN_PROGS = \ crossrepomove\ arch-nspawn \ mkarchroot \ - makechrootpkg + makechrootpkg \ + sogrep BINPROGS = \ $(IN_PROGS) \ offload-build \ - sogrep CONFIGFILES = \ makepkg-x86_64.conf \ diff --git a/lib/valid-repos.sh b/lib/valid-repos.sh new file mode 100644 index 0000000..252fdcf --- /dev/null +++ b/lib/valid-repos.sh @@ -0,0 +1,31 @@ +#!/hint/bash +# License: Unspecified +: + +# shellcheck disable=2034 +_repos=( + staging + testing + core + extra + community-staging + community-testing + community + multilib-staging + multilib-testing + multilib + gnome-unstable + kde-unstable +) + +# shellcheck disable=2034 +_build_repos=( + staging + testing + extra + multilib-staging + multilib-testing + multilib + gnome-unstable + kde-unstable +) diff --git a/sogrep b/sogrep deleted file mode 100755 index 56a0e70..0000000 --- a/sogrep +++ /dev/null @@ -1,149 +0,0 @@ -#!/bin/bash -# -# sogrep - find shared library links in an Arch Linux repository. -# -# Copyright (c) 2019 by Eli Schwartz -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -# globals -: ${SOLINKS_MIRROR:="https://mirror.pkgbuild.com"} -: ${SOCACHE_DIR:="${XDG_CACHE_HOME:-${HOME}/.cache}/sogrep"} -repos=('staging' 'testing' 'core' 'extra' - 'community-staging' 'community-testing' 'community' - 'multilib-staging' 'multilib-testing' 'multilib' - 'gnome-unstable' 'kde-unstable') -arches=('x86_64') - -# options -REFRESH=0 -VERBOSE=0 - -source /usr/share/makepkg/util/parseopts.sh -source /usr/share/makepkg/util/util.sh - -recache() { - local repo arch verbosity=-s - - (( VERBOSE )) && verbosity=--progress-bar - - for repo in "${repos[@]}"; do - for arch in "${arches[@]}"; do - rm -rf "${SOCACHE_DIR}/${arch}/${repo}" - mkdir -p "${SOCACHE_DIR}/${arch}/${repo}" - curl "$verbosity" "${SOLINKS_MIRROR}/${repo}/os/${arch}/${repo}.links.tar.gz" | bsdtar -xf - -C "${SOCACHE_DIR}/${arch}/${repo}" - done - done -} - -search() { - local repo=$1 arch lib=$2 srepos=("${repos[@]}") - - if [[ $repo != all ]]; then - if ! in_array "${repo}" "${repos[@]}"; then - echo "${BASH_SOURCE[0]##*/}: unrecognized repo '$repo'" - echo "Try '${BASH_SOURCE[0]##*/} --help' for more information." - exit 1 - fi - srepos=("${repo}") - fi - - for arch in "${arches[@]}"; do - for repo in "${srepos[@]}"; do - local prefix= - (( VERBOSE && ${#srepos[@]} > 1 )) && prefix=${repo}/ - db=${SOCACHE_DIR}/${arch}/${repo}/ - if [[ -d ${db} ]]; then - while read -rd '' pkg; do - read -r match - pkg=${pkg#${db}} - pkg="${prefix}${pkg%-*-*/links}" - - if (( VERBOSE )); then - printf '%-35s %s\n' "${pkg}" "${match}" - else - printf '%s\n' "${pkg}" - fi - done < <(grep -rZ "${lib}" "${db}") | sort -u - fi - done - done | resort -} - -usage() { - cat <<- _EOF_ - Usage: ${BASH_SOURCE[0]##*/} [OPTIONS] REPO LIBNAME - - Check the soname links database for Arch Linux repositories containing - packages linked to a given shared library. If the repository specified - is "all", then all repositories will be searched, otherwise only the - named repository will be searched. - - If the links database does not exist, it will be downloaded first. - - OPTIONS - -v, --verbose Show matched links in addition to pkgname - -r, --refresh Refresh the links databases - -h, --help Show this help text -_EOF_ -} - -# utility function to resort with multiple repos + no-verbose -resort() { sort -u; } - -if (( $# == 0 )); then - echo "error: No arguments passed." - echo "Try '${BASH_SOURCE[0]##*/} --help' for more information." - exit 1 -fi -OPT_SHORT='vrh' -OPT_LONG=('verbose' 'refresh' 'help') -if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then - exit 1 -fi -set -- "${OPTRET[@]}" - -while :; do - case $1 in - -v|--verbose) - resort() { cat; } - VERBOSE=1 - ;; - -r|--refresh) - REFRESH=1 - ;; - -h|--help) - usage - exit 0 - ;; - --) - shift; break - ;; - esac - shift -done - -if ! (( ( REFRESH && $# == 0 ) || $# == 2 )); then - echo "error: Incorrect number of arguments passed." - echo "Try '${BASH_SOURCE[0]##*/} --help' for more information." - exit 1 -fi - -if (( REFRESH )) || [[ ! -d ${SOCACHE_DIR} ]]; then - recache - (( $# == 2 )) || exit 0 -fi - -search "$@" diff --git a/sogrep.in b/sogrep.in new file mode 100755 index 0000000..055c61f --- /dev/null +++ b/sogrep.in @@ -0,0 +1,147 @@ +#!/bin/bash +# +# sogrep - find shared library links in an Arch Linux repository. +# +# Copyright (c) 2019 by Eli Schwartz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# globals +: ${SOLINKS_MIRROR:="https://mirror.pkgbuild.com"} +: ${SOCACHE_DIR:="${XDG_CACHE_HOME:-${HOME}/.cache}/sogrep"} + +m4_include(lib/valid-repos.sh) +arches=('x86_64') + +# options +REFRESH=0 +VERBOSE=0 + +source /usr/share/makepkg/util/parseopts.sh +source /usr/share/makepkg/util/util.sh + +recache() { + local repo arch verbosity=-s + + (( VERBOSE )) && verbosity=--progress-bar + + for repo in "${_repos[@]}"; do + for arch in "${arches[@]}"; do + rm -rf "${SOCACHE_DIR}/${arch}/${repo}" + mkdir -p "${SOCACHE_DIR}/${arch}/${repo}" + curl "$verbosity" "${SOLINKS_MIRROR}/${repo}/os/${arch}/${repo}.links.tar.gz" | bsdtar -xf - -C "${SOCACHE_DIR}/${arch}/${repo}" + done + done +} + +search() { + local repo=$1 arch lib=$2 srepos=("${_repos[@]}") + + if [[ $repo != all ]]; then + if ! in_array "${repo}" "${_repos[@]}"; then + echo "${BASH_SOURCE[0]##*/}: unrecognized repo '$repo'" + echo "Try '${BASH_SOURCE[0]##*/} --help' for more information." + exit 1 + fi + srepos=("${repo}") + fi + + for arch in "${arches[@]}"; do + for repo in "${srepos[@]}"; do + local prefix= + (( VERBOSE && ${#srepos[@]} > 1 )) && prefix=${repo}/ + db=${SOCACHE_DIR}/${arch}/${repo}/ + if [[ -d ${db} ]]; then + while read -rd '' pkg; do + read -r match + pkg=${pkg#${db}} + pkg="${prefix}${pkg%-*-*/links}" + + if (( VERBOSE )); then + printf '%-35s %s\n' "${pkg}" "${match}" + else + printf '%s\n' "${pkg}" + fi + done < <(grep -rZ "${lib}" "${db}") | sort -u + fi + done + done | resort +} + +usage() { + cat <<- _EOF_ + Usage: ${BASH_SOURCE[0]##*/} [OPTIONS] REPO LIBNAME + + Check the soname links database for Arch Linux repositories containing + packages linked to a given shared library. If the repository specified + is "all", then all repositories will be searched, otherwise only the + named repository will be searched. + + If the links database does not exist, it will be downloaded first. + + OPTIONS + -v, --verbose Show matched links in addition to pkgname + -r, --refresh Refresh the links databases + -h, --help Show this help text +_EOF_ +} + +# utility function to resort with multiple repos + no-verbose +resort() { sort -u; } + +if (( $# == 0 )); then + echo "error: No arguments passed." + echo "Try '${BASH_SOURCE[0]##*/} --help' for more information." + exit 1 +fi +OPT_SHORT='vrh' +OPT_LONG=('verbose' 'refresh' 'help') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + exit 1 +fi +set -- "${OPTRET[@]}" + +while :; do + case $1 in + -v|--verbose) + resort() { cat; } + VERBOSE=1 + ;; + -r|--refresh) + REFRESH=1 + ;; + -h|--help) + usage + exit 0 + ;; + --) + shift; break + ;; + esac + shift +done + +if ! (( ( REFRESH && $# == 0 ) || $# == 2 )); then + echo "error: Incorrect number of arguments passed." + echo "Try '${BASH_SOURCE[0]##*/} --help' for more information." + exit 1 +fi + +if (( REFRESH )) || [[ ! -d ${SOCACHE_DIR} ]]; then + recache + (( $# == 2 )) || exit 0 +fi + +search "$@" diff --git a/zsh_completion.in b/zsh_completion.in index 78330ea..72dbfa3 100644 --- a/zsh_completion.in +++ b/zsh_completion.in @@ -1,7 +1,8 @@ -#compdef archbuild archco arch-nspawn archrelease commitpkg finddeps makechrootpkg mkarchroot rebuildpkgs extrapkg=commitpkg corepkg=commitpkg testingpkg=commitpkg stagingpkg=commitpkg communitypkg=commitpkg community-testingpkg=commitpkg community-stagingpkg=commitpkg multilibpkg=commitpkg multilib-testingpkg=commitpkg extra-x86_64-build=archbuild testing-x86_64-build=archbuild staging-x86_64-build=archbuild multilib-build=archbuild multilib-testing-build=archbuild multilib-staging-build=archbuild kde-unstable-x86_64-build=archbuild gnome-unstable-x86_64-build=archbuild communityco=archco checkpkg +#compdef archbuild archco arch-nspawn archrelease commitpkg finddeps makechrootpkg mkarchroot rebuildpkgs extrapkg=commitpkg corepkg=commitpkg testingpkg=commitpkg stagingpkg=commitpkg communitypkg=commitpkg community-testingpkg=commitpkg community-stagingpkg=commitpkg multilibpkg=commitpkg multilib-testingpkg=commitpkg extra-x86_64-build=archbuild testing-x86_64-build=archbuild staging-x86_64-build=archbuild multilib-build=archbuild multilib-testing-build=archbuild multilib-staging-build=archbuild kde-unstable-x86_64-build=archbuild gnome-unstable-x86_64-build=archbuild communityco=archco checkpkg sogrep # License: Unspecified m4_include(lib/valid-tags.sh) +m4_include(lib/valid-repos.sh) _archbuild_args=( '-c[Recreate the chroot before building]' @@ -74,6 +75,14 @@ _checkpkg_args=( '(-h --help)'{-h,--help}'[Display usage]' ) +_sogrep_args=( + '(-v --verbose)'{-v,--verbose}'[Show matched links in addition to pkgname]' + '(-r --refresh)'{-r,--refresh}'[Refresh the links databases]' + '(-h --help)'{-h,--help}'[Display usage]' + '1:repo:(all $_repos[*])' + '2:libname' +) + _devtools_completions_all_packages() { typeset -U packages packages=($(_call_program packages pacman -Sql)) -- cgit v1.2.3-70-g09d2