#!/bin/bash 
########################################################################
# MuGLIn - MuGLIn GNU/Linux Installation		                       #
#                                                                      #
# Copyright (C) 2010 Jakob Gurnhofer <jakob.gurnhofer@gmail.com>       #
# Copyricht (C) 2010 Srdjan Markovic <smark2ki@htl.moedling.at>        #
#                                                                      #
# This file is part of MuGLIn source code.                             #
#                                                                      #
# MuGLIn 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 3 of the License, or    #
# (at your option) any later version.                                  #
#                                                                      #
# MuGLIn 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 MuGLIn. If not, see <http://www.gnu.org/licenses/>.       #
########################################################################

if [ "`whoami`" != "root" ];then
	echo "I will not run as a non-root user,bye!"
	exit -1;
fi

# Basic config like MODDIR and MODS
. /etc/muglin/base.conf

# Frontend-specifig config - maybe lang?
. /etc/muglin/cli_frontend.conf

GENHELP="MuGLIn - Multicast GNU/Linux Installation
Usage: muglin command [options] [arguments]

Basic Commands:
	help			Show this help
	licence			Show licence informations
"

export HELP

show_help() {
	echo "$GENHELP"
	echo -n "Available modules: "
	echo $MODS 
	for MOD in $MODS; do
		echo ""
		echo "Help for $MOD:"
		$MODDIR/$MOD -h
	done
}

show_lic(){
	cat << GPL_LIC
    MuGLIn GNU/Linux Installation - CLI Frontend
    Version 0.3.5.0 Franky Boy
    
    Copyright (C) 2010 Srdjan Markovic <ism.a@inode.at>
    Copyright (C) 2010 Jakob Gurnhofer <jakob.gurnhofer@gmail.com>

    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 3 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, see <http://www.gnu.org/licenses/>.
GPL_LIC
}

if [ "$1" = "" ]; then
	show_help
	exit
fi

case $1 in
	help|--help|-help|-h) show_help;;
	licence|-v|--version) show_lic;;
	*)
		if [ "`echo $MODS | grep $1`" = "" ]; then
			echo "Modul nicht registriert"
			exit
		fi
		MOD=$1
		shift
		$MODDIR/$MOD "$@"
	;;
esac
