changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra > home / .stash/scripts/pacman-pkgsearch.sh

changeset 49: f3c32ffdbbef
parent: 953c5127546a
author: Richard Westhaver <ellis@rwest.io>
date: Thu, 20 Jun 2024 22:29:29 -0400
permissions: -rwxr-xr-x
description: publish-dir remote
1 #!/bin/bash
2 
3 # SPDX-License-Identifier: GPL-2.0
4 
5 set -o errexit
6 shopt -s extglob
7 
8 help(){
9  cat << EOF
10 Usage:
11  $PROGRAM
12 Flags:
13  -m [maintainer] find packages from maintainer
14  -p [packager] find packages from the last packager
15  -q local packages
16  -s print the package maintainers
17  -l [limit] co-maintainer limit to filter on default: 1
18  -f [repository] filter on repository, Default: core extra multilib community
19  -o list flagged packages
20  -n use pkgname instead of pkgbase (not recommended as we sort away split pkgs)
21  -h help messages
22 Example:
23  Packages from a maintainer with 2 maintainers
24  $ pkgsearch -m Foxboron -l 2
25  Orphaned packages in [extra]
26  $ pkgsearch -f extra -l 0 -m orphan
27  Packages installed on the system from [core] with 1 maintainer
28  $ pkgsearch -q -f core -l 1
29  Locally installed packages from [community], orphaned, and flagged out-of-date
30  $ pkgsearch -q -f community -l 0 -m orphan -o
31 EOF
32 }
33 
34 
35 limit_maintainers=1
36 see_maintainers=0
37 out_of_date=""
38 name=".pkgbase"
39 filter=()
40 
41 while true; do
42  case "$1" in
43  -m) shift; maintainer_query="maintainer=$1" ;;
44  -p) shift; packager_query="&packager=$1" ;;
45  -q) local_packages=1;;
46  -s) see_maintainers=1;;
47  -l) shift; limit_maintainers=$1;;
48  -f) shift; filter+=("${1,,}");;
49  -o) out_of_date="Flagged";;
50  -n) name=".pkgname";;
51  -h) help;;
52  "") break;;
53  esac
54  shift
55 done
56 
57 find_packages(){
58  test ${#filter} -eq 0 && filter=(core extra community multilib)
59  if ((local_packages)); then
60  # shellcheck disable=SC2046
61  expac -S "%r %a %n %e" $(expac %n) | grep -P "^($(tr ' ' '|' <<< "${filter[*]}")) "
62  else
63  filter=("${filter[@]^}") # Uppercase the repo names
64  filter=("${filter[@]/#/&repo=}") # Prepend &repo= to all elements
65  query="?${maintainer_query}${packager_query}$(printf "%s" "${filter[@]}")&flagged=$out_of_date"
66  curl -s "https://archlinux.org/packages/search/json/$query" \
67  | jq -r '.results[] | "\(.repo) \(.arch) \(.pkgname) \(.pkgbase)"' | sort | uniq
68  fi
69 }
70 
71 while read -r repo arch pkg _; do
72  # shellcheck disable=SC2016
73  format="select(.maintainers | length == \$LIMIT) | \"\(${name})\""
74  if ((see_maintainers)); then
75  # shellcheck disable=SC2016
76  format="select(.maintainers | length == \$LIMIT) | \"\(${name})\", (.maintainers | join(\" \"))"
77  fi
78  curl -s "https://archlinux.org/packages/$repo/$arch/$pkg/json/" | \
79  jq -r --argjson LIMIT "$limit_maintainers" "$format"
80 done <<< "$(find_packages | sort -u -k4,4)"