#!/bin/sh
#---------------------------------------------------------------
# Project         : Mandriva Linux
# Module          : mountloop
# File            : mountloop.sh
# Version         : $Id: mountloop.sh 145743 2005-11-14 14:04:39Z tvignaud $
# Author          : Frederic Lepied
# Created On      : Thu Jun  6 20:55:29 2002
#---------------------------------------------------------------
# Comment for Xsession:
# to be sourced
#---------------------------------------------------------------

PATH=$PATH:/usr/lib/ssh

if [ -r $HOME/.mountlooprc ]; then
    while read enc file dir onstart; do
        if [ -r "$HOME/$file" -a -d "$HOME/$dir" -a "$onstart" != no ] && ! grep -q "$dir" /proc/mounts > /dev/null 2>&1; then
    	times=3
    	while [ $times -gt 0 ]; do
	    
    	    if [ -n "$DISPLAY" ] && type ssh-askpass > /dev/null 2>&1; then
    		xsetroot -cursor_name left_ptr
    		( ssh-askpass "Enter passphrase for mounting $file on $dir using $enc ($times try)" ; echo $? > $HOME/.ssh-askpass.button) | /usr/bin/mountloop "$enc" "$HOME/$file" "$HOME/$dir"
		MOUNTLOOPEC=$?
		ASKPASS=`cat $HOME/.ssh-askpass.button` && rm -f $HOME/.ssh-askpass.button
		if [ $ASKPASS != 0 ]; then break; fi
    	    else
    		/usr/bin/mountloop "$enc" "$HOME/$file" "$HOME/$dir" < /dev/tty
		MOUNTLOOPEC=$?
    	    fi
    	    
    	    if [ $MOUNTLOOPEC != 0 ]; then
    		times=`expr $times - 1`
    	    else
    		break
    	    fi
    	done
        fi
    done < $HOME/.mountlooprc
    
    if [ -n "$DISPLAY" ]; then
        (/usr/X11R6/bin/xwait
        
        while read enc file dir onstart; do
    	if [ -d "$HOME/$dir" ] && grep -q "$HOME/$dir" /proc/mounts > /dev/null 2>&1; then
    	    umountloop "$HOME/$dir"
    	fi
        done < $HOME/.mountlooprc
        )&
    fi
fi

# mountloop.sh ends here
