2005-06-13 20:46:07 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# a simple wrapper around cryptdisks to:
|
|
|
|
# mount after cryptsetup
|
|
|
|
# umount before cryptsetup
|
|
|
|
|
|
|
|
# break on error or undefined variables
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
|
|
crypt_mount()
|
|
|
|
{
|
|
|
|
local partitions=`dmsetup ls | grep -v "No devices found" | cut -f1`
|
|
|
|
for i in $partitions; do
|
2005-06-17 00:48:37 +02:00
|
|
|
if mount | grep -q "^/dev/mapper/$i$"; then
|
|
|
|
#if [ `mount | grep -c /dev/mapper/$i` -lt 1 ]; then
|
2005-06-14 11:34:52 +02:00
|
|
|
echo -en "\t$i(mounting)"
|
|
|
|
mount "/dev/mapper/$i" &>/dev/null || echo -en "(failed)" >&2
|
|
|
|
else echo -en "\t$i(already mounted)"
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
done
|
2005-06-13 20:46:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
crypt_umount()
|
|
|
|
{
|
|
|
|
local partitions=`dmsetup ls | grep -v "No devices found" | cut -f1`
|
|
|
|
for i in $partitions; do
|
2005-06-17 00:48:37 +02:00
|
|
|
if mount | grep -q "^/dev/mapper/$i$"; then
|
|
|
|
#if [ `mount | grep -c /dev/mapper/$i` -gt 0 ]; then
|
2005-06-14 11:34:52 +02:00
|
|
|
echo -en "\t$i (unmounting)"
|
|
|
|
umount "/dev/mapper/$i" &>/dev/null || echo -en "(failed!)" >&2
|
|
|
|
else echo -en "\t$i(not mounted)"
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
show_active_mappings()
|
|
|
|
{
|
|
|
|
mappings=`dmsetup ls | cut -f1`
|
|
|
|
if [ "X$mappings" != "X" ]; then
|
|
|
|
echo "there are still some active mappings:"
|
|
|
|
echo "$mappings"
|
|
|
|
fi
|
2005-06-13 20:46:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
########### do it! ##############
|
|
|
|
|
|
|
|
ACTION=help
|
|
|
|
[ $# -gt 0 ] && ACTION="$1"
|
|
|
|
|
|
|
|
case "$ACTION" in
|
|
|
|
start|retry )
|
|
|
|
/etc/init.d/cryptdisks start
|
|
|
|
crypt_mount
|
|
|
|
;;
|
|
|
|
stop )
|
|
|
|
crypt_umount
|
|
|
|
/etc/init.d/cryptdisks stop
|
2005-06-14 11:34:52 +02:00
|
|
|
show_active_mappings
|
2005-06-13 20:46:07 +02:00
|
|
|
;;
|
|
|
|
restart|reload|force-reload )
|
|
|
|
$0 stop
|
|
|
|
$0 start
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "Syntax: `basename $0` { start | stop | restart | retry | reload | force-reload | help }"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|