summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cryptfs.bin.in62
1 files changed, 54 insertions, 8 deletions
diff --git a/cryptfs.bin.in b/cryptfs.bin.in
index 1930ec5..fd172cd 100644
--- a/cryptfs.bin.in
+++ b/cryptfs.bin.in
@@ -75,6 +75,12 @@ mountorder_to_device() {
cut -d' ' -f1
}
+raid_device_to_disk() {
+ printf '%s\n' "${mdadm_conf}" | \
+ grep -F " $1 " | \
+ cut -d' ' -f1
+}
+
crypttab=$(
sed '
s|^\s*#CONF_PREFIXES#\s*||
@@ -103,6 +109,22 @@ fstab=$(
s/ $//
'
)
+mdadm_conf=$(
+ sed '
+ s|^\s*#CONF_PREFIXES#\s*||
+ /^\s*#/d
+ ' #ETCDIR#/mdadm.conf | \
+ sed -n '
+ /^ARRAY / {
+ N
+ s,^ARRAY \(\S\+\) [^\n]\+\n\s*devices=\(\S\+\)$,\1 \2 ,
+ y/,/ /
+ s|UUID=|#UUIDDIR#/|
+ p
+ }
+ ' | \
+ sort -u
+)
mount_details() {
printf '%s\n' "${fstab}" | \
@@ -245,6 +267,14 @@ do_crypt_open() {
fi
}
+do_mdadm_stop() {
+ device="$1"
+ if mdadm --detail "${device}" | \
+ grep -q '^\s*State : \(active\|clean\)\s*$'; then
+ mdadm --stop "${device}"
+ fi
+}
+
printf '%s\n' "${crypttab}" | \
grep -vxF '' | \
while read -r name raw key; do
@@ -257,17 +287,33 @@ printf '%s\n' "${crypttab}" | \
unset key_slot_option
fi
key_mount=$(mountpoint_to_file "${key}")
- mount_order=$(mountorder_to_device "#MAPDIR#/${name}")
-
+ raid_device=$(raid_device_to_disk "#MAPDIR#/${name}")
+ if [ -n "${raid_device}" ]; then
+ mount_order=$(mountorder_to_device "${raid_device}")
+ else
+ mount_order=$(mountorder_to_device "#MAPDIR#/${name}")
+ fi
if ${unmount}; then
- do_unmount "${mount_order}"
- do_crypt_close "${name}"
+ if [ -n "${mount_order}" ]; then
+ printf '0 do_unmount %s\n' "${mount_order}"
+ fi
+ if [ -n "${raid_device}" ]; then
+ printf '1 do_mdadm_stop %s\n' "${raid_device}"
+ fi
+ printf '2 do_crypt_close %s\n' "${name}"
else
- do_mount "${key_mount}"
- do_crypt_open "${name}" "${raw}" "${key}" ${key_slot_option}
- do_unmount -l "${key_mount}"
- do_mount "${mount_order}"
+ printf '0 do_mount %s\n' "${key_mount}"
+ printf '1 do_crypt_open %s\n' "${name} ${raw} ${key} ${key_slot_option}"
+ printf '2 do_unmount -l %s\n' "${key_mount}"
+ if [ -n "${mount_order}" ]; then
+ printf '3 do_mount %s\n' "${mount_order}"
+ fi
fi
+ done | \
+ sort -u | \
+ sort -k1n,1 | \
+ while read -r _ aktion params; do
+ ${aktion} ${params}
done
# End of file