diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index e4f6c2c..f3cdfe5 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -8,7 +8,7 @@ script_dir="$(dirname -- "$(realpath -- "${0}")")" source "${script_dir}/lib.sh" # Directory that holds the cached packages. -cache_dir=$1 +cache_dir="${1}" # List of the packages to use. input_packages="${@:2}" diff --git a/lib.sh b/lib.sh old mode 100644 new mode 100755 index 3802483..2a31aac --- a/lib.sh +++ b/lib.sh @@ -17,7 +17,3 @@ function get_package_name_ver { fi echo 'package_name="${name}"; package_ver="${ver}"' } - -function blah { - > /dev/null 2>&1 -} \ No newline at end of file diff --git a/post_cache_action.sh b/post_cache_action.sh index 5503013..56fda54 100755 --- a/post_cache_action.sh +++ b/post_cache_action.sh @@ -4,23 +4,23 @@ set -e # Directory that holds the cached packages. -cache_dir=$1 +cache_dir="${1}" # Root directory to untar the cached packages to. # Typically filesystem root '/' but can be changed for testing. -cache_restore_root=$2 +cache_restore_root="${2}" # Indicates that the cache was found. -cache_hit=$3 +cache_hit="${3}" # List of the packages to use. packages="${@:4}" -script_dir=$(dirname $0) +script_dir="$(dirname -- "$(realpath -- "${0}")")" if [ "$cache_hit" == true ]; then - $script_dir/restore_pkgs.sh ~/cache-apt-pkgs $cache_restore_root + ${script_dir}/restore_pkgs.sh ~/cache-apt-pkgs ${cache_restore_root} else - $script_dir/install_and_cache_pkgs.sh ~/cache-apt-pkgs $packages + ${script_dir}/install_and_cache_pkgs.sh ~/cache-apt-pkgs ${packages} fi echo "" diff --git a/pre_cache_action.sh b/pre_cache_action.sh index 05d2fbe..4bd63d4 100755 --- a/pre_cache_action.sh +++ b/pre_cache_action.sh @@ -5,10 +5,10 @@ script_dir="$(dirname -- "$(realpath -- "${0}")")" source "${script_dir}/lib.sh" # Directory that holds the cached packages. -cache_dir=$1 +cache_dir=${1} # Version of the cache to create or load. -version=$2 +version=${2} # List of the packages to use. input_packages="${@:3}" @@ -17,12 +17,12 @@ input_packages="${@:3}" packages="$(normalize_package_list "${input_packages}")" # Create cache directory so artifacts can be saved. -mkdir -p $cache_dir +mkdir -p ${cache_dir} -echo -n "Validating action arguments (version='$version', packages='$packages')..."; +echo -n "Validating action arguments (version='${version}', packages='${packages}')..."; if grep -q " " <<< "${cache_version}"; then echo "aborted." - echo "Version value '$version' cannot contain spaces." >&2 + echo "Version value '${version}' cannot contain spaces." >&2 exit 1 fi @@ -39,7 +39,7 @@ echo -n "Verifying packages..." for package in ${packages}; do if test ! "$(apt show "${package}")"; then echo "aborted." - echo "Package '$package' not found." >&2 + echo "Package '${package}' not found." >&2 exit 3 fi get_package_name_ver "${package}" # -> package_name, package_ver @@ -64,6 +64,6 @@ echo "- Value hashed as '${key}'." echo "done." -key_filepath="$cache_dir/cache_key.md5" -echo $key > $key_filepath -echo "Hash value written to $key_filepath" +key_filepath="${cache_dir}/cache_key.md5" +echo ${key} > ${key_filepath} +echo "Hash value written to ${key_filepath}" diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 4c710f3..3cee703 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -4,16 +4,16 @@ set -e # Directory that holds the cached packages. -cache_dir=$1 +cache_dir="${1}" # Root directory to untar the cached packages to. # Typically filesystem root '/' but can be changed for testing. -cache_restore_root=$2 +cache_restore_root="${2}" -cache_filepaths=$(ls -1 $cache_dir | sort) -echo "Found $(echo $cache_filepaths | wc -w) files in the cache." -for cache_filepath in $cache_filepaths; do - echo "- $(basename $cache_filepath)" +cache_filepaths=$(ls -1 ${cache_dir} | sort) +echo "Found $(echo ${cache_filepaths} | wc -w) files in the cache." +for cache_filepath in ${cache_filepaths}; do + echo "- $(basename ${cache_filepath})" done echo "Reading from manifest..." @@ -23,12 +23,12 @@ done echo "done." # Only search for archived results. Manifest and cache key also live here. -cache_pkg_filepaths=$(ls -1 $cache_dir/*.tar.gz | sort) -cache_pkg_filecount=$(echo $cache_pkg_filepaths | wc -w) -echo "Restoring $cache_pkg_filecount packages from cache..." -for cache_pkg_filepath in $cache_pkg_filepaths; do - echo -n "- $(basename $cache_pkg_filepath) restoring..." - sudo tar -xf $cache_pkg_filepath -C $cache_restore_root > /dev/null +cache_pkg_filepaths=$(ls -1 ${cache_dir}/*.tar.gz | sort) +cache_pkg_filecount=$(echo ${cache_pkg_filepaths} | wc -w) +echo "Restoring ${cache_pkg_filecount} packages from cache..." +for cache_pkg_filepath in ${cache_pkg_filepaths}; do + echo -n "- $(basename ${cache_pkg_filepath}) restoring..." + sudo tar -xf ${cache_pkg_filepath} -C ${cache_restore_root} > /dev/null echo "done." done echo "done."