Skip to content

Commit 7390a61

Browse files
committed
Save all files in /var/lib/dpkg/info
1 parent 61fc13e commit 7390a61

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

install_and_cache_pkgs.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ for installed_package in ${installed_packages}; do
110110
read package_name package_ver < <(get_package_name_ver "${installed_package}")
111111
log " * Caching ${package_name} to ${cache_filepath}..."
112112

113+
# Get the entry in /var/lib/dpkg/status
114+
mkdir -p /var/tmp/dpkg-restore || :
115+
sed -n -r -e "/Package:\s+${package_name}$/,/^$/p" /var/lib/dpkg/status > /var/tmp/dpkg-restore/${package_name}.status
116+
113117
# Pipe all package files (no folders), including symlinks, their targets, and installation control data to Tar.
114118
tar -cf "${cache_filepath}" -C / --verbatim-files-from --files-from <(
115-
{ dpkg -L "${package_name}" &&
116-
{ get_install_script_filepath "/" "${package_name}" "preinst" ;
117-
get_install_script_filepath "/" "${package_name}" "postinst" ; } ; } |
119+
{ dpkg -L "${package_name}" && echo "/var/tmp/dpkg-restore/${package_name}.status" &&
120+
get_install_script_filepaths "/" "${package_name}" ; } |
118121
while IFS= read -r f; do
119122
if test -f "${f}" -o -L "${f}"; then
120123
get_tar_relpath "${f}"

lib.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function execute_install_script {
2727
test "${debug}" == "true" && log "- Executing ${install_script_filepath}..." || :
2828
# Don't abort on errors; dpkg-trigger will error normally since it is
2929
# outside its run environment.
30+
export DPKG_MAINTSCRIPT_NAME="${3}"
3031
sudo sh ${echocmd} ${install_script_filepath} ${4} || true
3132
test "${debug}" == "true" && log " done"
3233
fi
@@ -49,6 +50,11 @@ function get_install_script_filepath {
4950
test "${filepath}" && echo "${filepath}"
5051
}
5152

53+
function get_install_script_filepaths {
54+
# Filename includes arch (e.g. amd64).
55+
ls -1 ${1}var/lib/dpkg/info/${2}:*.* ${1}var/lib/dpkg/info/${2}.* 2> /dev/null
56+
}
57+
5258
###############################################################################
5359
# Gets a list of installed packages from a Debian package installation log.
5460
# Arguments:

restore_pkgs.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ for package in "${packages[@]}"; do
5555
test "${debug}" == "true" && log "- ${package} restoring..." || :
5656
sudo tar -xf "${cached_filepath}" -C "${cache_restore_root}" > /dev/null
5757
test "${debug}" == "true" && log " done" || :
58-
58+
if test -f "${cache_restore_root}/var/tmp/dpkg-restore/${package}.status" ] ; then
59+
echo "" >> "${cache_restore_root}/var/lib/dpkg/status"
60+
cat "${cache_restore_root}/var/tmp/dpkg-restore/${package}.status" >> "${cache_restore_root}/var/lib/dpkg/status"
61+
fi
5962
# Execute install scripts if available.
6063
if test ${execute_install_scripts} == "true"; then
6164
# May have to add more handling for extracting pre-install script before extracting all files.

0 commit comments

Comments
 (0)