#! /bin/sh -efu

#
# Moodle install tools
#
# @package   mt-install
# @copyright 2012 Aleksey Avdeev <solo@altlinux.ru>
# @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
#

PROG="${0##*/}"

PATH="/usr/sbin:$PATH"

dbtype=

. shell-error

TEMP=`getopt -n "$PROG" -o t: -l dbtype: -- "$@"`
eval set -- "$TEMP"

while :; do
	case "$1" in
		--)
			shift
			break
			;;
		-t|--dbtype)
			shift
			dbtype="$1"
			;;
		*) fatal "Unrecognized option: $1"
			;;
	esac
	shift
done

script="$1"
shift

if [ -n '$dbtype' ]; then
	case "$dbtype" in
		mysqli)
			db='MySQL'
			;;
		*) fatal "Unrecognized dbtype: $1"
			;;
	esac

	script=`printf "%s" $script \
		| sed -rn "s@^((/usr/sbin/)?mt-)DB(-[^[:space:]]+)[[:space:]]*\\$@\\1$db\\3@p"`
fi

exec $script $@
