[Grml-devel] Patch to grml-crypt

Thomas Köhler jean-luc at picard.franken.de
Thu Nov 10 17:52:58 CET 2011


Hello all,

Thomas Köhler wrote:
> Attached patch will add another feature to this if there is a
> third -F option: It will get the next commandline option and
> passes it to fsck as additional options.

Just sending the first patch, I found a bug in this new feature
which I fixed using attached patch #2.

After a short discussion on IRC, I came to the conclusion that
mrud was right to propose another option for passing additional
arguments to fsck, so I changed -F to -X (which cleans up the
getopts part at the same time). So this is patch #3.

> For example
> grml-crypt -FFF "-y -T" /dev/ice
> will pass "-y -T" to the (forced) fsck.

That would now (all 3 patches applied) be
grml-crypt -F "-y -T" /dev/ice
or
grml-crypt -FF "-y -T" /dev/ice
to pass "-y -T" to fsck (forced in the second form).

bye,
Thomas

-- 
 Thomas Köhler       Email:       jean-luc at picard.franken.de
     <><             WWW:              http://gott-gehabt.de
                     IRC: tkoehler       Freenode: thkoehler
                     PGP public key available from Homepage!
-------------- next part --------------
From 00882c92a69b405752b08d00a815cab39a63fd05 Mon Sep 17 00:00:00 2001
From: Thomas Koehler <jean-luc at picard.franken.de>
Date: Thu, 10 Nov 2011 17:19:28 +0100
Subject: [PATCH 1/3] If given a third time, -F will pass the next argument as additional arguments to fsck.

---
 grml-crypt |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/grml-crypt b/grml-crypt
index 7722474..3e740f1 100755
--- a/grml-crypt
+++ b/grml-crypt
@@ -36,6 +36,7 @@ ACTION_=""
 DM_PREFIX_="grml-crypt_"
 FORCE_='false'
 FSCK_='false'
+FSCK_EXTRA_OPTS_=""
 ENTROPY_SOURCE_='/dev/urandom'
 OPTIMIZED_MODE_SET_='false'
 OPTIMIZING_LEVEL_=0
@@ -67,7 +68,10 @@ OPTIONS:
    -o         optimised initialisation mode (should be as secure as the default but faster)
    -y         verifies the passphrase by asking for it twice
    -f         force file overwriting in format mode and/or disable confirmation dialog
-   -F         only for action start: run fsck before mounting the filesystem. Use fsck's -f option if given twice.
+   -F         only for action start: run fsck before mounting the filesystem.
+              Use fsck's -f option if given twice.
+              Read next argument as a list of options to pass to fsck if given three times:
+              'grml-crypt -FFF "-y -T" start /dev/ice' will run fsck with options -y and -T.
    -m         additional arguments to mount
    -v         verbose (show what is going on, v++)
    -h         this help text
@@ -194,7 +198,7 @@ function actionStart
   if [[ "$FSCK_" == "true" ]] ; then
     execute "fsck -C $DM_PATH_" || die "fsck failed on $DM_PATH_"
   elif [[ "$FSCK_" == "trueforce" ]] ; then
-    execute "fsck -f -C $DM_PATH_" || die "fsck failed on $DM_PATH_"
+    execute "fsck -f $FSCK_EXTRA_OPTS_ -C $DM_PATH_" || die "fsck failed on $DM_PATH_"
   fi
   margs_=""
   $READONLY_SET_ && margs_='-r'
@@ -389,7 +393,12 @@ while getopts "s:t:rzoyfFm:hvS:C:I:A:" opt; do
     F) if [[ "$FSCK_" == "true" ]] ; then
          FSCK_='trueforce'
        else
-         FSCK_='true'
+         if [[ "$FSCK_" == "trueforce" ]] ; then
+           FSCK_EXTRA_OPTS_="$2"
+           shift
+         else
+           FSCK_='true'
+         fi
        fi
       ;;
     m) ADDITIONAL_MOUNT_ARGS_="$OPTARG" ;;
-- 
1.7.2.3

-------------- next part --------------
From cd33b341cb5f2ef6b210eb8d3f843e377bc80d4d Mon Sep 17 00:00:00 2001
From: Thomas Koehler <jean-luc at picard.franken.de>
Date: Thu, 10 Nov 2011 17:33:24 +0100
Subject: [PATCH 2/3] Bugfix: getopts handling was wrong with -FFF if another argument came first.

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

diff --git a/grml-crypt b/grml-crypt
index 3e740f1..8ed9249 100755
--- a/grml-crypt
+++ b/grml-crypt
@@ -394,7 +394,7 @@ while getopts "s:t:rzoyfFm:hvS:C:I:A:" opt; do
          FSCK_='trueforce'
        else
          if [[ "$FSCK_" == "trueforce" ]] ; then
-           FSCK_EXTRA_OPTS_="$2"
+           eval "FSCK_EXTRA_OPTS_=\"\$$OPTIND\""
            shift
          else
            FSCK_='true'
-- 
1.7.2.3

-------------- next part --------------
From 0294c76313c7cf21a997b012933fc7f0d9e1b693 Mon Sep 17 00:00:00 2001
From: Thomas Koehler <jean-luc at picard.franken.de>
Date: Thu, 10 Nov 2011 17:45:43 +0100
Subject: [PATCH 3/3] remove -F "third time" logic, add -X instead

---
 grml-crypt |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/grml-crypt b/grml-crypt
index 8ed9249..5bcd12e 100755
--- a/grml-crypt
+++ b/grml-crypt
@@ -70,8 +70,8 @@ OPTIONS:
    -f         force file overwriting in format mode and/or disable confirmation dialog
    -F         only for action start: run fsck before mounting the filesystem.
               Use fsck's -f option if given twice.
-              Read next argument as a list of options to pass to fsck if given three times:
-              'grml-crypt -FFF "-y -T" start /dev/ice' will run fsck with options -y and -T.
+   -X         Read next argument as a list of options to pass to fsck:
+              'grml-crypt -FF -X "-y -T" start /dev/ice' will run fsck with options -y and -T.
    -m         additional arguments to mount
    -v         verbose (show what is going on, v++)
    -h         this help text
@@ -196,7 +196,7 @@ function actionStart
   execute "$CRYPTSETUP_ $cargs_ luksOpen $TARGET_ $DM_NAME_" warn || execute "losetup -d $TARGET_" || \
     die "could not luksOpen $TARGET_"
   if [[ "$FSCK_" == "true" ]] ; then
-    execute "fsck -C $DM_PATH_" || die "fsck failed on $DM_PATH_"
+    execute "fsck $FSCK_EXTRA_OPTS_ -C $DM_PATH_" || die "fsck failed on $DM_PATH_"
   elif [[ "$FSCK_" == "trueforce" ]] ; then
     execute "fsck -f $FSCK_EXTRA_OPTS_ -C $DM_PATH_" || die "fsck failed on $DM_PATH_"
   fi
@@ -378,7 +378,7 @@ function actionFormat
 ### __MAIN
 ###
 
-while getopts "s:t:rzoyfFm:hvS:C:I:A:" opt; do
+while getopts "s:t:rzoyfFm:hvS:C:I:A:X:" opt; do
   case "$opt" in
     s) SIZE_="$OPTARG"; SIZE_SET_='true' ;;
     t) FSTYPE_="$OPTARG" ;;
@@ -393,14 +393,10 @@ while getopts "s:t:rzoyfFm:hvS:C:I:A:" opt; do
     F) if [[ "$FSCK_" == "true" ]] ; then
          FSCK_='trueforce'
        else
-         if [[ "$FSCK_" == "trueforce" ]] ; then
-           eval "FSCK_EXTRA_OPTS_=\"\$$OPTIND\""
-           shift
-         else
-           FSCK_='true'
-         fi
+         FSCK_='true'
        fi
       ;;
+    X) FSCK_EXTRA_OPTS_="$OPTARG" ;;
     m) ADDITIONAL_MOUNT_ARGS_="$OPTARG" ;;
     h) printUsage; exit ;;
     v) let verbose_=$verbose_+1 ;;
-- 
1.7.2.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://ml.grml.org/pipermail/grml-devel/attachments/20111110/0ced29d7/attachment.pgp>


More information about the Grml-devel mailing list