From 72dd60ff9f47be5ef600ff53c39a80a4f03a6fd1 Mon Sep 17 00:00:00 2001 From: Thomas Koehler Date: Thu, 3 Feb 2011 16:38:40 +0100 Subject: [PATCH] if no mountpoint was given to action start, create a default one --- grml-crypt | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/grml-crypt b/grml-crypt index b9f0f26..d45a787 100755 --- a/grml-crypt +++ b/grml-crypt @@ -83,8 +83,8 @@ ACTIONS: Format a device or a file (is created with the given size if it does not exist) with the given filesystem and mount it, if a mountpoint was given. - start - Mount the device/file in the mountpoint. + start [mountpoint] + Mount the device/file in the mountpoint or to a default mountpoint. stop Umount the given mountpoint (umount, luksClose, losetup -d) @@ -166,13 +166,13 @@ function actionStart { ret_=0 - # no mountpoint, by-by if [[ "$MOUNT_POINT_" == "" ]]; then - printUsage - die 'no mountpoint given' - fi - if [ ! -d "$MOUNT_POINT_" ]; then - die "mountpoint $MOUNT_POINT_ does not exist" + MOUNT_POINT_="/mnt/$DM_NAME_" + else + # error out if mountpoint was given but doesn't exist + if [ ! -d "$MOUNT_POINT_" ]; then + die "mountpoint $MOUNT_POINT_ does not exist" + fi fi # removed due to unionfs problem isLuks does not work with filesystem images # without losetup @@ -198,6 +198,10 @@ function actionStart fi margs_="" $READONLY_SET_ && margs_='-r' + # mountpoint was not given so we use the default one which we need to create first + if [ ! -d "$MOUNT_POINT_" ]; then + execute "mkdir -p '$MOUNT_POINT_'" || die "failed to create mountpoint $MOUNT_POINT_" + fi execute "mount $margs_ $ADDITIONAL_MOUNT_ARGS_ $DM_PATH_ $MOUNT_POINT_" die } @@ -240,6 +244,9 @@ function actionStop dprint "device_=\"$device_\"" execute "umount $dm_path_" die "could not unmount $device_" + if [[ "$MOUNT_POINT_" == "/mnt/$dm_name_" ]]; then + rmdir "$MOUNT_POINT_" + fi execute "$CRYPTSETUP_ luksClose $dm_name_" die "could not close $dm_path_" echo "$device_" |grep loop &>/dev/null && execute "losetup -d $device_" \ die "could not delete loop device $device_" || \ -- 2.1.4