74 lines
2 KiB
Bash
Executable file
74 lines
2 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Script to mount encrypted disk image in FreeBSD
|
|
|
|
DISK_IMAGE="/test.img"
|
|
MOUNT_POINT="/mnt/test"
|
|
SERVICES=""
|
|
|
|
if [ -e $DISK_IMAGE ]
|
|
then
|
|
echo "Image disk not found, exiting."
|
|
exit 1
|
|
fi
|
|
|
|
case $0 in
|
|
m|mount)
|
|
echo "mount $MOUNT_POINT"
|
|
mdconfig -a -t vnode -f $DISK_IMAGE -u 0 > /dev/null
|
|
geli attach -d /dev/md0 > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
mount /dev/md0.eli $MOUNT_POINT
|
|
if [ $? -neq 0 ]
|
|
then
|
|
for i in $SERVICES
|
|
do
|
|
service $i one start
|
|
if [ $? -neq 0 ]
|
|
then
|
|
echo something gone wrong when starting $i
|
|
fi
|
|
done
|
|
else
|
|
echo "I can't mount..."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "Something wrong happen, did you give me the good password?"
|
|
mdconfig -d -u 0
|
|
exit 1
|
|
fi
|
|
;;
|
|
u|unmount)
|
|
for i in $SERVICES
|
|
do
|
|
echo "stop $i service ..."
|
|
service $i onestop
|
|
if [ $? -neq 0 ]
|
|
then
|
|
echo "can't stop $i service then unmount $MOUNT_POINT exiting ..."
|
|
exit 1
|
|
fi
|
|
done
|
|
echo "unmount $MOUNT_POINT ..."
|
|
umount $MOUNT_POINT > /dev/null
|
|
mdconfig -d -u 0 > /dev/null
|
|
if [ $? ] && [ ! -e /dev/md0 ] && [ ! -e /dev/md0.eli ] && [ `ls $clear | wc -l` ]
|
|
then
|
|
echo 'Everything clean'
|
|
else
|
|
echo 'Some ressources are still present, please check'
|
|
fi
|
|
;;
|
|
*)
|
|
echo "what is this argument? We don't speak the same language..."
|
|
echo "USAGE"
|
|
echo "mount.sh [mount|umount]"
|
|
echo "mount / umount an encrypted image and axecute dependent services"
|
|
echo "modify MOUNT_POINT and IMAGE_DISK variables then add services"
|
|
echo "to SERVICES."
|
|
exit 1
|
|
|
|
esac
|
|
exit 0
|