From f7b89333d6f265bcd37cf611cc4a61824c626226 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Tue, 19 Jul 2022 20:02:22 -0700 Subject: [PATCH] Copy from master to staging. --- action.yml | 2 +- install_and_cache_pkgs.sh | 17 +++++++++-------- lib.sh | 10 +++++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index c20f70a..9cd2164 100644 --- a/action.yml +++ b/action.yml @@ -45,7 +45,7 @@ runs: shell: bash - id: load-cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/cache-apt-pkgs key: cache-apt-pkgs_${{ env.CACHE_KEY }} diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index 2c22fb2..1d420b2 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -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" | awk '{print $2}')" - 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. diff --git a/lib.sh b/lib.sh index f3757c9..fc8eb1e 100755 --- a/lib.sh +++ b/lib.sh @@ -9,9 +9,17 @@ function normalize_package_list { echo "${sorted}" } +# Gets a package list of dependencies as common delimited pairs +# :,... +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}')"