From 4d55f8a4fb2ddd13371e80d5a218b93f87493054 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Fri, 3 Jun 2022 21:51:44 -0700 Subject: [PATCH] Fix literal quotes and make variables use best practice. --- lib.sh | 4 ++-- pre_cache_action.sh | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib.sh b/lib.sh index 063492a..9e52157 100755 --- a/lib.sh +++ b/lib.sh @@ -2,9 +2,9 @@ # Sort these packages by name and split on commas. function normalize_package_list { - stripped="$(echo \"${1}\" | sed 's/,//g')" + stripped="$(echo ${1} | sed 's/,//g')" # Remove extraneous spaces at the middle, beginning, and end. - trimmed="$(echo \"${stripped}\" | sed 's/\s\+/ /g; s/^\s\+//g; s/\s\+$//g')" + trimmed="$(echo ${stripped} | sed 's/\s\+/ /g; s/^\s\+//g; s/\s\+$//g')" echo "${trimmed}" | sort } diff --git a/pre_cache_action.sh b/pre_cache_action.sh index 7c03802..70f3f87 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 +cache_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='${cache_version}', packages='${packages}')..."; if grep -q " " <<< "${cache_version}"; then echo "aborted." - echo "Version value '$version' cannot contain spaces." >&2 + echo "Version value '${cache_version}' cannot contain spaces." >&2 exit 1 fi @@ -34,12 +34,16 @@ if test -z "${packages}"; then fi echo "done." +echo -n "Updating APT package list..." +sudo apt-get update > /dev/null +echo "done." + versioned_packages="" 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 +68,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}"