From 08d1b8537048cab50c1670644de0dc4e6f44ece7 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 21:45:24 -0700 Subject: [PATCH] Add better diagnostics. --- install_and_cache_pkgs.sh | 8 +++++++- restore_pkgs.sh | 24 +++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index 37fda4f..9d68cf8 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -8,6 +8,12 @@ cache_dir=$1 # List of the packages to use. packages="${@:2}" +package_count=$(echo $packages | wc -w) +echo "* Clean installing $package_count packages..." +for package in $packages; do + echo " - $package" +done + mkdir -p $cache_dir for package in $packages; do cache_filepath=$cache_dir/$package.tar.gz @@ -24,4 +30,4 @@ for package in $packages; do xargs tar -czf $cache_filepath -C / done -echo "Action complete. ${#packages[@]} package(s) installed and cached." +echo "Action complete. $(echo $packages | wc -w) package(s) installed and cached." diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 2e61d70..9f151e6 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -8,17 +8,23 @@ cache_dir=$1 # Root directory to untar the cached packages to. # Typically filesystem root '/' but can be changed for testing. cache_restore_root=$2 +# List of the packages to use. +packages="${@:3}" cache_filenames=$(ls -1 $cache_dir | sort) -echo "* Found ${#cache_filenames[@]} files in cache..." -echo $cache_filenames - +cache_filename_count=$(echo $cache_filenames | wc -w) +echo "* Found $cache_filename_count files in cache..." for cache_filename in $cache_filenames; do - cache_filepath=$cache_dir/$cache_filename - echo "* Restoring $cache_filepath from cache... " - sudo tar -xf $cache_filepath -C $cache_restore_root + echo " - $cache_filename" done -# Update all packages. -sudo apt-get --yes --only-upgrade install -echo "Action complete. $(echo $cache_filenames | wc -l) package(s) restored." +for package in $packages; do + cache_filepath=$cache_dir/$package.tar.gz + echo "* Restoring package $package ($cache_filepath) from cache... " + sudo tar -xf $cache_filepath -C $cache_restore_root + # Upgrade the install from last state. + # TODO(awalsh128) Add versioning to cache key creation. + sudo apt-get --yes --only-upgrade install $package +done + +echo "Action complete. $cache_filename_count package(s) restored."