Fix literal quotes and make variables use best practice.

This commit is contained in:
awalsh128 2022-06-03 21:51:44 -07:00
parent 6fe1db8111
commit 4d55f8a4fb
2 changed files with 15 additions and 11 deletions

4
lib.sh
View file

@ -2,9 +2,9 @@
# Sort these packages by name and split on commas. # Sort these packages by name and split on commas.
function normalize_package_list { 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. # 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 echo "${trimmed}" | sort
} }

View file

@ -5,10 +5,10 @@ script_dir="$(dirname -- "$(realpath -- "${0}")")"
source "${script_dir}/lib.sh" source "${script_dir}/lib.sh"
# Directory that holds the cached packages. # Directory that holds the cached packages.
cache_dir=$1 cache_dir="${1}"
# Version of the cache to create or load. # Version of the cache to create or load.
version=$2 cache_version="${2}"
# List of the packages to use. # List of the packages to use.
input_packages="${@:3}" input_packages="${@:3}"
@ -17,12 +17,12 @@ input_packages="${@:3}"
packages="$(normalize_package_list "${input_packages}")" packages="$(normalize_package_list "${input_packages}")"
# Create cache directory so artifacts can be saved. # 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 if grep -q " " <<< "${cache_version}"; then
echo "aborted." echo "aborted."
echo "Version value '$version' cannot contain spaces." >&2 echo "Version value '${cache_version}' cannot contain spaces." >&2
exit 1 exit 1
fi fi
@ -34,12 +34,16 @@ if test -z "${packages}"; then
fi fi
echo "done." echo "done."
echo -n "Updating APT package list..."
sudo apt-get update > /dev/null
echo "done."
versioned_packages="" versioned_packages=""
echo -n "Verifying packages..." echo -n "Verifying packages..."
for package in ${packages}; do for package in ${packages}; do
if test ! "$(apt show "${package}")"; then if test ! "$(apt show "${package}")"; then
echo "aborted." echo "aborted."
echo "Package '$package' not found." >&2 echo "Package '${package}' not found." >&2
exit 3 exit 3
fi fi
get_package_name_ver "${package}" # -> package_name, package_ver get_package_name_ver "${package}" # -> package_name, package_ver
@ -64,6 +68,6 @@ echo "- Value hashed as '${key}'."
echo "done." echo "done."
key_filepath="$cache_dir/cache_key.md5" key_filepath="${cache_dir}/cache_key.md5"
echo $key > $key_filepath echo "${key}" > "${key_filepath}"
echo "Hash value written to $key_filepath" echo "Hash value written to ${key_filepath}"