[Grml-devel] [Patches] grml-crypt: if no mountpoint was given to action start, create a default one

Thomas Köhler jean-luc at picard.franken.de
Thu Feb 3 16:57:59 CET 2011


Hello all,

After discussing with gebi, I've just implemented the "create
a default mountpoint if none was given to action start" feature
in a better way than in bc3a3b852c2e7dddb0ffe3a6f9650f95b1a15593.
Just forget about the previous approach and consider applying
this series of patches instead :-)

Bye,
Thomas

-- 
 Thomas Köhler       Email:       jean-luc at picard.franken.de
     <><             WWW:              http://gott-gehabt.de
                     IRC:                           tkoehler
                     PGP public key available from Homepage!
-------------- next part --------------
From 6328766cb37449a34bcb7115d40622cff7187f1d Mon Sep 17 00:00:00 2001
From: Thomas Koehler <jean-luc at picard.franken.de>
Date: Thu, 3 Feb 2011 16:38:40 +0100
Subject: [PATCH 1/3] if no mountpoint was given to action start, create a default one

---
 grml-crypt |   23 +++++++++++++++--------
 1 files 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  <device/file> <mountpoint>
-              Mount the device/file in the mountpoint.
+   start  <device/file> [mountpoint]
+              Mount the device/file in the mountpoint or to a default mountpoint.
    stop   <mountpoint>
               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_" || \
-- 
1.7.2.3

-------------- next part --------------
From 1a10fb381a923bd786a197d4ad768c5cbca44575 Mon Sep 17 00:00:00 2001
From: Thomas Koehler <jean-luc at picard.franken.de>
Date: Thu, 3 Feb 2011 16:44:11 +0100
Subject: [PATCH 2/3] updated documentation for previous patch

---
 grml-crypt.8.txt |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/grml-crypt.8.txt b/grml-crypt.8.txt
index 1ff290d..43be27d 100644
--- a/grml-crypt.8.txt
+++ b/grml-crypt.8.txt
@@ -32,9 +32,9 @@ ACTIONS
     Commands: [losetup], dd, cryptsetup luksFormat, cryptsetup
     luksOpen, [dd], mkfs, [mount]
 
-*start <device/file> <mountpoint>*::
+*start <device/file> [mountpoint]*::
     Starts an encrypted <device/file> and mounts it to the given
-    mountpoint. Commands: [losetup], cryptsetup luksOpen, mount
+    or a default mountpoint. Commands: [losetup], cryptsetup luksOpen, mount
 
 *stop <mountpoint>*::
     Stops an encrypted filesystem mounted at <mountpoint>. Even the
-- 
1.7.2.3

-------------- next part --------------
From b9eac823606eb19a3ead7490d2caea0dacbd49bf Mon Sep 17 00:00:00 2001
From: Thomas Koehler <jean-luc at picard.franken.de>
Date: Thu, 3 Feb 2011 16:56:01 +0100
Subject: [PATCH 3/3] bugfix: throw in a "udevadm settle" to avoid occasional failing mount attempts

---
 grml-crypt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/grml-crypt b/grml-crypt
index d45a787..7722474 100755
--- a/grml-crypt
+++ b/grml-crypt
@@ -202,6 +202,7 @@ function actionStart
   if [ ! -d "$MOUNT_POINT_" ]; then
     execute "mkdir -p '$MOUNT_POINT_'" || die "failed to create mountpoint $MOUNT_POINT_"
   fi
+  udevadm settle
   execute "mount $margs_ $ADDITIONAL_MOUNT_ARGS_ $DM_PATH_ $MOUNT_POINT_" die
 }
 
-- 
1.7.2.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://ml.grml.org/pipermail/grml-devel/attachments/20110203/031226e4/attachment.pgp>


More information about the Grml-devel mailing list