diff --git a/tools/build/beinstall.sh b/tools/build/beinstall.sh index 9c0e93491c0d..cd325dafc805 100755 --- a/tools/build/beinstall.sh +++ b/tools/build/beinstall.sh @@ -82,6 +82,14 @@ unmount_be() { mount | grep " on ${BE_MNTPT}" | awk '{print $3}' | sort -r | xargs -t umount -f } +copy_pkgs() { + # Before cleaning up, try to save progress in pkg(8) updates, to + # speed up future updates. This is only called on the error path; + # no need to run on success. + echo "Rsyncing back newly saved packages..." + rsync -av --progress ${BE_MNTPT}/var/cache/pkg/. /var/cache/pkg/. +} + cleanup_be() { # Before destroying, unmount any child filesystems that may have # been mounted under the boot environment. Sort them in reverse @@ -225,6 +233,10 @@ if [ -n "${CONFIG_UPDATER}" ]; then [ $? -ne 0 ] && errx "${CONFIG_UPDATER} (post-world) failed!" fi +if which rsync >/dev/null 2>&1; then + cleanup_commands="copy_pkgs ${cleanup_commands}" +fi + BE_PKG="chroot ${BE_MNTPT} env ASSUME_ALWAYS_YES=true pkg" if [ -z "${NO_PKG_UPGRADE}" ]; then ${BE_PKG} update || errx "Unable to update pkg"