chiark / gitweb /
Add a --key-file argument to rsbackup-mount
authorMatthew Vernon <matthew.vernon@sac.ac.uk>
Fri, 16 Nov 2012 16:46:24 +0000 (16:46 +0000)
committerRichard Kettlewell <rjk@terraraq.org.uk>
Fri, 16 Nov 2012 21:18:12 +0000 (21:18 +0000)
One might want to store the passphrase for a luks device in a key-file
and then use rsbackup-mount to open and mount said device for backups.
To do this, it would be handy to pass on a --key-file argument to
cryptsetup. This patch does that (and updates the usage message and
manual).

Signed-off-by: Matthew Vernon <matthew@debian.org>

doc/rsbackup-mount.1
tools/rsbackup-mount.in

index 3522060..bc7e81b 100644 (file)
@@ -15,6 +15,9 @@ Unmount devices.
 .B \-\-dry\-run\fR, \fB\-n
 Do nothing, instead print the commands that would be executed.
 .TP
+.B \-\-key\-file \fIPATH\fR, \fB\-k \fIPATH
+Pass the argument \fB\-\-key\-file\fR \fIPATH\fR to \fBcryptsetup\fR.
+.TP
 .B \-\-help\fR, \fB\-h
 Display usage message.
 .TP
index d349592..18231e3 100755 (executable)
@@ -18,6 +18,7 @@ set -e
 
 action=mount
 act=""
+keyfile=""
 
 while [ $# -gt 0 ]; do
   case "$1" in
@@ -29,16 +30,22 @@ while [ $# -gt 0 ]; do
     shift
     act="echo"
     ;;
+  --key-file | -k )
+    shift
+    keyfile="$1"
+    shift
+    ;;
   --help | -h )
     cat <<EOF
 Usage:
   rsbackup-mount [OPTIONS] [--] [DEVICES]
 
 Options:
-  --unmount, -u      Unmount instead of mount
-  --dry-run, -n      Display commands but do nothing
-  --help, -h         Display usage message
-  --version, -V      Display version string
+  --unmount, -u        Unmount instead of mount
+  --dry-run, -n        Display commands but do nothing
+  --key-file, -k PATH  Path to encryption key
+  --help, -h           Display usage message
+  --version, -V        Display version string
 EOF
     exit 0
     ;;
@@ -72,7 +79,11 @@ mount )
     if [ ! -e /dev/mapper/$device ]; then
       uuid=$(eval echo \$${device}_uuid)
       ls -l /dev/disk/by-uuid/$uuid
-      $act cryptsetup luksOpen /dev/disk/by-uuid/$uuid $device
+      if [ -n "$keyfile" ]; then
+        $act cryptsetup luksOpen --key-file "$keyfile" /dev/disk/by-uuid/$uuid $device
+      else
+       $act cryptsetup luksOpen /dev/disk/by-uuid/$uuid $device
+      fi
     fi
     if [ ! -e /$device/device-id ]; then
       $act mount /$device