2003-06-17 02:56:29 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# This file, originally written by Garrett A. Wollman, is in the public
|
|
|
|
# domain.
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: disks
|
2004-10-07 13:55:26 +00:00
|
|
|
# KEYWORD: nojail
|
2003-06-17 02:56:29 +00:00
|
|
|
|
|
|
|
. /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])
|
2004-02-03 10:21:35 +00:00
|
|
|
gbde_devices=""
|
|
|
|
;;
|
2003-06-17 02:56:29 +00:00
|
|
|
*)
|
2004-02-03 10:21:35 +00:00
|
|
|
return 0
|
|
|
|
;;
|
2003-06-17 02:56:29 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
case "$1" in
|
2004-02-03 10:21:35 +00:00
|
|
|
start)
|
|
|
|
fstab="/etc/fstab"
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
fstab=$(mktemp /tmp/mtab.XXXXXX)
|
2003-06-17 02:56:29 +00:00
|
|
|
mount -p >${fstab}
|
2004-02-03 10:21:35 +00:00
|
|
|
;;
|
2003-06-17 02:56:29 +00:00
|
|
|
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)
|
2004-02-03 10:22:55 +00:00
|
|
|
continue
|
|
|
|
;;
|
2003-06-17 02:56:29 +00:00
|
|
|
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
|
2004-02-03 10:21:35 +00:00
|
|
|
stop)
|
|
|
|
rm -f ${fstab}
|
|
|
|
;;
|
2003-06-17 02:56:29 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
gbde_start()
|
|
|
|
{
|
|
|
|
for device in $gbde_devices; do
|
2004-10-07 10:02:46 +00:00
|
|
|
parent=${device%.bde}
|
|
|
|
parent=${parent#/dev/}
|
2004-07-18 18:01:48 +00:00
|
|
|
eval "lock=\${gbde_lock_${parent}-\"${gbde_lockdir}/${parent}.lock\"}"
|
2004-10-07 10:02:46 +00:00
|
|
|
if [ -e "/dev/${parent}" -a ! -e "/dev/${parent}.bde" ]; then
|
|
|
|
echo "Configuring Disk Encryption for ${parent}."
|
2004-07-18 18:01:48 +00:00
|
|
|
|
|
|
|
count=1
|
|
|
|
while [ ${count} -le ${gbde_attach_attempts} ]; do
|
2004-10-06 14:42:35 +00:00
|
|
|
if [ -e "${lock}" ]; then
|
2004-10-07 10:02:46 +00:00
|
|
|
gbde attach ${parent} -l ${lock}
|
2004-10-06 14:42:35 +00:00
|
|
|
else
|
2004-10-07 10:02:46 +00:00
|
|
|
gbde attach ${parent}
|
2004-10-06 14:42:35 +00:00
|
|
|
fi
|
2004-10-07 10:02:46 +00:00
|
|
|
if [ -e "/dev/${parent}.bde" ]; then
|
2004-07-18 18:01:48 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo "Attach failed; attempt ${count} of ${gbde_attach_attempts}."
|
|
|
|
count=$((${count} + 1))
|
|
|
|
done
|
2003-06-17 02:56:29 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
gbde_stop()
|
|
|
|
{
|
|
|
|
for device in $gbde_devices; do
|
2004-10-07 10:02:46 +00:00
|
|
|
parent=${device%.bde}
|
|
|
|
parent=${parent#/dev/}
|
|
|
|
if [ -e "/dev/${parent}.bde" ]; then
|
|
|
|
umount "/dev/${parent}.bde" 2>/dev/null
|
|
|
|
gbde detach "${parent}"
|
|
|
|
fi
|
2003-06-17 02:56:29 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|