Update package gathering.

This commit is contained in:
awalsh128 2022-07-19 19:53:44 -07:00
parent f20c69935b
commit 0735dbdc22
2 changed files with 18 additions and 9 deletions

View file

@ -39,21 +39,22 @@ for package in ${normalized_packages}; do
# Comma delimited name:ver pairs in the main requested packages manifest.
manifest_main="${manifest_main}${package_name}:${package_ver},"
all_packages="$(apt-get install --dry-run --yes "${package_name}" | grep "^Inst" | sort | awk '{print $2 $3}' | tr '(' ':')"
dep_packages="$(echo "${all_packages}" | grep -v "${package_name}" | tr '\n' ,)"
if "${dep_packages}" == ","; then
dep_packages="none";
read dep_packages < <(get_dep_packages "${package_name}")
if test -z "${dep_packages}"; then
dep_packages_text="none";
else
dep_packages_text="${dep_packages}"
fi
log "- ${package_name}"
log " * Version: ${package_ver}"
log " * Dependencies: ${dep_packages}"
log " * Dependencies: ${dep_packages_text}"
log " * Installing..."
# Zero interaction while installing or upgrading the system via apt.
sudo DEBIAN_FRONTEND=noninteractive apt-get --yes install "${package}" > /dev/null
sudo DEBIAN_FRONTEND=noninteractive apt-get --yes install "${package_name}" > /dev/null
echo "done."
for cache_package in ${all_packages}; do
for cache_package in ${package_name}:${package_ver} ${dep_packages}; do
cache_filepath="${cache_dir}/${cache_package}.tar.gz"
if test ! -f "${cache_filepath}"; then
@ -65,7 +66,7 @@ for package in ${normalized_packages}; do
if test -f $f || test -L $f; then echo "${f:1}"; fi; #${f:1} removes the leading slash that Tar disallows
done |
xargs tar -czf "${cache_filepath}" -C /
log "done (compressed size $(du -k "${cache_filepath}" | cut -f1))."
log "done (compressed size $(du -h "${cache_filepath}" | cut -f1))."
fi
# Comma delimited name:ver pairs in the all packages manifest.

10
lib.sh
View file

@ -9,9 +9,17 @@ function normalize_package_list {
echo "${sorted}"
}
# Gets a package list of dependencies as common delimited pairs
# <name>:<version>,<name:version>...
function get_dep_packages {
echo $(apt-get install --dry-run --yes "${1}" | \
grep "^Inst" | sort | awk '{print $2 $3}' | \
tr '(' ':' | grep -v "${1}:")
}
# Split fully qualified package into name and version
function get_package_name_ver {
IFS=\= read name ver <<< "${1}"
IFS=\: read name ver <<< "${1}"
# If version not found in the fully qualified package value.
if test -z "${ver}"; then
ver="$(grep "Version:" <<< "$(apt show ${name})" | awk '{print $2}')"