#!/usr/bin/env bash set -o errexit set -o nounset set -o pipefail cd "$(dirname "$0")" if [[ -z "${1-}" ]] || [[ ! -e "${1}" ]]; then echo "Missing or non-existent loop device path." exit fi if [[ ! $(findmnt -M "./rootfs") ]]; then echo "Not mounted, aborting." exit fi echo "Unmounting FSes..." sudo umount ./rootfs/boot/ sudo umount ./rootfs/sys/ sudo umount ./rootfs/dev/pts sudo umount ./rootfs/dev/ sudo umount ./rootfs/proc/ sudo umount ./rootfs/ echo "Detaching loop setup..." sudo losetup -d "${1}"