#!/bin/bash

if [ "`whoami`" != 'root' ]
then
    echo You need to run this script as user "root"
    exit 1
fi

PATH=/usr/sbin:$PATH

export ENSTORE_DIR=`rpm -ql enstore | head -1`
export PYTHON_DIR=$ENSTORE_DIR/Python
export PYTHONINC=`ls -d ${PYTHON_DIR}/include/python*`
export PYTHONLIB=`ls -d ${PYTHON_DIR}/lib/python*`
export PATH=${PYTHON_DIR}/bin:${PATH}
set PYTHONPATH="./"
for p in ${ENSTORE_DIR}/src \
	 ${ENSTORE_DIR}/modules \
	 ${ENSTORE_DIR}/HTMLgen 	
do	
	PYTHONPATH=${PYTHONPATH}:${p}
done

export PYTHONPATH

chmod +x web_server.py
chmod +x make_enstore_system.py

./web_server.py --install

if [ $? != 0 ];
then
	exit 1 
fi

./make_enstore_system.py 

rc=$?

if [ ${rc} == 2 ]; then
    systemctl is-enabled httpd.service
    if [ $? -ne 0 ]; then
	systemctl disable httpd.service
    fi
    exit 0
elif  [ ${rc} == 0 ]; then
    systemctl enable httpd.service
    systemctl start httpd.service
    exit 0
else 
    exit 1
fi

exit 0 
