[arch-projects] [RFC 07/23] Add support for -U, the unmap operation

Matthew Monaco dgbaley27 at 0x01b.net
Fri May 18 12:22:01 EDT 2012


From: Matthew Monaco <matthew.monaco at 0x01b.net>

Without any arguments, use crypttab. Otherwise try to unmap whatever is
given on the command line. This does not support automatically unmapping
volumes which are not in crypttab.

One FIXME might be that when using crypttab, volumes should be handled
in the reverse order.
---
 cryptmount.sh |   44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/cryptmount.sh b/cryptmount.sh
index 47b3ac6..bdfd1a1 100755
--- a/cryptmount.sh
+++ b/cryptmount.sh
@@ -151,7 +151,13 @@ ct_main() {
 
 	elif [ "$action" = "unmap" ]; then
 
-		:
+		if [ $# -gt 0 ]; then
+			[ "$FILTER" != "!noauto" ] && \
+				info "Filters from -O are ignored in this mode"
+			unset FILTER
+		fi
+
+		ct_main_unmap "$@"
 
 	elif [ "$action" = "map" ]; then
 
@@ -165,6 +171,25 @@ ct_main() {
 	fi
 }
 
+ct_main_unmap() {
+
+	if [ $# -eq 0 ]; then
+
+		ct_read_crypttab ct_unmap
+
+	else
+
+		local vol ret=0
+
+		for vol in "$@"; do
+			ct_unmap "$vol" || ret=$(( ret+1 ))
+		done
+
+		return $ret
+
+	fi
+}
+
 
 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #
 #                                                                              #
@@ -273,6 +298,23 @@ ct_check_filter() {
 	return 0
 }
 
+# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #
+#                                                                              #
+#  Mapping, unmapping, finding stuff                                           #
+#                                                                              #
+
+ct_unmap() {
+	local name="$1"
+	if [ ! -e "/dev/mapper/$name" ]; then
+		warn "Volume was not mapped (no '/dev/mapper/$name')"
+	elif run cryptsetup remove "$name"; then
+		info "$name unmapped"
+	else
+		error "failed to unmap $name"
+		false
+	fi
+}
+
 #                                                                              #
 # ---------------------------------------------------------------------------- #
 
-- 
1.7.10.2



More information about the arch-projects mailing list