#!/bin/bash
# Script to mount .xzm module
# This script is called from konqueror servicemenu
# Author: Brokenman  <brokenman@porteus.org>

path=${1}
mod=${2}
name=${mod%.*}
l=/mnt/loop
xfile=${mod}
x=`ls -1 /dev/loop* | awk -F/ '{print$3}' | tr -d [:alpha:] | sort -n | tail -n1`
lp=$(($x+1))

start_work(){

[ -d /mnt/loop ] || mkdir /mnt/loop
# Make a new loop
mknod /dev/loop$lp b 7 $lp
mount -no loop $path/$mod $l

kdialog --msgbox "$mod has been mounted at /mnt/loop \n\n You can unmount with: umount /mnt/loop"
exit
}

usage(){
echo
echo "Usage: mount-module /path/to/module.xzm"
echo
echo "Mounts chosen module at /mnt/loop"
echo "The module files can then be accessed"
echo
echo "This script is also called by right clicking"
echo "on a module and using the 'module actions'"
exit
}

if [ "$1" == "" -o "$1" == "-h" -o "$1" == "--help" ]; then
	usage
		else
	start_work
fi

exit