#!/bin/bash

# Copyright (C) Big-Cat Software Association, 2007.
#
# GILDE project.
# (Graphical Interfaces to Learn Debian Easily)
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. Please read the COPYING file.
#

#USERLOCALPREFIX=$(kde-config --localprefix)

if [ -d "$HOME"/.kencfs2 ]; then
  echo "User specific directories for K-EncFS are present"
else
  mkdir "$HOME"/.kencfs2
  mkdir "$HOME"/.kencfs2/encrypted
fi

if [ -d "$HOME"/.kencfs2/encrypted ]; then
  echo "User specific encrypted directory for K-EncFS present"
else
  mkdir "$HOME"/.kencfs2/encrypted
fi

FUSERMOUNT=`which fusermount`;
ENCFS=`which encfs`;

if test "$FUSERMOUNT"; then
    if test "$ENCFS"; then
        FUSEINSERTED=`lsmod | grep "fuse "`;
        if test "$FUSEINSERTED"; then
            python /usr/lib/kencfs2/kencfs.py
        else
            sudo modprobe fuse
            FUSEINSERTABLE=`lsmod | grep "fuse "`;
            if test "$FUSEINSERTABLE"; then
                python /usr/lib/kencfs2/kencfs.py
            else
                echo 'The kernel module fuse is missing. Please compile and install it before unless it is compiled into the kernel image!'
                python /usr/lib/kencfs2/kencfs.py
            fi
        fi
    else
        kdialog --caption "Missing encfs" --error 'The encfs utility is missing. Please install it before!'
    fi
else
    kdialog --caption "Missing fusermount" --error 'The fusermount utility is missing. Please install it before!'
fi
