2022-03-26 12:42:40 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Sort these packages by name and split on commas.
|
|
|
|
function normalize_package_list {
|
2022-07-14 21:44:35 -07:00
|
|
|
local stripped=$(echo "${1}" | sed 's/,//g')
|
2022-03-26 12:42:40 -07:00
|
|
|
# Remove extraneous spaces at the middle, beginning, and end.
|
2022-07-14 21:57:20 -07:00
|
|
|
local trimmed="$(echo "${stripped}" | sed 's/\s\+/ /g; s/^\s\+//g; s/\s\+$//g')"
|
|
|
|
local sorted="$(echo ${trimmed} | tr ' ' '\n' | sort | tr '\n' ' ')"
|
|
|
|
echo "${sorted}"
|
2022-03-26 12:42:40 -07:00
|
|
|
}
|
|
|
|
|
2022-08-02 21:14:51 -07:00
|
|
|
# Gets a list of installed packages as space delimited pairs with each pair colon delimited.
|
|
|
|
# <name>:<version> <name:version>...
|
|
|
|
function get_installed_packages {
|
|
|
|
install_log_filepath="${1}"
|
|
|
|
local regex="^Unpacking ([^ :]+)([^ ]+)? (\[[^ ]+\]\s)?\(([^ )]+)"
|
|
|
|
dep_packages=""
|
|
|
|
while read -r line; do
|
|
|
|
if [[ "${line}" =~ ${regex} ]]; then
|
|
|
|
dep_packages="${dep_packages}${BASH_REMATCH[1]}:${BASH_REMATCH[4]} "
|
|
|
|
else
|
|
|
|
log_err "Unable to parse package name and version from \"${line}\""
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
done < <(grep "^Unpacking " ${install_log_filepath})
|
|
|
|
if test -n "${dep_packages}"; then
|
|
|
|
echo "${dep_packages:0:-1}" # Removing trailing space.
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
fi
|
2022-07-19 20:02:22 -07:00
|
|
|
}
|
|
|
|
|
2022-08-02 21:14:51 -07:00
|
|
|
# Split fully qualified package into name and version.
|
2022-03-26 12:42:40 -07:00
|
|
|
function get_package_name_ver {
|
2022-07-19 20:02:22 -07:00
|
|
|
IFS=\: read name ver <<< "${1}"
|
2022-03-26 12:42:40 -07:00
|
|
|
# If version not found in the fully qualified package value.
|
|
|
|
if test -z "${ver}"; then
|
2022-07-23 17:06:17 -07:00
|
|
|
ver="$(grep "Version:" <<< "$(apt-cache show ${name})" | awk '{print $2}')"
|
2022-03-26 12:42:40 -07:00
|
|
|
fi
|
2022-06-30 01:17:13 -07:00
|
|
|
echo "${name}" "${ver}"
|
2022-03-26 12:42:40 -07:00
|
|
|
}
|
2022-06-30 07:13:58 -07:00
|
|
|
|
2022-07-14 21:23:42 -07:00
|
|
|
function log { echo "$(date +%H:%M:%S)" "${@}"; }
|
2022-08-02 21:14:51 -07:00
|
|
|
function log_err { >&2 echo "$(date +%H:%M:%S)" "${@}"; }
|
2022-07-14 21:23:42 -07:00
|
|
|
|
2022-07-23 17:06:17 -07:00
|
|
|
function log_empty_line { echo ""; }
|
|
|
|
|
|
|
|
# Writes the manifest to a specified file.
|
|
|
|
function write_manifest {
|
2022-07-14 21:23:42 -07:00
|
|
|
log "Writing ${1} packages manifest to ${3}..."
|
2022-08-02 21:14:51 -07:00
|
|
|
# 0:-1 to remove trailing comma, delimit by newline and sort.
|
2022-07-14 21:23:42 -07:00
|
|
|
echo "${2:0:-1}" | tr ',' '\n' | sort > ${3}
|
2022-07-23 17:06:17 -07:00
|
|
|
log "done"
|
2022-07-19 21:08:41 -07:00
|
|
|
}
|
2022-08-02 21:14:51 -07:00
|
|
|
|
|
|
|
get_installed_packages "/tmp/cache-apt-pkgs-action-cache/install.log"
|