From 9eacf3fe3f264629d22bb0b2c15414da53fc6a85 Mon Sep 17 00:00:00 2001 From: downtownallday Date: Mon, 27 Jun 2022 11:02:15 -0400 Subject: [PATCH] Simplify ehdd mount/umount code --- ehdd/ehdd_funcs.sh | 15 +++++++++++++++ ehdd/mount.sh | 2 +- ehdd/umount.sh | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ehdd/ehdd_funcs.sh b/ehdd/ehdd_funcs.sh index b86901b2..5c4a82f5 100644 --- a/ehdd/ehdd_funcs.sh +++ b/ehdd/ehdd_funcs.sh @@ -24,3 +24,18 @@ keyfile_option() { echo "--key-file $EHDD_KEYFILE" fi } + +hdd_exists() { + [ -e "$EHDD_IMG" ] && return 0 + return 1 +} + +is_mounted() { + [ ! -e "$EHDD_IMG" ] && return 1 + if mount | grep "^/dev/mapper/$EHDD_LUKS_NAME on $EHDD_MOUNTPOINT" >/dev/null; then + # mounted + return 0 + else + return 1 + fi +} diff --git a/ehdd/mount.sh b/ehdd/mount.sh index 10a9509c..37233f4e 100755 --- a/ehdd/mount.sh +++ b/ehdd/mount.sh @@ -7,7 +7,7 @@ if [ ! -e "$EHDD_IMG" ]; then exit 0 fi -if mount | grep "^/dev/mapper/$EHDD_LUKS_NAME on $EHDD_MOUNTPOINT" >/dev/null; then +if is_mounted; then echo "$EHDD_IMG already mounted" exit 0 fi diff --git a/ehdd/umount.sh b/ehdd/umount.sh index ed11b62a..b9ffc442 100755 --- a/ehdd/umount.sh +++ b/ehdd/umount.sh @@ -2,7 +2,8 @@ . "ehdd/ehdd_funcs.sh" || exit 1 -if ! mount | grep "$EHDD_MOUNTPOINT" >/dev/null; then + +if ! is_mounted; then # not mounted exit 0 fi