From c3eeebd0310c79f301636eb6ce271300a8d97ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Wed, 18 Oct 2017 14:50:02 +0300 Subject: setup-bootable: do cleanup via exit trap --- setup-bootable.in | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/setup-bootable.in b/setup-bootable.in index 06127be..ab6b0d7 100644 --- a/setup-bootable.in +++ b/setup-bootable.in @@ -3,6 +3,9 @@ prog=${0##*/} version=@VERSION@ files_to_move="boot efi apks syslinux.cfg .alpine-release" +read_only_mounts= +umounts= +uninstalls= cleanup_mounts() { local i= @@ -12,24 +15,34 @@ cleanup_mounts() { for i in $read_only_mounts; do mount -o remount,ro "$i" || echo "Warning: Failed to remount as read-only. Is modloop mounted?" done + read_only_mounts="" if [ -n "$umounts" ]; then umount $umounts + umounts="" fi } cleanup_installs() { if [ -n "$uninstalls" ]; then - apk del --quiet syslinux + apk del --quiet $uninstalls + uninstalls="" fi } -die() { - echo "$@" >&2 +cleanup() { cleanup_mounts cleanup_installs +} + +trap cleanup EXIT +trap "exit 2" INT TERM QUIT + +die() { + echo "$@" >&2 exit 1 } + # find device for mountpoint find_dev() { local mnt="${1%/}" # strip trailing / @@ -377,8 +390,6 @@ check_syslinux # If we only copy then we are done. if [ -n "$upgrade" ] && [ -z "$syslinux" ]; then - cleanup_installs - cleanup_mounts exit 0 fi @@ -406,4 +417,3 @@ if [ -b $parent_dev ]; then else echo "Warning: Could not find the parent device for $dest" fi -cleanup_installs -- cgit v1.2.3