Saturday, January 17, 2009

#!/bin/sh
#####################################################
# simple script that will mount/umount
# encrypted partition using cryptsetup/LUKS.
# how to setup such partition can be found
# at:
# http://www.spmalloy.com/howto/linux-cryptofs.html
# ###################################################

#####################################################
# edit this part accordingly - start #
# mount directory. in this example it's '/edata'
md=edata
# partition
partition=sda6
# edit - end
#####################################################

if df |grep -q '/'$md'$'
then
echo "Found mount point, umount it [y/n]?"
wrongEntry=1
while [ $wrongEntry == "1" ]
do
read answer
clear
if [ $answer == "y" ]
then
sudo umount /$md
sudo cryptsetup luksClose $partition
wrongEntry=0
elif [ $answer == "n" ]
then
wrongEntry=0
else
echo "enter 'y' or 'n'. try again.."
fi
done
else

echo "Disk is not mounted. Mount it now?"
wrongEntry=1
while [ $wrongEntry == "1" ]
do
read answer
if [ $answer == "y" ]
then
sudo cryptsetup luksOpen /dev/$partition $partition
sudo mount /dev/mapper/$partition /$md/
wrongEntry=0
elif [ $answer == "n" ]
then
wrongEntry=0
else
echo "enter 'y' or 'n'. try again.."
fi
done

fi

exit 0