]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
- add halt_crypto() from fc initscripts-8.54
authorElan Ruusamäe <glen@pld-linux.org>
Fri, 9 Nov 2007 00:49:07 +0000 (00:49 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Fri, 9 Nov 2007 00:49:07 +0000 (00:49 +0000)
- add standalone mode for start/stop

svn-id: @9025

rc.d/init.d/cryptsetup

index 478f60607d1f52b214830718ae5953b01f81cffb..089549930e953f9e572b362d79f080238d9664fd 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # cryptsetup functions for rc-scripts
-# if invoked standalone, processes /etc/cryptab like on boot.
+# if invoked standalone, processes /etc/cryptab like on boot/shutdown
 
 key_is_random() {
        [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" -o "$1" = "/dev/random" ]
@@ -124,10 +124,50 @@ init_crypto() {
        return $ret
 }
 
-# if invoked directly,
-if [[ "$0" = *cryptsetup ]] && [ -f /etc/crypttab ]; then
-       . /etc/rc.d/init.d/functions
+halt_crypto() {
+    fnval=0
+    while read dst src key; do
+       [ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
+        if [ -b "/dev/mapper/$dst" ]; then
+            if /sbin/dmsetup info "$dst" | grep -q '^Open count: *0$'; then
+                /sbin/cryptsetup remove "$dst"
+            else
+                fnval=1
+            fi
+        fi
+    done < /etc/crypttab
+    return $fnval
+}
+
+# if not invoked directly, return to caller
+if [[ "$0" != *cryptsetup ]] || [ ! -f /etc/crypttab ]; then
+       return
+fi
 
+. /etc/rc.d/init.d/functions
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
        show "Starting disk encryption:"
        init_crypto 1 && ok || fail
-fi
+       ;;
+  stop)
+       show "Stopping disk encryption:"
+       halt_crypto && ok || fail
+       ;;
+  status)
+       # this is way overkill, but at least we have some status output...
+       if fgrep -q dm_crypt /proc/modules; then
+               nls "dm-crypt module is loaded"
+       else
+               nls "dm-crypt module is not loaded"
+       fi
+       ;;
+  *)
+       msg_usage "$0 {start|stop|status}"
+       exit 3
+esac
+
+exit $RETVAL
This page took 0.033339 seconds and 4 git commands to generate.