#!/bin/sh
#---------------------------------------------------------------
# Project         : Mandrake Linux
# Module          : mountloop
# File            : mountloop.sh
# Version         : $Id: mountloop.sh,v 1.3 2002/12/27 23:33:24 flepied Exp $
# Author          : Frederic Lepied
# Created On      : Thu Jun  6 20:55:29 2002
#---------------------------------------------------------------

if [ ! -r $HOME/.mountlooprc ]; then
    exit 0
fi

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
		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
	    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

# mountloop.sh ends here
