#!/bin/bash
#
# MOLMAKE -- This program starts up Make One Linux setup
# Copyright (C) 2005-2007 Keicho Kondo <dgel@users.sourceforge.jp>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

## === Setup Environment === ##
CONFIG_ROOT="/etc/mol"

# load libmolmake
if which libmolmake >/dev/null; then
	. libmolmake
else
	echo "<< Can't find libmolmake. >>" >/dev/stderr
	exit 1
fi

# load config files
load_molmake_config $CONFIG_ROOT

# allow only root account
check_user_account

# check variables whether it is filled or not
check_variable BUILD_ROOT $BUILD_ROOT

# set cmd output option
OPTION=
case $* in *--line*) OPTION="--line $OPTION";; esac
case $* in *--log*) OPTION="--log $OPTION";; esac

## Check options
case "$*" in
	*--help*)
	echo "MOLMAKE (Make One Linux) $MOL_VERSION"
	echo " (C)2005-2007 Keicho Kondo <dgel@users.sourceforge.jp>"
	echo
	echo "This program starts up Make One Linux setup."
	echo "Usage: molmake <option>"
	echo
	echo "   --clean         : Clean up files made by this script"
	echo "   --help          : Show this help"
	echo "   --version       : Show version and notice"
	echo
	echo "   --line          : Show running command line"
	echo "   --log           : Output log in $BUILD_ROOT/log"
	echo
	exit 0 ;;

	*--version*)
	echo "MOLMAKE (Make One Linux) $MOL_VERSION"
	echo "Written by Keicho Kondo."
	echo
	echo "Copyright (C) 2005-2007 Keicho Kondo."
	echo "This is free software; see the source for copying conditions.  There is NO"
	echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
	echo
	exit 0 ;;

	*--clean*)
	molmake-iso --clean
	molmake-modules --clean
	molmake-initramfs --clean
	exit 0 ;;
esac


## === Start === ##
echo "${MAGENTA}<-- ${RED}Make ${CYAN}One ${GREEN}Linux ${BLUE}Setup Starting ${MAGENTA}-->${NORMAL}"
echo
echo

## Execute script files
echo "${MAGENTA}<- ${BLUE}Stage 1 ${MAGENTA}->${NORMAL}"
molmake-initramfs $OPTION
echo
echo "${MAGENTA}<- ${BLUE}Stage 2 ${MAGENTA}->${NORMAL}"
molmake-modules $OPTION
echo
echo "${MAGENTA}<- ${BLUE}Stage 3 ${MAGENTA}->${NORMAL}"
molmake-iso $OPTION
echo
echo


## === fin. === ##
echo "${MAGENTA}<-- ${RED}Make ${CYAN}One ${GREEN}Linux ${BLUE}Setup Finished ${MAGENTA}-->${NORMAL}"
exit 0

