freebsd-skq/etc/rc.d/gbde
simon 0fcf2627f6 For the gbde attach script:
- Ask the user up to X times (3 by default) for the pass-phrase, if
  it is incorrect the first time.
- Add support for storing the lockfiles in another other directory
  than /etc.
- Document that it is possible to override the location of each single
  lockfile.

Approved by:	pjd
2004-07-18 18:01:48 +00:00

112 lines
1.8 KiB
Bash

#!/bin/sh
#
# This file, originally written by Garrett A. Wollman, is in the public
# domain.
#
# $FreeBSD$
#
# PROVIDE: disks
# KEYWORD: FreeBSD nojail
. /etc/rc.subr
name="gbde"
start_precmd="find_gbde_devices start"
stop_precmd="find_gbde_devices stop"
start_cmd="gbde_start"
stop_cmd="gbde_stop"
find_gbde_devices()
{
case "${gbde_devices-auto}" in
[Aa][Uu][Tt][Oo])
gbde_devices=""
;;
*)
return 0
;;
esac
case "$1" in
start)
fstab="/etc/fstab"
;;
stop)
fstab=$(mktemp /tmp/mtab.XXXXXX)
mount -p >${fstab}
;;
esac
#
# We can't use "mount -p | while ..." because when a shell loop
# is the target of a pipe it executes in a subshell, and so can't
# modify variables in the script.
#
while read device mountpt type options dump pass; do
case "$device" in
*.bde)
# Ignore swap devices
case "$type" in
swap)
continue
;;
esac
case "$options" in
*noauto*)
if checkyesno gbde_autoattach_all; then
gbde_devices="${gbde_devices} ${device}"
fi
;;
*)
gbde_devices="${gbde_devices} ${device}"
;;
esac
;;
esac
done <${fstab}
case "$1" in
stop)
rm -f ${fstab}
;;
esac
return 0
}
gbde_start()
{
for device in $gbde_devices; do
parentdev=${device%.bde}
parent=${parentdev#/dev/}
eval "lock=\${gbde_lock_${parent}-\"${gbde_lockdir}/${parent}.lock\"}"
if [ -e "${lock}" -a ! -e "${device}" ]; then
echo "Configuring Disk Encryption for ${device}."
count=1
while [ ${count} -le ${gbde_attach_attempts} ]; do
gbde attach ${parentdev} -l ${lock}
if [ -e ${device} ]; then
break
fi
echo "Attach failed; attempt ${count} of ${gbde_attach_attempts}."
count=$((${count} + 1))
done
fi
done
}
gbde_stop()
{
for device in $gbde_devices; do
umount ${device}
gbde detach ${device%.bde}
done
}
load_rc_config $name
run_rc_command "$1"