First commit

This commit is contained in:
Yorick Barbanneau 2016-07-30 20:27:08 +02:00
commit aee895f1dd
2 changed files with 110 additions and 0 deletions

36
README.md Normal file
View file

@ -0,0 +1,36 @@
Mount_FreeBSD_encimg
--------------------
A small script utility to mount encrypted image disk in FreeBSD / FreeNAS then
execute desired services
this script is inspired by one you can find [here][L_nlsr]
# Customize
First you'll need to customize a little for your need, there 3 variables to
modify :
* IMAGE_DISK : full path to your disk image
* MOUNT_PATH : full path to your mount point
* SERVICES : services you want to start after mounting image.
# Example
I want to mount my image ``/data/backup_drive.img`` to ``/var/spool/burp/``
then start burp service. Here is all three variables :
~~~sh
DISK_IMAGE="/data/backup_drive.img"
MOUNT_POINT="/var/spool/burp/"
SERVICES="burp"
~~~
Then, i just need to launch the script then prey there is no bug ;-)
~~~
#mount.sh mount
~~~
done!
[L_nlsr]:http://www.nlrs.fr/2011/09/17/encrypted-share-geli/

74
mount.sh Executable file
View file

@ -0,0 +1,74 @@
#!/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