]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - etc/rc.d/encswap
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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="encswap"
13 start_cmd="encswap_attach"
14 stop_cmd="encswap_detach"
15
16 encswap_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                         passphrase=`dd if=/dev/random count=1 2>/dev/null | md5 -q`
25                         device="${device%.bde}"
26                         gbde init "${device}" -P "${passphrase}" || return 1
27                         gbde attach "${device}" -p "${passphrase}" || return 1
28                         ;;
29                 *.eli:swap:sw)
30                         device="${device%.eli}"
31                         geli onetime ${geli_swap_flags} "${device}" || return 1
32                         ;;
33                 esac
34         done < /etc/fstab
35 }
36
37 encswap_detach()
38 {
39         while read device mountpoint type options rest ; do
40                 case ":${device}:${type}:${options}" in
41                 :#*)
42                         continue
43                         ;;
44                 *.bde:swap:sw)
45                         device="${device%.bde}"
46                         gbde detach "${device}"
47                         ;;
48                 *.eli:swap:sw)
49                         # Nothing here, because geli swap devices should be
50                         # created with the auto-detach-on-last-close option.
51                         ;;
52                 esac
53         done < /etc/fstab
54 }
55
56 load_rc_config $name
57 run_rc_command "$1"