Refactored destructor

This commit is contained in:
Kevin Veen-Birkenbach 2020-06-11 12:19:19 +02:00
parent aa2eb62e77
commit a8d099144e
3 changed files with 13 additions and 22 deletions

View File

@ -51,15 +51,19 @@ mount_partitions(){
} }
umount_everything(){ umount_everything(){
info "Unmounting everything..." && info "Cleaning up..."
(umount -lv "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!") && info "Unmounting everything..."
(umount -lv "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!" ) && umount -lv "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!"
(umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!" ) && umount -lv "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!"
(umount -v "$chroot_sys_mount_path" || warning "Umounting $chroot_sys_mount_path failed!") && umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!"
(umount -v "$root_mount_path""boot/" || warning "Umounting $root_mount_path""boot/ failed!") && umount -v "$chroot_sys_mount_path" || warning "Umounting $chroot_sys_mount_path failed!"
(umount -v "$root_mount_path" || warning "Umounting $root_mount_path failed!") && umount -v "$root_mount_path""boot/" || warning "Umounting $root_mount_path""boot/ failed!"
(umount -v "$boot_mount_path" || warning "Umounting $boot_mount_path failed!") || umount -v "$root_mount_path" || warning "Umounting $root_mount_path failed!"
warning "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(){ mount_chroot_binds(){

View File

@ -4,10 +4,6 @@
# shellcheck disable=SC2154 # Deactivate not referenced link # shellcheck disable=SC2154 # Deactivate not referenced link
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1) source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
destructor(){
umount_everything
}
info "Starting chroot..." info "Starting chroot..."
set_device_path set_device_path

View File

@ -7,15 +7,6 @@ source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh fa
info "Setupscript for images started..." 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..." info "Checking if root..."
if [ "$(id -u)" != "0" ];then if [ "$(id -u)" != "0" ];then
error "This script must be executed as root!" error "This script must be executed as root!"