#!/bin/bash
#

pwd="`pwd`"
path="/usr/src/router/vmware"
disk="$path/linux.dsk"
pidf="$path/linux.dsk.WRITELOCK"
mp="$path/mnt"
sleep=2

qt () { "$@" >/dev/null 2>&1 ; }

if [ $# -lt 1 ]; then
	echo "Usage: `basename $0` <mo|file1 file2 ...>"
	exit 1
fi

if [ -f "$pidf" ]; then
	echo "Diskfile already mounted. Bailing..."
	exit 1
fi

qt vmware-mount.pl $disk 1 -t msdos $mp &
sleep $sleep

if [ ! -f "$pidf" ]; then
	echo "Mounting process failed. Bailing..."
	exit 1
fi

if [ "$1" == "mo" ]; then
	echo "Mounted on $mp."
	echo
	echo "Press 'enter' to unmount..."
	read null
else
	cp $@ $mp/
fi

pid="$(cat $pidf)"
set -- $(ps lh $pid)
ppid="$4"

kill -2 $ppid


