diff options
author | Lyndon Brown <jnqnfe@gmail.com> | 2020-05-05 01:56:36 +0100 |
---|---|---|
committer | Lyndon Brown <jnqnfe@gmail.com> | 2020-05-05 19:43:15 +0100 |
commit | f27d13de08af9ae788b0d2f848e2202a399e4f43 (patch) | |
tree | 1165ce57a756aec4f8def2e684c6e77e05b654eb /functions/packages.sh | |
parent | a065e60043fc5ff217be0be90191305d8ade2518 (diff) | |
download | vyos-live-build-f27d13de08af9ae788b0d2f848e2202a399e4f43.tar.gz vyos-live-build-f27d13de08af9ae788b0d2f848e2202a399e4f43.zip |
make temporary state of installed tools recoverable
some scripts temporarily install packages to accomplish some work before
then removing them. the list of packages installed is kept in memory in a
variable.
a weakness of this design is that if a failure occurs or the user cancels,
and then following this the user re-runs `lb build`, letting it try to
pick up and recover from where it left off, that list of packages that had
been installed is lost, resulting in those packages that were installed
then being a permanent part of the chroot.
here we fix this weakness by backing up the list to a file, which is always
read from on removal. thus in a recovery situation, any packages still
installed from a situation like that just described, will be removed upon
the next use of `Remove_package()`.
this is not perfect, since we are having to wait for opportunistic
execution of the remove function. we need to find a suitable place for the
`Cleanup_temp_packages()` function to be used.
- doing so in `Init_config_data()` would not be suitable because we don't
hold the lock when that's run, even if we ignored the hijacking of that
function for taking such action...
- doing it in `Exit()` doesn't seem a good fit either.
- putting it explicitly in every build script just seems a little messy...
perhaps a local exit trap like for removing the lock...?
note that `binary_rootfs` skips running the remove function after installing
tooling, since it just throws the wrapper chroot away, which then leaves the
file around with stale data for the next remove instance to pick up, which
then does not actually remove it because it's not installed. this is not
ideal either... perhaps the optimisation should be removed from that script?
Gbp-Dch: Short
Diffstat (limited to 'functions/packages.sh')
-rwxr-xr-x | functions/packages.sh | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/functions/packages.sh b/functions/packages.sh index 5c7529051..0044a46e4 100755 --- a/functions/packages.sh +++ b/functions/packages.sh @@ -9,7 +9,13 @@ ## under certain conditions; see COPYING for details. -# Note, updates _LB_PACKAGES +# The file that records temporarily installed packages. +Installed_tmp_packages_file () +{ + echo "chroot.installed_tmp_pkgs" +} + +# Note, writes to _LB_PACKAGES Check_package () { local CHROOT="${1}" @@ -30,10 +36,19 @@ Check_package () fi } +# Note, reads from _LB_PACKAGES Install_package () { if [ -n "${_LB_PACKAGES}" ] && [ "${LB_BUILD_WITH_CHROOT}" != "false" ] then + # Record in file to survive failure such that recovery can take place. + local LIST_FILE + LIST_FILE="$(Installed_tmp_packages_file)" + local PACKAGE + for PACKAGE in ${_LB_PACKAGES}; do + echo "${PACKAGE}" >> "${LIST_FILE}" + done + case "${LB_APT}" in apt|apt-get) Chroot chroot "apt-get install -o APT::Install-Recommends=false ${APT_OPTIONS} ${_LB_PACKAGES}" @@ -43,23 +58,51 @@ Install_package () Chroot chroot "aptitude install --without-recommends ${APTITUDE_OPTIONS} ${_LB_PACKAGES}" ;; esac + unset _LB_PACKAGES # Can clear this now fi } Remove_package () { - if [ -n "${_LB_PACKAGES}" ] && [ "${LB_BUILD_WITH_CHROOT}" != "false" ] - then + if [ "${LB_BUILD_WITH_CHROOT}" != "true" ]; then + return + fi + + local LIST_FILE + LIST_FILE="$(Installed_tmp_packages_file)" + + # List is read from file to ensure packages from any past failure are + # included in the list on re-running scripts to recover. + local PACKAGES="" + if [ -e "${LIST_FILE}" ]; then + local PACKAGE + while read -r PACKAGE; do + PACKAGES="${PACKAGES} ${PACKAGE}" + done < "${LIST_FILE}" + fi + + if [ -n "${PACKAGES}" ]; then case "${LB_APT}" in apt|apt-get) - Chroot chroot "apt-get remove --auto-remove --purge ${APT_OPTIONS} ${_LB_PACKAGES}" + Chroot chroot "apt-get remove --auto-remove --purge ${APT_OPTIONS} ${PACKAGES}" ;; aptitude) - Chroot chroot "aptitude purge --purge-unused ${APTITUDE_OPTIONS} ${_LB_PACKAGES}" + Chroot chroot "aptitude purge --purge-unused ${APTITUDE_OPTIONS} ${PACKAGES}" ;; esac fi + + rm -f "${LIST_FILE}" +} + +#FIXME: make use of this. see commit log that added this for details. +# Perform temp package removal for recovery if necessary +Cleanup_temp_packages () +{ + if [ -e "$(Installed_tmp_packages_file)" ]; then + Remove_package + fi } # Check_installed |