#!/bin/bash DEVICE="sda4" MAPPER="hd_encrypt" MOUNT="/home" MODULES="dm_crypt sha256 aes_i586" if [ "$1" != "close" ]&&[ "$1" != "open" ]&&[ "$1" != "status" ]; then echo "Usage: $0 " exit 0 fi if [ "$1" == "close" ]; then if [ ! -b "/dev/mapper/$MAPPER" ]; then echo "Nothing to close, /dev/mapper/$MAPPER is not present" exit 0 fi /sbin/fuser -k $MOUNT 1>/dev/null 2>/dev/null /bin/umount $MOUNT /sbin/cryptsetup luksClose $MAPPER echo "Home unmounted" fi if [ "$1" == "open" ]; then if [ -b "/dev/mapper/$MAPPER" ]; then echo "/dev/mapper/$MAPPER already exists" echo "try: $0 close" exit 0 fi echo -e "\nLoading luks/crypt modules" modprobe -a $MODULES echo "Attempting to mount $MOUNT:" /sbin/cryptsetup luksOpen /dev/$DEVICE $MAPPER if [ ! -b "/dev/mapper/$MAPPER" ]; then echo "Unable to mount \"$MOUNT\" !" else mount /dev/mapper/$MAPPER $MOUNT echo "Home has been mounted!" fi fi if [ "$1" == "status" ]; then if [ -b "/dev/mapper/$MAPPER" ]; then stat1="Initialized Encryption: /dev/mapper/$MAPPER" else stat1="Uninitialized Encryption: /dev/mapper/$MAPPER" fi stat2=`mount |grep $MOUNT |grep -o $MAPPER` if [ "$stat2" == "$MAPPER" ]; then stat2="Mounted Device: /dev/$DEVICE on $MOUNT" else stat2="Mounted Device: None" fi /sbin/cryptsetup luksDump /dev/$DEVICE echo -e "\n$stat1\n$stat2\n" fi