From 58ca9eb86fa35da57eafcbf3e75d2700d569e5bc Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 16 Nov 2024 04:23:54 +0100 Subject: [PATCH] wip/mount --- shell/mount.sh | 55 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/shell/mount.sh b/shell/mount.sh index 118f8e9..ed78546 100644 --- a/shell/mount.sh +++ b/shell/mount.sh @@ -1,52 +1,75 @@ mo() { local root="${1}" if [ -z "${root}" ]; then - log_error "No root" + log_error "No root target directory" return 1 fi root="$(realpath "${root}")" if ! mkdir "overlay"; then - log_error "Unable to make mount directory" + log_error "Unable to make overlay directory" return 2 fi - { + ( if ! cd "overlay"; then - log_error "Unable to move into mount directory" + log_error "Unable to move into overlay directory" return 3 fi local directory for directory in "lower" "upper" "work" "mount"; do if ! mkdir --parents "${directory}"; then - log_error "Unable to move into: ${directory}" + log_error "Unable to make directory: ${directory}" return 4 fi done local file="${root}/filesystem.squashfs" if ! mount "${file}" "lower"; then - log_error "Unable to mount: ${file}" + log_error "Unable to lower mount: ${file}" return 5 fi if ! mount \ -o "lowerdir=lower,upperdir=upper,workdir=work" \ -t "overlay" \ "overlay" "mount"; then - log_error "Unable to mount: ${file}" + log_error "Unable to overlay mount" return 6 fi - } + ) } uo() { - cd "overlay" - if umount "mount"; then - rmdir "mount" - rm --recursive "upper" "work" - if umount "lower"; then - rmdir "lower" + ( + if ! cd "overlay"; then + log_error "Unable to move into overlay directory" + return 1 fi + if ! umount "mount"; then + log_error "Unable to unmount mount directory" + return 2 + fi + if ! rmdir "mount"; then + log_error "Unable to remove mount directory" + return 3 + fi + local directory + for directory in "upper" "work"; do + if ! rm --force --recursive "${directory}"; then + log_error "Unable to remove directory: ${directory}" + return 4 + fi + done + if ! umount "lower"; then + log_error "Unable to unmount lower directory" + return 5 + fi + if ! rmdir "lower"; then + log_error "Unable to remove lower directory" + return 6 + fi + ) + if ! rmdir "overlay"; then + log_error "Unable to remove overlay directory" + return 7 fi - cd .. - rmdir "overlay" } mr() {