#!/bin/sh
#script to log out of servers
#Read in config file
source ./login.cfg

DEBUG=echo
#DEBUG=:

#remove empty mount points
#[ "$(ls -A ../H)" ] && echo "Not Empty" || echo "Empty"

#or
#DIR="/tmp"
# init
# look for empty dir
#if [ "$(ls -A $DIR)" ]; then
#     echo "Take action $DIR is not Empty"
#else
#    echo "$DIR is Empty"
#fi
# rest of the logic

echo ""

echo "+-------- Current CIFS Connections -------+"
mount |grep cifs | grep ${USER}
echo "+-----------------------------------------+"
echo""
echo "+--------- Current SSH_FS Connections ----+"
mount |grep sshfs | grep ${USER}
echo "+-----------------------------------------+"
echo""


#disconnect all resources
$DEBUG "Umounting cifs"
/sbin/umount.cifs ${HOME}/I > 2&>1
/sbin/umount.cifs ${HOME}/J > 2&>1

$DEBUG "Umounting sshfs"
/usr/bin/fusermount -u ${HOME}/H > 2&>1

$DEBUG "Destroying Desktop icons"
#delete desktop icons ending with .cifs.desktop, these were created at login
rm $HOME/Desktop/*.cifs.desktop > 2&>1

#delete desktop icons ending with .sshfs.desktop, these were created at login
rm $HOME/Desktop/*.sshfs.desktop > 2&>1


exit 0

#New stuff to do a better job of unmounting filesystems.

#SMB logout
logout_cifs() {

}

#SSH logout
logout_sshfs()
{

}

#Netware logout
logout_ncp()
{

}




# Loop though the arrays and mount each using the login_* functions.
for (( I=0; $I < ${#LOGIN_SERVER[*]}; I++ )); do
  logout_${LOGIN_FSTYPE[$I]} $I
  if [ $? -ne 0 ]; then
    echo "Mount error, wrong fs type maybe?"
    exit 1
  fi
done





exit 0


