#!/bin/sh

#       mountiso
#       
#       Copyright 2009 Raphael Michel <webmaster@raphaelmichel.de>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.


echo "Skript zum Ein- und Aushängen von Datenträger-Images..."
if [ $# = 0 ] ; then
	echo "..::[ Hilfe ]::.."
	echo "mountiso.sh hängt per mount -o loop ein Datenträger-Image ein."
	echo "~~+ Nutzung +~~"
	echo "$ mountiso parameter1 [parameter2]"
	echo "	1. Parameter:"
	echo "		(leer)	Ruft diese Hilfe auf. Erfordert keinen 2. Parameter."
	echo "		u	Hängt eine eingehängte Datei wieder aus. 2. Parameter muss den Einhängepunkt enthalten."
	echo "		...	1. Parameter ist die einzuhängende Datei, 2. Parameter der Einhängepunkt."
	echo "	2. Parameter:"
	echo "		Wenn nicht angegeben: /media/iso0"
	exit 0;
fi

if [ $1 = "u" ] ; then
	if [ -n "$2" ] ; then
		echo "Hänge $2 aus..."
		sudo umount $2
	else
		echo "Hänge /media/iso0 aus..."
		sudo umount /media/iso0
	fi
	if [ $? -ne 0 ]
	then
		echo "Aushängen schlug fehl!" >&2
		exit 1
	fi
else
	if [ -n "$2" ] ; then
		echo "Hänge $1 in $2 ein..."
		sudo mount -o loop $1 $2
	else
		echo "Hänge $1 in /media/iso0 ein..."
		sudo mount -o loop $1 /media/iso0
	fi
	if [ $? -ne 0 ]
	then
		echo "Einhängen schlug fehl!" >&2
		exit 1
	fi
fi
echo "OK"
exit 0

