From aee895f1ddfa4eb7472e7746101c16a795c85a16 Mon Sep 17 00:00:00 2001 From: Yorick Date: Sat, 30 Jul 2016 20:27:08 +0200 Subject: [PATCH] First commit --- README.md | 36 +++++++++++++++++++++++++++ mount.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 README.md create mode 100755 mount.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6a8593 --- /dev/null +++ b/README.md @@ -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/ diff --git a/mount.sh b/mount.sh new file mode 100755 index 0000000..a4555d8 --- /dev/null +++ b/mount.sh @@ -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