#!/bin/sh

dir="/var/lib/jack/tmp"
fstype=ramfs
fstab=/etc/fstab
mtab=/etc/mtab
fstab_entry="jacktmp	"$dir"	"$fstype"	defaults	0 0"

mount_jackit_tmpdir()
{
echo -ne "Mounting jack temporary directory...\t"
mount $dir && \
echo "done" || \
{ echo "failed to mount jack temporary directory"; exit 0; }
    if [ -f /etc/rc.d/init.d/jack ]; then
	/bin/sh /etc/rc.d/init.d/jack
    fi    
}

if [ -f $fstab ]; then
echo -ne "Finding jack temporary directory mount point in $fstab...\t"
    if grep -qs "jack" $fstab; then
	if ! grep -qs "$dir" $fstab; then
	    echo "found" 
	    echo "but this entry does not match the one needed by jack"
	    echo "Please add the following line to $fstab manually"
	    echo "$fstab_entry"
	else
	    echo "found"
	    if ! grep -qs "$dir" $mtab; then
	    	mount_jackit_tmpdir
	    fi
	fi
    else
	echo "not found"
	echo -ne "Adding jack temporary directory mount point entry to $fstab...\t"
	echo "$fstab_entry" >> $fstab && \
	echo "done" || \
	{ echo "failed"; exit 0; }
	mount_jackit_tmpdir
    fi
fi
