]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/encswap
Add an rc script for powerd(8).
[FreeBSD/FreeBSD.git] / etc / rc.d / encswap
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # PROVIDE: disks
7 # REQUIRE: initrandom
8 # KEYWORD: nojail
9
10 . /etc/rc.subr
11
12 name="gbde_swap"
13 start_cmd="gbde_swap_attach"
14 stop_cmd="gbde_swap_detach"
15
16 gbde_swap_attach()
17 {
18         while read device mountpoint type options rest ; do
19                 case ":${device}:${type}:${options}" in
20                 :#*)
21                         continue
22                         ;;
23                 *.bde:swap:sw)
24                         ;;
25                 *)
26                         continue
27                         ;;
28                 esac
29                 passphrase=`dd if=/dev/random count=1 2>/dev/null | md5 -q`
30                 device="${device%.bde}"
31                 gbde init "${device}" -P "${passphrase}" || return 1
32                 gbde attach "${device}" -p "${passphrase}" || return 1
33         done < /etc/fstab
34 }
35
36 gbde_swap_detach()
37 {
38         while read device mountpoint type options rest ; do
39                 case ":${device}:${type}:${options}" in
40                 :#*)
41                         continue
42                         ;;
43                 *.bde:swap:sw)
44                         ;;
45                 *)
46                         continue
47                         ;;
48                 esac
49                 device="${device%.bde}"
50                 gbde detach "${device}"
51         done < /etc/fstab
52 }
53
54 load_rc_config $name
55 run_rc_command "$1"