#!/bin/bash

# Copyright (c) 2006 by Springs Rescue Mission. 
# Written by Andrew Ziem with bits borrowed from Henry Burroughs.

# LICENSE
#  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.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# PURPOSE
#  This script sets up LTSP LDA (Local Drive Access) with LtspFS.
#  Specifically, it setups the mounts.
#
# EFFECTS
#  The terminal's disks will be mounted as <~/drives>.
#
# VERSION
#  This script developed for LTSP version 4.1.
#
# INSTALLATION
#  1. Run this script from </usr/share/gnome/default.session>.
#
#  2. Setup $LOCALDEV with proper permissions.  For example:
#      mkdir /mnt/localdev
#      chgrp users /mnt/localdev
#      chmod g+rwx /mnt/localdev
#
#  3. Add each terminal user to the group fuse for Fedora Core 4 (and maybe 
#     other distributions).
#
# NOTE
#  This script runs as a normal (non-root) user.
#
#  Why mount under </mnt> and link to <~/drives>?  If </home>
#  is a NFS file system with root squashing, then you cannot
#  mount directly to <~/drives>.



CLIENT=`echo $DISPLAY | cut -d: -f1 `



### variables (change if desired)
LOCALDEV="/mnt/localdev"
LOCATION="$LOCALDEV/$CLIENT"
### end variables



### main code
if [ ! -d $LOCALDEV ] || [ $CLIENT == "`hostname`" ] || [ "$CLIENT" == "" ] || [ "$CLIENT" == "localhost.localdomain" ]
then
	exit 0
else
	fusermount -u $LOCATION
	[ -d $LOCATION ] && rmdir $LOCATION
	mkdir $LOCATION
	chown $USER $LOCATION
	chmod o= $LOCATION
	ltspfs $CLIENT:/tmp/drives $LOCATION
	ln -sf $LOCATION ~/drives/
fi




