add guard clauses if dpkg status is missing

This commit is contained in:
Jérémy Lecour 2024-03-29 10:31:34 +01:00 committed by Jérémy Lecour
parent c67c1ca7ad
commit 297cafe04b
Signed by: jlecour
SSH key fingerprint: SHA256:h+5LgHRKwN9lS0SsdVR5yZPeFlJE4Mt+8UtL4CcP8dY
2 changed files with 48 additions and 37 deletions

View file

@ -15,6 +15,7 @@ The **patch** part changes is incremented if multiple releases happen the same m
### Changed
* rsync `/etc` with `--delete`
* add guard clauses if dpkg status is missing
### Fixed
@ -81,4 +82,4 @@ use nft is available and ignore iptables errors
## [22.03.8] 2022-03-27
dump-server-state has its own repository and changelog
dump-server-state has its own repository and changelog

View file

@ -187,48 +187,53 @@ task_dpkg_full() {
apt_config_bin=$(command -v apt-config)
if [ -n "${apt_config_bin}" ]; then
# will do something like `dir_state_status='/var/lib/dpkg/status'`
eval "$(${apt_config_bin} shell dir_state_status Dir::State::status)"
fi
dpkg_dir=$(dirname "${dir_state_status}")
last_result=$(mkdir -p "${dump_dir}${dpkg_dir}" && chmod -R 755 "${dump_dir}${dpkg_dir}")
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* mkdir/chmod OK"
else
debug "* mkdir/chmod ERROR"
debug "${last_result}"
rc=10
fi
rsync_bin=$(command -v rsync)
if [ -n "${rsync_bin}" ]; then
last_result=$(${rsync_bin} -ah --itemize-changes --exclude='*-old' "${dpkg_dir}/" "${dump_dir}${dpkg_dir}/")
if [ -d "${dpkg_dir}" ]; then
last_result=$(mkdir -p "${dump_dir}${dpkg_dir}" && chmod -R 755 "${dump_dir}${dpkg_dir}")
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* rsync OK"
debug "* mkdir/chmod OK"
else
debug "* rsync ERROR :"
debug "* mkdir/chmod ERROR"
debug "${last_result}"
rc=10
fi
rsync_bin=$(command -v rsync)
if [ -n "${rsync_bin}" ]; then
last_result=$(${rsync_bin} -ah --itemize-changes --exclude='*-old' "${dpkg_dir}/" "${dump_dir}${dpkg_dir}/")
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* rsync OK"
else
debug "* rsync ERROR :"
debug "${last_result}"
rc=10
fi
else
debug "* rsync not found"
last_result=$(cp -r "${dpkg_dir}/*" "${dump_dir}${dpkg_dir}/" && rm -rf "${dump_dir}${dpkg_dir}/*-old")
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* cp OK"
else
debug "* cp ERROR :"
debug "${last_result}"
rc=10
fi
fi
else
debug "* rsync not found"
last_result=$(cp -r "${dpkg_dir}/*" "${dump_dir}${dpkg_dir}/" && rm -rf "${dump_dir}${dpkg_dir}/*-old")
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* cp OK"
else
debug "* cp ERROR :"
debug "${last_result}"
rc=10
fi
debug "* ${dpkg_dir} not found"
fi
}
@ -240,18 +245,23 @@ task_dpkg_status() {
apt_config_bin=$(command -v apt-config)
if [ -n "${apt_config_bin}" ]; then
# will do something like `dir_state_status='/var/lib/dpkg/status'`
eval "$(${apt_config_bin} shell dir_state_status Dir::State::status)"
fi
last_result=$(cp "${dir_state_status}" "${dump_dir}/dpkg-status.txt")
last_rc=$?
if [ -f "${dir_state_status}" ]; then
last_result=$(cp "${dir_state_status}" "${dump_dir}/dpkg-status.txt")
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* cp OK"
if [ ${last_rc} -eq 0 ]; then
debug "* cp OK"
else
debug "* cp ERROR :"
debug "${last_result}"
rc=10
fi
else
debug "* cp ERROR :"
debug "${last_result}"
rc=10
debug "* ${dir_state_status} not found"
fi
}