#!/bin/sh
#---------------------------------------------------------------
# Project         : Mandrakelinux
# Module          : mountloop
# File            : mountloop.sh
# Version         : $Id: mountloop.sh,v 1.9 2004/03/25 14:43:04 flepied Exp $
# 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
    mount=0
    while read enc file dir fstype; do
        if [ -r "$file" -a -d "$dir" ] && ! 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)" | /usr/bin/mountloop "$enc" "$file" "$dir" $fstype
    	    else
    		/usr/bin/mountloop "$enc" "$file" "$dir" $fstype < /dev/tty
    	    fi
    	    
    	    if [ $? != 0 ]; then
    		times=`expr $times - 1`
    	    else
    		mount=`expr $mount + 1`
    		break
    	    fi
    	done
        fi
    done < $HOME/.mountlooprc
    
    if [ -n "$DISPLAY" -a $mount -gt 0 ]; then
        (/usr/X11R6/bin/xwait
        
        while read enc file dir fstype; do
    	if [ -d "$dir" ] && grep -q "$dir" /proc/mounts > /dev/null 2>&1; then
    	    umountloop "$dir"
    	fi
        done < $HOME/.mountlooprc
        )&
    fi
fi

# mountloop.sh ends here
