gbde revision 125384
1#!/bin/sh
2#
3# This file, originally written by Garrett A. Wollman, is in the public
4# domain.
5#
6# $FreeBSD: head/etc/rc.d/gbde 125384 2004-02-03 10:21:35Z des $
7#
8
9# PROVIDE: disks
10# KEYWORD: FreeBSD
11
12. /etc/rc.subr
13
14name="gbde"
15start_precmd="find_gbde_devices start"
16stop_precmd="find_gbde_devices stop"
17start_cmd="gbde_start"
18stop_cmd="gbde_stop"
19
20find_gbde_devices()
21{
22	case "${gbde_devices-auto}" in
23	[Aa][Uu][Tt][Oo])
24		gbde_devices=""
25		;;
26	*)
27		return 0
28		;;
29	esac
30
31	case "$1" in
32	start)
33		fstab="/etc/fstab"
34		;;
35	stop)
36		fstab=$(mktemp /tmp/mtab.XXXXXX)
37		mount -p >${fstab}
38		;;
39	esac
40
41	#
42	# We can't use "mount -p | while ..." because when a shell loop
43	# is the target of a pipe it executes in a subshell, and so can't
44	# modify variables in the script.
45	#
46	while read device mountpt type options dump pass; do
47		case "$device" in
48		*.bde)
49			# Ignore swap devices
50			case "$type" in
51			swap)
52				continue;;
53			esac
54
55			case "$options" in
56			*noauto*)
57				if checkyesno gbde_autoattach_all; then
58					gbde_devices="${gbde_devices} ${device}"
59				fi
60				;;
61			*)
62				gbde_devices="${gbde_devices} ${device}"
63				;;
64			esac
65			;;
66		esac
67	done <${fstab}
68
69	case "$1" in
70	stop)
71		rm -f ${fstab}
72		;;
73	esac
74
75	return 0
76}
77
78gbde_start()
79{
80	for device in $gbde_devices; do
81		parentdev=${device%.bde}
82		parent=${parentdev#/dev/}
83		eval "lock=\${gbde_lock_${parent}-\"/etc/${parent}.lock\"}"
84		if [ -e $lock ]; then
85			echo "Configuring Disk Encryption for ${device}."
86			gbde attach ${parentdev} -l ${lock}
87		fi
88	done
89}
90
91gbde_stop()
92{
93	for device in $gbde_devices; do
94		umount ${device}
95		gbde detach ${device%.bde}
96	done
97}
98
99load_rc_config $name
100run_rc_command "$1"
101