Experiment with new Go code for package formatting.

This commit is contained in:
Andrew Walsh 2023-11-26 20:33:25 -08:00
parent 3b5900ec5a
commit 587ece84f2

52
lib.sh
View file

@ -99,57 +99,11 @@ function get_normalized_package_list {
# Remove commas, and block scalar folded backslashes, # Remove commas, and block scalar folded backslashes,
# extraneous spaces at the middle, beginning and end # extraneous spaces at the middle, beginning and end
# then sort. # then sort.
packages=$(echo "${1}" \ local packages=$(echo "${1}" \
| sed 's/[,\]/ /g; s/\s\+/ /g; s/^\s\+//g; s/\s\+$//g' \ | sed 's/[,\]/ /g; s/\s\+/ /g; s/^\s\+//g; s/\s\+$//g' \
| sort -t' ') | sort -t' ')
local script_dir="$(dirname -- "$(realpath -- "${0}")")"
# Validate package names and get versions. go ${script_dir}/apt_query.go normalized-list ${packages}
log_err "resolving package versions..."
data=$(apt-cache --quiet=0 --no-all-versions show ${packages} 2>&1 | \
grep -E '^(Package|Version|N):')
log_err "resolved"
local ORIG_IFS="${IFS}"
IFS=$'\n'
declare -A missing
local package_versions=''
local package='' separator=''
for key_value in ${data}; do
local key="${key_value%%: *}"
local value="${key_value##*: }"
case $key in
Package)
package=$value
;;
Version)
package_versions="${package_versions}${separator}"${package}=${value}""
separator=' '
;;
N)
# Warning messages.
case $value in
'Unable to locate package '*)
package="${value#'Unable to locate package '}"
# Avoid duplicate messages.
if [ -z "${missing[$package]}" ]; then
package="${value#'Unable to locate package '}"
log_err "Package '${package}' not found."
missing[$package]=1
fi
;;
esac
;;
esac
done
IFS="${ORIG_IFS}"
if [ ${#missing[@]} -gt 0 ]; then
echo "aborted"
exit 5
fi
echo "${package_versions}"
} }
############################################################################### ###############################################################################