From 8234e068614c0bffb77149f238c6059cad6be010 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 27 Feb 2022 20:12:49 -0500 Subject: [PATCH] Finish incorporating cleanup in the normal shutdown process. --- scripts/build_image/build_alpine.bash | 42 ++++++++++++++++++--------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/scripts/build_image/build_alpine.bash b/scripts/build_image/build_alpine.bash index f3a2140..162750d 100755 --- a/scripts/build_image/build_alpine.bash +++ b/scripts/build_image/build_alpine.bash @@ -9,18 +9,9 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function cleanup { sync kill_gpg_agent - for f in "${jails[@]}"; do - log "Stopping jail $f" - jail -r "$f" - done - for (( idx=${#mountedfolders[@]}-1 ; idx>=0 ; idx-- )) ; do - log "Unmounting folder ${mountedfolders[idx]}" - umount "${mountedfolders[idx]}" - done - for f in "${memorydevices[@]}"; do - log "Removing memory device $f" - mdconfig -d -u "$f" - done + stop_jails + unmount_folders + remove_memory_devices for f in "${folders[@]}"; do log "Deleting $f" rm -rf "$f" @@ -227,8 +218,28 @@ function kill_gpg_agent { unset gpgagents } -function unmount_image { - echo "foo" +function stop_jails { + for f in "${jails[@]}"; do + log "Stopping jail $f" + jail -r "$f" + done + unset jails +} + +function unmount_folders { + for (( idx=${#mountedfolders[@]}-1 ; idx>=0 ; idx-- )) ; do + log "Unmounting folder ${mountedfolders[idx]}" + umount "${mountedfolders[idx]}" + done + unset mountedfolders +} + +function remove_memory_devices { + for f in "${memorydevices[@]}"; do + log "Removing memory device $f" + mdconfig -d -u "$f" + done + unset memorydevices } function main { @@ -253,6 +264,9 @@ function main { make_chroot kill_gpg_agent + stop_jails + unmount_folders + remove_memory_devices log "Copying final image to $DIR" cp "$image_file" "$DIR"