codekasten/spielspass/dmcrypt-wrapper.sh

59 lines
1.1 KiB
Bash
Raw Normal View History

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-14 02:15:26 +02:00
if mount | grep -q "^/dev/mapper/$i "
2005-06-13 20:53:26 +02:00
then true
else echo -e "\t$i (mounting)"
2005-06-13 20:49:19 +02:00
mount "/dev/mapper/$i" &>/dev/null || echo -e " (\"mount /dev/mapper/$i\" failed)" >&2
2005-06-13 20:46:07 +02:00
fi
done
}
crypt_umount()
{
local partitions=`dmsetup ls | grep -v "No devices found" | cut -f1`
for i in $partitions; do
2005-06-14 02:15:26 +02:00
if mount | grep -q "^/dev/mapper/$i "
2005-06-13 20:53:26 +02:00
then echo -e "\t$i (unmounting)"
2005-06-13 20:49:19 +02:00
umount "/dev/mapper/$i" &>/dev/null || echo -e " (\"umount /dev/mapper/$i\" failed)" >&2
2005-06-13 20:46:07 +02:00
fi
done
}
########### 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
;;
restart|reload|force-reload )
$0 stop
$0 start
;;
* )
echo "Syntax: `basename $0` { start | stop | restart | retry | reload | force-reload | help }"
;;
esac