summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/gbde_swap
blob: e839249d4f92da9cb76c5af442370cce5ca1d9ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: disks
# REQUIRE: initrandom
# KEYWORD: FreeBSD nojail

. /etc/rc.subr

name="gbde_swap"
start_cmd="gbde_swap_attach"
stop_cmd="gbde_swap_detach"

gbde_swap_attach()
{
	cat /etc/fstab |
	while read device mountpoint type options rest ; do
		case "${device}:${type}:${options}" in
		*.bde:swap:sw)
			;;
		*)
			continue
			;;
		esac
		passphrase=`dd if=/dev/random count=1 2>/dev/null | md5 -q`
		device="${device%.bde}"
		gbde init "${device}" -P "${passphrase}" || return 1
		gbde attach "${device}" -p "${passphrase}" || return 1
	done
}

gbde_swap_detach()
{
	cat /etc/fstab |
	while read device mountpoint type options rest ; do
		case "${device}:${type}:${options}" in
		*.bde:swap:sw)
			;;
		*)
			continue
			;;
		esac
		device="${device%.bde}"
		gbde detach "${device}"
	done
}

load_rc_config $name
run_rc_command "$1"
OpenPOWER on IntegriCloud