summaryrefslogtreecommitdiffstats
path: root/etc/rc.d
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>2003-06-17 02:56:29 +0000
committerwollman <wollman@FreeBSD.org>2003-06-17 02:56:29 +0000
commit9b4e9335cf4206880e0662c2e5b2d4ec205b3d88 (patch)
treeb7f2cb69ee0e94d8b83eacedfb778acbf7b00fcd /etc/rc.d
parent2896b67c141d60d5d93fd2cc89648de2eb03fdb5 (diff)
downloadFreeBSD-src-9b4e9335cf4206880e0662c2e5b2d4ec205b3d88.zip
FreeBSD-src-9b4e9335cf4206880e0662c2e5b2d4ec205b3d88.tar.gz
Add a script to automatically attach gbde devices found in fstab
(or rc.conf) at boot time, and detach them when shutting down. Not added to the Makefile to give the rcng gurus an opportunity to improve it.
Diffstat (limited to 'etc/rc.d')
-rw-r--r--etc/rc.d/gbde92
1 files changed, 92 insertions, 0 deletions
diff --git a/etc/rc.d/gbde b/etc/rc.d/gbde
new file mode 100644
index 0000000..900afc7
--- /dev/null
+++ b/etc/rc.d/gbde
@@ -0,0 +1,92 @@
+#!/bin/sh
+#
+# This file, originally written by Garrett A. Wollman, is in the public
+# domain.
+#
+# $FreeBSD$
+#
+
+# PROVIDE: disks
+# KEYWORD: FreeBSD
+
+. /etc/rc.subr
+
+name="gbde"
+start_precmd="find_gbde_devices start"
+stop_precmd="find_gbde_devices stop"
+start_cmd="gbde_start"
+stop_cmd="gbde_stop"
+
+find_gbde_devices()
+{
+ case "${gbde_devices-auto}" in
+ [Aa][Uu][Tt][Oo])
+ gbde_devices="";;
+ *)
+ return 0;;
+ esac
+
+ case "$1" in
+ start) fstab="/etc/fstab";;
+ stop) fstab=$(mktemp /tmp/mtab.XXXXXX)
+ mount -p >${fstab}
+ esac
+
+ #
+ # We can't use "mount -p | while ..." because when a shell loop
+ # is the target of a pipe it executes in a subshell, and so can't
+ # modify variables in the script.
+ #
+ while read device mountpt type options dump pass; do
+ case "$device" in
+ *.bde)
+ # Ignore swap devices
+ case "$type" in
+ swap)
+ continue;;
+ esac
+
+ case "$options" in
+ *noauto*)
+ if checkyesno gbde_autoattach_all; then
+ gbde_devices="${gbde_devices} ${device}"
+ fi
+ ;;
+ *)
+ gbde_devices="${gbde_devices} ${device}"
+ ;;
+ esac
+ ;;
+ esac
+ done <${fstab}
+
+ case "$1" in
+ stop) rm -f ${fstab};;
+ esac
+
+ return 0
+}
+
+gbde_start()
+{
+ for device in $gbde_devices; do
+ parentdev=${device%.bde}
+ parent=${parentdev#/dev/}
+ eval "lock=\${gbde_lock_${parent}-\"/etc/${parent}.lock\"}"
+ if [ -e $lock ]; then
+ echo "Configuring Disk Encryption for ${device}."
+ gbde attach ${parentdev} -l ${lock}
+ fi
+ done
+}
+
+gbde_stop()
+{
+ for device in $gbde_devices; do
+ umount ${device}
+ gbde detach ${device%.bde}
+ done
+}
+
+load_rc_config $name
+run_rc_command "$1"
OpenPOWER on IntegriCloud