From a8d099144e4e35593aab162ffeb667a1916ece18 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Thu, 11 Jun 2020 12:19:19 +0200 Subject: [PATCH] Refactored destructor --- scripts/image/base.sh | 22 +++++++++++++--------- scripts/image/chroot.sh | 4 ---- scripts/image/setup.sh | 9 --------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/scripts/image/base.sh b/scripts/image/base.sh index 1d82fd5..8693779 100644 --- a/scripts/image/base.sh +++ b/scripts/image/base.sh @@ -51,15 +51,19 @@ mount_partitions(){ } umount_everything(){ - info "Unmounting everything..." && - (umount -lv "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!") && - (umount -lv "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!" ) && - (umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!" ) && - (umount -v "$chroot_sys_mount_path" || warning "Umounting $chroot_sys_mount_path failed!") && - (umount -v "$root_mount_path""boot/" || warning "Umounting $root_mount_path""boot/ failed!") && - (umount -v "$root_mount_path" || warning "Umounting $root_mount_path failed!") && - (umount -v "$boot_mount_path" || warning "Umounting $boot_mount_path failed!") || - warning "Failed." + info "Cleaning up..." + info "Unmounting everything..." + umount -lv "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!" + umount -lv "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!" + umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!" + umount -v "$chroot_sys_mount_path" || warning "Umounting $chroot_sys_mount_path failed!" + umount -v "$root_mount_path""boot/" || warning "Umounting $root_mount_path""boot/ failed!" + umount -v "$root_mount_path" || warning "Umounting $root_mount_path failed!" + umount -v "$boot_mount_path" || warning "Umounting $boot_mount_path failed!" + info "Deleting mount folders..." + rmdir -v "$root_mount_path" || warning "Removing $root_mount_path failed!" + rmdir -v "$boot_mount_path" || warning "Removing $boot_mount_path failed!" + rmdir -v "$working_folder_path" || warning "Removing $working_folder_path failed!" } mount_chroot_binds(){ diff --git a/scripts/image/chroot.sh b/scripts/image/chroot.sh index b751df8..a968ae7 100644 --- a/scripts/image/chroot.sh +++ b/scripts/image/chroot.sh @@ -4,10 +4,6 @@ # shellcheck disable=SC2154 # Deactivate not referenced link source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1) -destructor(){ - umount_everything -} - info "Starting chroot..." set_device_path diff --git a/scripts/image/setup.sh b/scripts/image/setup.sh index 6d7c31b..7ee3492 100644 --- a/scripts/image/setup.sh +++ b/scripts/image/setup.sh @@ -7,15 +7,6 @@ source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh fa info "Setupscript for images started..." -info "Define functions..." -destructor(){ - info "Cleaning up..." - umount_everything - rmdir -v "$root_mount_path" || warning "Removing $root_mount_path failed!" - rmdir -v "$boot_mount_path" || warning "Removing $boot_mount_path failed!" - rmdir -v "$working_folder_path" || warning "Removing $working_folder_path failed!" -} - info "Checking if root..." if [ "$(id -u)" != "0" ];then error "This script must be executed as root!"