From 7768ced57e0a7bc67f72dce24af3f4b57724e45c Mon Sep 17 00:00:00 2001 From: Christopher Spinrath Date: Tue, 17 Jul 2018 17:09:52 +0200 Subject: [PATCH] VeraCrypt: verschiebe Programmlogik aus Shell- in Python-Skript --- veracrypt/verausbdrive.py | 14 +++++++++++++- veracrypt/verausbdrive.sh.example | 17 +---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/veracrypt/verausbdrive.py b/veracrypt/verausbdrive.py index cac5224..67a7143 100755 --- a/veracrypt/verausbdrive.py +++ b/veracrypt/verausbdrive.py @@ -141,12 +141,24 @@ def __main(): container_name = args[ARG_CONTAINER_NAME] container = os.path.join(usbdrive, container_name) + if not os.path.exists(usbdrive): + print(":: USB partition mount point \"{}\" doesn't exist. Ignoring request.".format(usbdrive)) + return + if args[ARG_VERA_DISMOUNT]: - vera_unmount(volume) + if os.path.exists(volume): + vera_unmount(volume) + else: + print(":: VeraCrypt mount point \"{}\" doesn't exist. Skipping unmount!".format(volume)) + if args[ARG_UNMOUNT_USB_DRIVE]: unmount_usbdrive(usbdrive) return + if os.path.exists(volume): + print(":: VeraCrypt mount point \"{}\" already exists! Assuming container is already mounted.".format(volume)) + return + vera_mount(volume, container) if __name__ == '__main__': diff --git a/veracrypt/verausbdrive.sh.example b/veracrypt/verausbdrive.sh.example index 5646dca..9e13786 100755 --- a/veracrypt/verausbdrive.sh.example +++ b/veracrypt/verausbdrive.sh.example @@ -16,24 +16,9 @@ PYTHON_VERA_WRAPPER_BIN=~/ls1-misc/veracrypt/verausbdrive.py set -e -USB_DRIVE_MOUNT_PATH="$MOUNT_PATH/$USB_DRIVE_PART_NAME" -VERA_MOUNT_PATH="$MOUNT_PATH/$VERA_DRIVE_NAME" - -if [ ! -d "$USB_DRIVE_MOUNT_PATH" ] -then - echo "USB drive partition not mounted; ignoring request." - exit 0 -fi - -if [ -d "$VERA_MOUNT_PATH" ] -then - echo "Verascript drive name already in use; assuming the container is already mounted." - exit 0 -fi - MY_BASEPATH="$(dirname "$PYTHON_VERA_WRAPPER_BIN")" MY_BINARY="$(basename "$PYTHON_VERA_WRAPPER_BIN")" pushd "$MY_BASEPATH" > /dev/null - pipenv run ./"$MY_BINARY" -m "$MOUNT_PATH" -v "$VERA_DRIVE_NAME" -n "$USB_DRIVE_PART_NAME" "$VERA_CONTAINER_PATH_REL" + pipenv run ./"$MY_BINARY" -m "$MOUNT_PATH" -v "$VERA_DRIVE_NAME" -n "$USB_DRIVE_PART_NAME" "$VERA_CONTAINER_PATH_REL" $@ popd > /dev/null