#!/usr/bin/bash
#
# Copyright (C) 2014 Oracle. All rights reserved.
#
# 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, version 2.  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
# 021110-1307, USA.

SYSCONFIG=/etc/sysconfig/ovm-template-initial-config
INITIAL_CONFIG=
DELETE_INITIAL_CONFIG_PARAMS=
RETVAL=0

[ -f $SYSCONFIG ] && . $SYSCONFIG

if [ "$INITIAL_CONFIG" != "yes" ]; then
    exit 0
fi

# Wait for other services to finish to keep the console clean.
sleep 5

[ -x /usr/bin/plymouth ] && /usr/bin/plymouth --hide-splash

echo -e "\nOracle VM template initial configure:\n"
ovmd -s configure
RETVAL=$?

if [ $RETVAL -eq 0 ]; then
    sed -i 's/^INITIAL_CONFIG=.*/INITIAL_CONFIG=no/g' $SYSCONFIG
fi

if [ "$DELETE_INITIAL_CONFIG_PARAMS" = "yes" ]; then
    /usr/sbin/ovmd -x
fi

[ -x /usr/bin/plymouth ] && /usr/bin/plymouth --show-splash

exit $RETVAL
