diff options
author | Timo Teräs <timo.teras@iki.fi> | 2017-10-18 14:50:02 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2017-10-18 15:01:03 +0300 |
commit | c3eeebd0310c79f301636eb6ce271300a8d97ea8 (patch) | |
tree | d43247db6290e9e3344c75659a6dd246354842ea | |
parent | 75475f7e89527ee6d2b9b4a8b4f8172467afc04e (diff) | |
download | alpine-conf-c3eeebd0310c79f301636eb6ce271300a8d97ea8.tar.bz2 alpine-conf-c3eeebd0310c79f301636eb6ce271300a8d97ea8.tar.xz |
setup-bootable: do cleanup via exit trap
-rw-r--r-- | setup-bootable.in | 22 |
1 files 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 |