#! /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"

moodledir='/var/www/webapps/moodle'
configfilename='config.php'

. shell-error

TEMP=`getopt -n "$PROG" -o m:,n: -l moodledir:,configname: -- "$@"`
eval set -- "$TEMP"

while :; do
	case "$1" in
		--)
			shift
			break
			;;
		-m|--moodledir)
			shift
			moodledir="$1"
			;;
		-n|--configname)
			shift
			configfilename="$1"
			;;
		*) fatal "Unrecognized option: $1"
			;;
	esac
	shift
done

cd "$moodledir"
conf=
if [ -e "$configfilename" ]; then
	conf="$configfilename"

	if [ -L "$conf" ];then
		conf=`readlink "$conf"`
	fi

	printf '%s\n' "$conf"
fi
