From 8bf46c59fda997134f7d12af54b65cb81a22ec60 Mon Sep 17 00:00:00 2001 From: torben Date: Tue, 9 Feb 2016 11:22:43 +0100 Subject: Adding cleanup routines. --- builder/build-initramfs.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index 6a956a7f..ab4c4242 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -368,13 +368,11 @@ if [[ "$target" != '' ]]; then if [[ -f "$target" ]]; then _target="$(mktemp --directory)" _xmount_mountpoint_target="$(mktemp --directory)" - xmount --in qemu "$target" --out raw \ - "$_xmount_mountpoint_target" + xmount --in qemu "$target" --out raw "$_xmount_mountpoint_target" _xmount_device_target="$(losetup --find)" losetup "$_xmount_device_target" loopdev \ "${_xmount_mountpoint_target}/"*.dd - mount "$_xmount_device_target" \ - "$_target" + mount "$_xmount_device_target" "$_target" fi if [[ -d "$_target" ]]; then _temporary_working_directory="$(chroot "$_target" mktemp --directory)" @@ -409,6 +407,15 @@ if [[ "$target" != '' ]]; then "${_temporary_working_directory}/${BASH_SOURCE[0]}" \ ${_parameter_to_forward[*]} mv "${_target}/$file_path" "$file_path" + # Do cleanup procedures. + umount "${_target}${_temporary_working_directory}" + rm --recursive --force "${_target}${_temporary_working_directory}" + if [[ -f "$target" ]]; then + umount "$_target" + losetup --detach "$_xmount_device_target" + umount "$_xmount_mountpoint_target" + rm --recursive --force "$_target" "$_xmount_mountpoint_target" + fi fi exit 0 fi -- cgit v1.2.3-55-g7522