#! /usr/bin/env bash

#
# zenoss_init_pre
#
# This script is intended to be run before the zenoss processes have
# been started for the first time.
#
# Note: it is run by root
#

#############################################################################
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2007, Zenoss Inc.
#
# 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.
#
# For complete information please visit: http://www.zenoss.com/oss/
#############################################################################
# environment variable
export OS_USERNAME="**OS_USERNAME**"
export OS_UID="**OS_UID**"
export ZENHOME="**ZENHOME**"
export MYSQLHOST="**MYSQL_HOST**"
export MYSQLROOTUSER="**MYSQL_ROOT_USERNAME**"
export MYSQLROOTPASSWD="**MYSQL_ROOT_PASSWD**"
export MYSQLUSER="**MYSQL_USERNAME**"
export MYSQLPASS="**MYSQL_PASSWD**"
export MYSQLEVENTDB="**MYSQL_DATABASE**"
export ZOPEPASSWORD="**ZOPE_PASSWD**"
export ZOPEHOME="**ZOPEHOME**"

# load the installation functions
. ${ZENHOME}/bin/shared-functions.sh
. ${ZENHOME}/bin/install-functions.sh

# create the log directory
mkdir -p ${ZENHOME}/log

# restart external server daemons
restart_snmpd
restart_mysql

# copy the etc/*.conf.example files to etc/*.conf if etc/*.conf don't
# already exist (we don't want to clobber people's configs)
update_conf_files

# create the events mysql database
create_database

# populate the events database
run_zeneventbuild

# set up the zope instance
run_mkzopeinstance

# create the zeodb instance
run_mkzeoinstance

# create the zeo database
start_zeodb
chown -R ${OS_USERNAME} ${ZENHOME}/var
run_zenbuild
stop_zeodb
