gbde revision 136209
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 136209 2004-10-07 06:00:06Z pjd $ 7# 8 9# PROVIDE: disks 10# KEYWORD: FreeBSD nojail 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 ;; 54 esac 55 56 case "$options" in 57 *noauto*) 58 if checkyesno gbde_autoattach_all; then 59 gbde_devices="${gbde_devices} ${device}" 60 fi 61 ;; 62 *) 63 gbde_devices="${gbde_devices} ${device}" 64 ;; 65 esac 66 ;; 67 esac 68 done <${fstab} 69 70 case "$1" in 71 stop) 72 rm -f ${fstab} 73 ;; 74 esac 75 76 return 0 77} 78 79gbde_start() 80{ 81 for device in $gbde_devices; do 82 parentdev=${device%.bde} 83 parent=${parentdev#/dev/} 84 eval "lock=\${gbde_lock_${parent}-\"${gbde_lockdir}/${parent}.lock\"}" 85 if [ -e "/dev/${parent}" -a ! -e "${device}" ]; then 86 echo "Configuring Disk Encryption for ${device}." 87 88 count=1 89 while [ ${count} -le ${gbde_attach_attempts} ]; do 90 if [ -e "${lock}" ]; then 91 gbde attach ${parentdev} -l ${lock} 92 else 93 gbde attach ${parentdev} 94 fi 95 if [ -e ${device} ]; then 96 break 97 fi 98 echo "Attach failed; attempt ${count} of ${gbde_attach_attempts}." 99 count=$((${count} + 1)) 100 done 101 102 fi 103 done 104} 105 106gbde_stop() 107{ 108 for device in $gbde_devices; do 109 umount ${device} 110 gbde detach ${device%.bde} 111 done 112} 113 114load_rc_config $name 115run_rc_command "$1" 116