Browse Source

Add the `-k' option to read a passphrase from a key file

master
Peter J. Jones 8 months ago
parent
commit
f40d1e70d0
Signed by: Peter Jones <pjones@devalot.com> GPG Key ID: 9DAFAA8D01941E49
1 changed files with 17 additions and 3 deletions
  1. 17
    3
      bin/mount-encrypted-dev

+ 17
- 3
bin/mount-encrypted-dev View File

@@ -1,4 +1,8 @@
1
-#!/bin/sh -eu
1
+#!/bin/bash
2
+
3
+################################################################################
4
+set -e
5
+set -u
2 6
 
3 7
 ################################################################################
4 8
 usage () {
@@ -10,6 +14,7 @@ Usage: $(basename "$0") -u <mount-point>
10 14
 Unmount encrypted device at <mount-point>
11 15
 
12 16
 Options:
17
+  -k FILE Read key from FILE
13 18
   -u      Unmount instead of mount
14 19
   -r      Mount read-only
15 20
   -G GID  Mount with group ID set to GID
@@ -28,13 +33,18 @@ do_mount () {
28 33
   encdevice=$1
29 34
   options=""
30 35
   map="$(basename "$encdevice")_crypt"
36
+  cryptsetup_flags=()
37
+
38
+  if [ -n "$keyfile" ] && [ -e "$keyfile" ]; then
39
+    cryptsetup_flags+=("--key-file" "$keyfile")
40
+  fi
31 41
 
32 42
   if [ -n "$mount_options" ]; then
33 43
     options="-o$mount_options"
34 44
   fi
35 45
 
36 46
   echo "==> mapping encrypted partition, enter disk password"
37
-  do_cmd cryptsetup luksOpen "$encdevice" "$map"
47
+  do_cmd cryptsetup "${cryptsetup_flags[@]}" luksOpen "$encdevice" "$map"
38 48
 
39 49
   echo "==> mounting mapped encdevice to $point"
40 50
   do_cmd mount "${options:--orw}" "/dev/mapper/$map" "$point"
@@ -71,10 +81,14 @@ append_mount_option() {
71 81
 mount_options=""
72 82
 mount_option_count=0
73 83
 unmount="NO"
84
+keyfile=""
74 85
 
75 86
 ################################################################################
76
-while getopts "hG:U:ru" o; do
87
+while getopts "hk:G:U:ru" o; do
77 88
   case "${o}" in
89
+    k) keyfile="$OPTARG"
90
+       ;;
91
+
78 92
     u) unmount="YES"
79 93
        ;;
80 94
 

Loading…
Cancel
Save