gbde revision 136193
1116456Swollman#!/bin/sh 2116456Swollman# 3116456Swollman# This file, originally written by Garrett A. Wollman, is in the public 4116456Swollman# domain. 5116456Swollman# 6116456Swollman# $FreeBSD: head/etc/rc.d/gbde 136193 2004-10-06 14:42:35Z pjd $ 7116456Swollman# 8116456Swollman 9116456Swollman# PROVIDE: disks 10126744Spjd# KEYWORD: FreeBSD nojail 11116456Swollman 12116456Swollman. /etc/rc.subr 13116456Swollman 14116456Swollmanname="gbde" 15116456Swollmanstart_precmd="find_gbde_devices start" 16116456Swollmanstop_precmd="find_gbde_devices stop" 17116456Swollmanstart_cmd="gbde_start" 18116456Swollmanstop_cmd="gbde_stop" 19116456Swollman 20116456Swollmanfind_gbde_devices() 21116456Swollman{ 22116456Swollman case "${gbde_devices-auto}" in 23116456Swollman [Aa][Uu][Tt][Oo]) 24125384Sdes gbde_devices="" 25125384Sdes ;; 26116456Swollman *) 27125384Sdes return 0 28125384Sdes ;; 29116456Swollman esac 30116456Swollman 31116456Swollman case "$1" in 32125384Sdes start) 33125384Sdes fstab="/etc/fstab" 34125384Sdes ;; 35125384Sdes stop) 36125384Sdes fstab=$(mktemp /tmp/mtab.XXXXXX) 37116456Swollman mount -p >${fstab} 38125384Sdes ;; 39116456Swollman esac 40116456Swollman 41116456Swollman # 42116456Swollman # We can't use "mount -p | while ..." because when a shell loop 43116456Swollman # is the target of a pipe it executes in a subshell, and so can't 44116456Swollman # modify variables in the script. 45116456Swollman # 46116456Swollman while read device mountpt type options dump pass; do 47116456Swollman case "$device" in 48116456Swollman *.bde) 49116456Swollman # Ignore swap devices 50116456Swollman case "$type" in 51116456Swollman swap) 52125385Sdes continue 53125385Sdes ;; 54116456Swollman esac 55116456Swollman 56116456Swollman case "$options" in 57116456Swollman *noauto*) 58116456Swollman if checkyesno gbde_autoattach_all; then 59116456Swollman gbde_devices="${gbde_devices} ${device}" 60116456Swollman fi 61116456Swollman ;; 62116456Swollman *) 63116456Swollman gbde_devices="${gbde_devices} ${device}" 64116456Swollman ;; 65116456Swollman esac 66116456Swollman ;; 67116456Swollman esac 68116456Swollman done <${fstab} 69116456Swollman 70116456Swollman case "$1" in 71125384Sdes stop) 72125384Sdes rm -f ${fstab} 73125384Sdes ;; 74116456Swollman esac 75116456Swollman 76116456Swollman return 0 77116456Swollman} 78116456Swollman 79116456Swollmangbde_start() 80116456Swollman{ 81116456Swollman for device in $gbde_devices; do 82116456Swollman parentdev=${device%.bde} 83116456Swollman parent=${parentdev#/dev/} 84132356Ssimon eval "lock=\${gbde_lock_${parent}-\"${gbde_lockdir}/${parent}.lock\"}" 85136193Spjd if [ ! -e "${device}" ]; then 86116456Swollman echo "Configuring Disk Encryption for ${device}." 87132356Ssimon 88132356Ssimon count=1 89132356Ssimon while [ ${count} -le ${gbde_attach_attempts} ]; do 90136193Spjd if [ -e "${lock}" ]; then 91136193Spjd gbde attach ${parentdev} -l ${lock} 92136193Spjd else 93136193Spjd gbde attach ${parentdev} 94136193Spjd fi 95132356Ssimon if [ -e ${device} ]; then 96132356Ssimon break 97132356Ssimon fi 98132356Ssimon echo "Attach failed; attempt ${count} of ${gbde_attach_attempts}." 99132356Ssimon count=$((${count} + 1)) 100132356Ssimon done 101132356Ssimon 102116456Swollman fi 103116456Swollman done 104116456Swollman} 105116456Swollman 106116456Swollmangbde_stop() 107116456Swollman{ 108116456Swollman for device in $gbde_devices; do 109116456Swollman umount ${device} 110116456Swollman gbde detach ${device%.bde} 111116456Swollman done 112116456Swollman} 113116456Swollman 114116456Swollmanload_rc_config $name 115116456Swollmanrun_rc_command "$1" 116