#!/bin/bash # packages-by - list all packages in the repos, published by a specifed hacker # # Copyright (C) 2020 bill-auger # # SPDX-License-Identifier: AGPL-3.0-or-later # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 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 Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # # NOTE: you should install 'pacman-all.conf' to /etc readonly DEBUG=0 readonly PACMAN_CONF_FILE=/etc/pacman-all.conf readonly USAGE="USAGE:\n\tpackages-by [-d] [-n] \n\nDESCRIPTION:\n\t will be matched against expac output lines of the form:\n\t\tPKGNAME ARCH/REPO YYYY-MM-DD-HH:MM PACKAGER_NAME BASE64_SIG\n\nOPTIONS:\n\t-d -> sort by date\n\t-n -> show usage help" readonly EXPAC_TIME_FMT='%Y-%m-%d-%R' readonly EXPAC_FMT='%n %a/%r %b %p %g' readonly KEYID_SED_CMD='s|.*([0-9A-F]{40})\)$|\1|p ; d' # convenience lookup dict (login->email) # TODO: incomplete declare -r -A HACKERS_EMAILS=( [bill-auger]='bill-auger@peers.community' \ [oaken-source]='andreas@grapentin.org' ) # collect CLI options SHOULD_SORT=0 while getopts 'dh' opt do case ${opt} in d) SHOULD_SORT=1 ;; h) echo -e "${USAGE}" ;; *) echo -e "Invalid argument\n${USAGE}" ; exit 1 ;; esac done shift $(( OPTIND - 1 )) readonly SHOULD_SORT readonly HACKER_EMAIL=${HACKERS_EMAILS[$*]} readonly SORT_CMD=$( (( SHOULD_SORT )) && echo 'sort --key=3' || echo 'cat' ) readonly TERM="$( [[ -n "${HACKER_EMAIL}" ]] && echo ${HACKER_EMAIL} || echo "$@" )" [[ -z "${TERM}" ]] && echo -e "${USAGE}" && exit 1 ; DBG() { (( DEBUG )) && echo -e "$dbg" >&2 ; } DBG "SHOULD_SORT=$SHOULD_SORT\nTERM=$TERM" # collect results expac -S --config ${PACMAN_CONF_FILE} --timefmt="${EXPAC_TIME_FMT}" "${EXPAC_FMT}" | \ grep -E "${TERM}" | column -t | ${SORT_CMD} | \ while read pkg_data_raw do pkg_data=$( sed -E 's|(.+) <.*|\1|' <<<${pkg_data_raw} ) email=$( sed -E 's|.+ <([^>]*)>.*|\1|' <<<${pkg_data_raw} ) sig=$( sed -E 's|.+ ([^ ]+)|\1|' <<<${pkg_data_raw} ) key_id=$( base64 --decode <<<${sig} | gpg --list-packets | sed -E "${KEYID_SED_CMD}" ) echo "${pkg_data} <${email}> [${key_id}]" DBG "pkg_data=$pkg_data\nemail=$email\nsig=$sig\nkey_id=$key_id" ; (( DEBUG )) && break ; done | tee >(echo "($(wc -l)) packages")