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