Update.
[scripts.git] / luks_toolbox.sh
index d3d6faa..aed8dc0 100755 (executable)
@@ -27,23 +27,23 @@ $(basename $0) [--help | clean | sync <source file> <dest file> | fsck [-f] <fil
 clean
 
   1. umounts all the volumes using a /dev/dm-* device
-  2. LUKS-close all the volumes appearing in /dev/mapper
+  2. luks-close all the volumes appearing in /dev/mapper
   3. Delete all the loop devices
 
 sync
 
-  Mounts both files as LUKS volumes, runs a dry-run rsync, and asks for
-  interactive confirmation before synchronizing.
+  Mounts both files as luks volumes, runs a dry-run rsync, and asks for
+  interactive confirmation, then rsync.
 
 fsck
 
-  LUKS-open the provided file and run fsck on it.
+  luks-open the provided file and run fsck on it.
 
 mount|umount
 
   Automagically figures out from /etc/fstab what is the /dev/mapper/
-  device associated to the dir, and both LUKS-opens/mounts or
-  umounts/LUKS-closes it.
+  device associated to the dir, and both luks-opens/mounts or
+  umounts/luks-closes it.
 
 EOF
 }
@@ -68,28 +68,23 @@ case $1 in
 
     clean)
 
-        # mount | grep ^'/dev/dm-[0-9]*' | sed -e 's/^.* on \([^ ]*\) .*$/\1/' | \
-
-        mount | grep ^'/dev/mapper' | sed -e 's/^.* on \([^ ]*\) .*$/\1/' | \
-            while read line
-            do
-                echo "umount ${line}"
-                umount ${line}
-            done
-
-        ls /dev/mapper | grep -v ^control$ | \
-            while read line
-            do
-                echo "cryptsetup luksClose ${line[0]}"
-                cryptsetup luksClose "${line[0]}"
-            done
-
-        losetup -a | sed -e "s/:.*$//" | \
-            while read line
-            do
-                echo "losetup -d ${line}"
-                losetup -d ${line}
-            done
+        mount | grep ^'/dev/mapper' | sed -e 's/^.* on \([^ ]*\) .*$/\1/' | while read line
+        do
+            echo "umount ${line}"
+            umount "${line}"
+        done
+
+        find /dev/mapper -type l | while read line
+        do
+            echo "cryptsetup luksClose ${line}"
+            cryptsetup luksClose "${line}"
+        done
+
+        losetup -a | sed -e "s/:.*$//" | while read line
+        do
+            echo "losetup -d ${line}"
+            losetup -d "${line}"
+        done
 
         exit 0
 
@@ -255,7 +250,7 @@ EOF
 
         else
 
-            echo "\`${device}' does not look like a LUKS one"
+            echo "\`${device}' does not look like a luks one"
 
         fi