#! /bin/bash

if [[ -z "$(lsmod | awk '{print $1}' | grep ecryptfs)" ]]; then
    echo "The ecryptfs module must be loaded first. Run,

    # modprobe ecryptfs" | fmt -w66
    exit 1
fi

setup_cmd="ecryptfs-setup-private"
mount_cmd="ecryptfs-mount-private"
umount_cmd="ecryptfs-umount-private"
if [[ ! $(which "$setup_cmd") ]] 2> /dev/null || [[ ! $(which "$mount_cmd") ]] 2> /dev/null || [[ ! $(which "$umount_cmd") ]] 2> /dev/null; then
    echo "It does not appear that you have the ecryptfs utility package installed. In Debianoids (Debian, Ubuntu, Mint, Crunchbang) and in Arch Linux, at least, this package is called ecryptfs-utils." | fmt -w66
fi



print_usage="false"
while getopts smu name; do
    case $name in
        s)  $setup_cmd;;
        m)  $mount_cmd;;
        u)  $umount_cmd;;
        h)  print_usage="true";;
    esac
done

[[ "x$print_usage" = "xtrue" ]] && echo "Usage: $0 (-s|-m|-u)

    -s  Setup private ecryptfs.

    -m  Mount private ecryptfs in ~/Private
    
    -u  Unmount private ecryptfs from ~/Private" | fmt -w66
