I restrained my own nature and managed to wait a few days before posting ![Smile :)]()
Bash + aptAWK
should work in most common configurations, but a few lines script can't replace everything apt does.I'm now looking forward to a Perl solution that takes advantage of the APT API.

Bash + apt
Code:
#!/usr/bin/env bashDIM="\e[0;37m" LANGSAVE="$LANG" LANG="C" PTRN="${1//[^0-9a-z\-+.]}" RS="\e[0m"declare -a RESULT=()### we assume that apt always adds the APT-Sources: field for real packageswhile IFS='' read -r FIELD; do [[ "$FIELD" != "${FIELD#Package: }" ]] && { PKNAME="${FIELD#Package: }"; continue; } [[ "$FIELD" != "${FIELD#Section: }" ]] && { SECTION="${FIELD#Section: }"; continue; } [[ "$FIELD" != "${FIELD#APT-Sources: }" ]] && { AREA="${FIELD#APT-Sources: }" [[ "$AREA" == *\ * ]] && AREA="${AREA#* }" AREA="${AREA%% *}" continue; } [[ "$FIELD" == "" ]] && { [[ "$AREA" ]] && { [[ "$SECTION" == */* ]] && AREA="$AREA${RS@P}" SECTION="${DIM@P}$SECTION" RESULT+=( "$PKNAME ${SECTION:-NOSECTION} $AREA" ); AREA=""; } SECTION=""; }done < <(apt show "*${PTRN:-firmware}*" 2>/dev/null)printf '%s\n' "${RESULT[@]}" | sort | column -t### sort on AREA - LANG affects sort order#printf '%s\n' "${RESULT[@]}" | LANG="$LANGSAVE" sort -k 3,3 | column -t[[ "${RESULT[*]}" ]] && exit 0 || exit 100
should work in most common configurations, but a few lines script can't replace everything apt does.
Code:
#!/usr/bin/env bashLANG="C" ARCH="$(dpkg --print-architecture)"PTRN="${1//[^0-9a-z\-+.]}" PTRN="${PTRN//\./\\\.}" PTRN="${PTRN//\+/\\\+}"declare -a PKFILESread -d '' -ra PKFILES \ < <(shopt -s extglob compgen -G "/var/lib/apt/lists/*-@($ARCH|all)_Packages")### Package, Version, and Architecture are mandatory. Section is recommended### https://www.debian.org/doc/debian-policy/ch-controlfields.htmlmawk 'BEGIN {es=100} FNR==1{area="LOCAL-"FILENAME if (NR!=1){sub(/^.+_dists_/,"",area) sub(/_binary-.+$/,"",area) gsub(/_/,"/",area); a=1}} FNR==NR{if (/^Architecture: /){if ($2=="'"$ARCH"'" || $2=="all"){a=1} else {a=0}}} /^Package: .*'"${PTRN:-firmware}"'.*/{pk=$2; p=1} /^Version: /{ver=$2} /^Section: /{sec=$2} /^$/{if (p && a){if (sec~"/"){sec="\x1b[0;37m"sec} else if (sec==""){sec="NOSECTION"} print pk,ver,sec,area"\x1b[0m"; es=0} p=0; sec=""} END {exit es}' /var/lib/dpkg/status "${PKFILES[@]}" |\ sort -rV | rev | uniq -f3 | rev | mawk '{print $1,$3,$4}' | sort | column -texit "${PIPESTATUS[0]}"
Statistics: Posted by fabien — 2024-06-14 21:23 — Replies 1 — Views 78