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

wwwroot=
wwwrootproto=
wwwrootsitename=
wwwrootport=
wwwrootpath=

. shell-error

TEMP=`getopt -n "$PROG" -o -p:,s:,m: -l wwwrootproto:,wwwrootsitename:,wwwrootport:,wwwrootpath: -- "$@"`
eval set -- "$TEMP"

while :; do
	case "$1" in
		--)
			shift
			break
			;;
		-p|--wwwrootproto)
			shift
			wwwrootproto="$1"
			;;
		-s|--wwwrootsitename)
			shift
			wwwrootsitename="$1"
			;;
		--wwwrootport)
			shift
			wwwrootport="$1"
			;;
		-m|--wwwrootpath)
			shift
			wwwrootpath="$1"
			;;
		*) fatal "Unrecognized option: $1"
			;;
	esac
	shift
done

wwwroot="${wwwrootproto:+$wwwrootproto://}$wwwrootsitename${wwwrootport:+:$wwwrootport}${wwwrootpath:+/$wwwrootpath}"

printf "%s\n" "$wwwroot"
