Draft of postinst support from issue #44.

This commit is contained in:
awalsh128 2022-09-09 20:35:48 -07:00
parent c85f53ff72
commit 00e34cb96c
4 changed files with 49 additions and 5 deletions

View file

@ -14,6 +14,10 @@ inputs:
description: 'Version will create a new cache and install packages.' description: 'Version will create a new cache and install packages.'
required: false required: false
default: '' default: ''
execute_postinst:
description: 'Execute Debian package postinst script upon restore. Required by some packages.'
required: false
default: 'false'
refresh: refresh:
description: 'Option to refresh / upgrade the packages in the same cache.' description: 'Option to refresh / upgrade the packages in the same cache.'
required: false required: false
@ -56,6 +60,7 @@ runs:
~/cache-apt-pkgs \ ~/cache-apt-pkgs \
/ \ / \
"${{ steps.load-cache.outputs.cache-hit }}" \ "${{ steps.load-cache.outputs.cache-hit }}" \
"${{ inputs.execute_postinst }}" \
${{ inputs.packages }} ${{ inputs.packages }}
function create_list { local list=$(cat ~/cache-apt-pkgs/manifest_${1}.log | tr '\n' ','); echo ${list:0:-1}; }; function create_list { local list=$(cat ~/cache-apt-pkgs/manifest_${1}.log | tr '\n' ','); echo ${list:0:-1}; };
echo "::set-output name=package-version-list::$(create_list main)" echo "::set-output name=package-version-list::$(create_list main)"

View file

@ -10,8 +10,11 @@ source "${script_dir}/lib.sh"
# Directory that holds the cached packages. # Directory that holds the cached packages.
cache_dir="${1}" cache_dir="${1}"
# Cache and execute post install scripts on restore.
execute_postinst="${2}"
# List of the packages to use. # List of the packages to use.
input_packages="${@:2}" input_packages="${@:3}"
# Trim commas, excess spaces, and sort. # Trim commas, excess spaces, and sort.
normalized_packages="$(normalize_package_list "${input_packages}")" normalized_packages="$(normalize_package_list "${input_packages}")"
@ -61,6 +64,11 @@ done
log_empty_line log_empty_line
# Post install script install location.
postinst_filepath="/tmp/deb-ctrl-data/postinst"
postinst_dirpath=$(dirname ${postinst_filepath})
mkdir -r "${postinst_dirpath}"
installed_package_count=$(wc -w <<< "${installed_packages}") installed_package_count=$(wc -w <<< "${installed_packages}")
log "Caching ${installed_package_count} installed packages..." log "Caching ${installed_package_count} installed packages..."
for installed_package in ${installed_packages}; do for installed_package in ${installed_packages}; do
@ -70,12 +78,23 @@ for installed_package in ${installed_packages}; do
if test ! -f "${cache_filepath}"; then if test ! -f "${cache_filepath}"; then
read installed_package_name installed_package_ver < <(get_package_name_ver "${installed_package}") read installed_package_name installed_package_ver < <(get_package_name_ver "${installed_package}")
log " * Caching ${installed_package_name} to ${cache_filepath}..." log " * Caching ${installed_package_name} to ${cache_filepath}..."
# Pipe all package files (no folders) to Tar. # Pipe all package files (no folders) to Tar.
dpkg -L "${installed_package_name}" | dpkg -L "${installed_package_name}" |
while IFS= read -r f; do while IFS= read -r f; do
if test -f $f || test -L $f; then echo "${f:1}"; fi; #${f:1} removes the leading slash that Tar disallows if test -f $f || test -L $f; then echo "${f:1}"; fi; #${f:1} removes the leading slash that Tar disallows
done | done |
sudo xargs tar -cf "${cache_filepath}" -C / sudo xargs tar -cf "${cache_filepath}" -C /
# Append post install scripts if enabled and available.
if test "${execute_postinst}" == "true"; then
dpkg -e pkg "${postinst_dirpath}"
if test -f "${postinst_filepath}"; then
tar -caf "${cache_filepath}" "${postinst_filepath}"
rm "${postinst_filepath}"
fi
fi
log " done (compressed size $(du -h "${cache_filepath}" | cut -f1))." log " done (compressed size $(du -h "${cache_filepath}" | cut -f1))."
fi fi

View file

@ -17,15 +17,18 @@ cache_restore_root="${2}"
# Indicates that the cache was found. # Indicates that the cache was found.
cache_hit="${3}" cache_hit="${3}"
# Cache and execute post install scripts on restore.
execute_postinst="${4}"
# List of the packages to use. # List of the packages to use.
packages="${@:4}" packages="${@:5}"
script_dir="$(dirname -- "$(realpath -- "${0}")")" script_dir="$(dirname -- "$(realpath -- "${0}")")"
if [ "$cache_hit" == true ]; then if [ "$cache_hit" == true ]; then
${script_dir}/restore_pkgs.sh ~/cache-apt-pkgs "${cache_restore_root}" ${script_dir}/restore_pkgs.sh ~/cache-apt-pkgs "${cache_restore_root}" "${execute_postinst}"
else else
${script_dir}/install_and_cache_pkgs.sh ~/cache-apt-pkgs ${packages} ${script_dir}/install_and_cache_pkgs.sh ~/cache-apt-pkgs "${execute_postinst}" ${packages}
fi fi
log_empty_line log_empty_line

View file

@ -14,6 +14,9 @@ cache_dir="${1}"
# Typically filesystem root '/' but can be changed for testing. # Typically filesystem root '/' but can be changed for testing.
cache_restore_root="${2}" cache_restore_root="${2}"
# Cache and execute post install scripts on restore.
execute_postinst="${3}"
cache_filepaths="$(ls -1 "${cache_dir}" | sort)" cache_filepaths="$(ls -1 "${cache_dir}" | sort)"
log "Found $(echo ${cache_filepaths} | wc -w) files in the cache." log "Found $(echo ${cache_filepaths} | wc -w) files in the cache."
for cache_filepath in ${cache_filepaths}; do for cache_filepath in ${cache_filepaths}; do
@ -33,10 +36,24 @@ log_empty_line
# Only search for archived results. Manifest and cache key also live here. # Only search for archived results. Manifest and cache key also live here.
cached_pkg_filepaths=$(ls -1 "${cache_dir}"/*.tar | sort) cached_pkg_filepaths=$(ls -1 "${cache_dir}"/*.tar | sort)
cached_pkg_filecount=$(echo ${cached_pkg_filepaths} | wc -w) cached_pkg_filecount=$(echo ${cached_pkg_filepaths} | wc -w)
# Post install script restore location.
postint_filepath="/tmp/deb-ctrl-data/postinst"
log "Restoring ${cached_pkg_filecount} packages from cache..." log "Restoring ${cached_pkg_filecount} packages from cache..."
for cached_pkg_filepath in ${cached_pkg_filepaths}; do for cached_pkg_filepath in ${cached_pkg_filepaths}; do
log "- $(basename "${cached_pkg_filepath}") restoring..." log "- $(basename "${cached_pkg_filepath}") restoring..."
sudo tar -xf "${cached_pkg_filepath}" -C "${cache_restore_root}" > /dev/null sudo tar -xf "${cached_pkg_filepath}" -C "${cache_restore_root}" > /dev/null
if test "${execute_postinst}" == "true"; then
# Execute post install script if available.
if test -f "${postint_filepath}"; then
sh -x ${postint_filepath}
rm -fr ${postint_filepath}
fi
fi
log " done" log " done"
done done
log "done" log "done"