2021-10-21 20:57:52 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-11-24 08:59:56 -08:00
|
|
|
set -e
|
|
|
|
|
|
|
|
# Include library.
|
|
|
|
script_dir="$(dirname -- "$(realpath -- "${0}")")"
|
|
|
|
source "${script_dir}/lib.sh"
|
|
|
|
|
2022-11-23 22:24:00 -08:00
|
|
|
# Debug mode for diagnosing issues.
|
|
|
|
# Setup first before other operations.
|
|
|
|
debug="${4}"
|
|
|
|
validate_bool "${debug}" debug 1
|
|
|
|
test ${debug} == "true" && set -x
|
|
|
|
|
2021-10-21 20:57:52 -07:00
|
|
|
# Directory that holds the cached packages.
|
2022-06-03 21:51:44 -07:00
|
|
|
cache_dir="${1}"
|
2021-10-21 20:57:52 -07:00
|
|
|
|
|
|
|
# Version of the cache to create or load.
|
2022-07-19 20:42:48 -07:00
|
|
|
version="${2}"
|
2021-10-21 20:57:52 -07:00
|
|
|
|
2022-11-23 22:24:00 -08:00
|
|
|
# Execute post-installation script.
|
|
|
|
execute_install_scripts="${3}"
|
|
|
|
|
|
|
|
# Debug mode for diagnosing issues.
|
|
|
|
debug="${4}"
|
|
|
|
|
2021-10-21 20:57:52 -07:00
|
|
|
# List of the packages to use.
|
2022-11-23 22:24:00 -08:00
|
|
|
input_packages="${@:5}"
|
2022-03-16 10:15:25 -07:00
|
|
|
|
2022-03-26 12:42:40 -07:00
|
|
|
# Trim commas, excess spaces, and sort.
|
2023-12-22 10:28:03 -08:00
|
|
|
log "Normalizing package list..."
|
2023-03-23 20:50:29 -07:00
|
|
|
packages="$(get_normalized_package_list "${input_packages}")"
|
2023-12-22 10:28:03 -08:00
|
|
|
log "done"
|
2021-10-21 20:57:52 -07:00
|
|
|
|
2021-10-21 21:12:42 -07:00
|
|
|
# Create cache directory so artifacts can be saved.
|
2022-07-19 20:42:48 -07:00
|
|
|
mkdir -p ${cache_dir}
|
2021-10-21 21:12:42 -07:00
|
|
|
|
2022-08-02 21:14:51 -07:00
|
|
|
log "Validating action arguments (version='${version}', packages='${packages}')...";
|
2022-07-19 20:42:48 -07:00
|
|
|
if grep -q " " <<< "${version}"; then
|
2022-07-23 17:06:17 -07:00
|
|
|
log "aborted"
|
2022-07-19 20:42:48 -07:00
|
|
|
log "Version value '${version}' cannot contain spaces." >&2
|
2022-11-23 22:24:00 -08:00
|
|
|
exit 2
|
2021-10-21 20:57:52 -07:00
|
|
|
fi
|
2022-06-03 21:04:43 -07:00
|
|
|
|
2022-03-26 12:42:40 -07:00
|
|
|
# Is length of string zero?
|
|
|
|
if test -z "${packages}"; then
|
2022-07-23 17:06:17 -07:00
|
|
|
log "aborted"
|
2022-07-19 20:42:48 -07:00
|
|
|
log "Packages argument cannot be empty." >&2
|
2022-11-23 22:24:00 -08:00
|
|
|
exit 3
|
2021-10-21 20:57:52 -07:00
|
|
|
fi
|
2022-08-02 21:14:51 -07:00
|
|
|
|
2022-11-23 22:24:00 -08:00
|
|
|
validate_bool "${execute_install_scripts}" execute_install_scripts 4
|
|
|
|
|
2022-08-02 21:14:51 -07:00
|
|
|
log "done"
|
|
|
|
|
|
|
|
log_empty_line
|
|
|
|
|
2021-10-21 20:57:52 -07:00
|
|
|
# Abort on any failure at this point.
|
|
|
|
set -e
|
|
|
|
|
2022-07-19 20:42:48 -07:00
|
|
|
log "Creating cache key..."
|
2021-10-21 20:57:52 -07:00
|
|
|
|
2023-02-03 12:42:50 -08:00
|
|
|
# Forces an update in cases where an accidental breaking change was introduced
|
|
|
|
# and a global cache reset is required.
|
2023-03-23 22:19:43 -07:00
|
|
|
force_update_inc="1"
|
2023-02-03 12:42:50 -08:00
|
|
|
|
2023-10-11 08:07:11 -07:00
|
|
|
value="${packages} @ ${version} ${force_update_inc}"
|
2022-07-19 20:42:48 -07:00
|
|
|
log "- Value to hash is '${value}'."
|
2021-10-21 20:57:52 -07:00
|
|
|
|
2022-07-20 10:58:33 -07:00
|
|
|
key="$(echo "${value}" | md5sum | cut -f1 -d' ')"
|
2022-07-19 20:42:48 -07:00
|
|
|
log "- Value hashed as '${key}'."
|
2021-10-21 20:57:52 -07:00
|
|
|
|
2022-07-23 17:06:17 -07:00
|
|
|
log "done"
|
2021-10-21 20:57:52 -07:00
|
|
|
|
2022-06-03 21:51:44 -07:00
|
|
|
key_filepath="${cache_dir}/cache_key.md5"
|
2022-07-19 20:42:48 -07:00
|
|
|
echo ${key} > ${key_filepath}
|
|
|
|
log "Hash value written to ${key_filepath}"
|