#!/bin/csh -f
#

set INST_PATH = /var/www/html/Backburner

set SELINUX_CONF = /etc/sysconfig/selinux
set HTTPD = /etc/httpd
set HTTPD_AUTH = ${HTTPD}/auth
set HTTPD_CONF = ${HTTPD}/conf
set INST_FLASH = /usr/discreet/backburner/WebMonitor
set DST_CGI = /var/www/cgi-bin/Backburner

# Install password file if not there
if ( ! -e ${HTTPD_AUTH}/backburner.auth ) then
    mkdir -p ${HTTPD_AUTH}
    cp -f ${INST_FLASH}/backburner.auth ${HTTPD_AUTH}/backburner.auth
    chown root.root ${HTTPD_AUTH}/backburner.auth 
endif

# Install account directory for persistence
if ( ! -e ${DST_CGI}/account ) then
    mkdir -p ${DST_CGI}/account
    chown apache ${DST_CGI}/account
endif

# Clean white space '\n' first
cat ${INST_FLASH}/flashmonitor_httpd_conf | tr -d '\n' > /tmp/flash_conf
cat ${HTTPD_CONF}/httpd.conf | tr -d '\n' > /tmp/httpd_conf

# Check if the backburner authentication is already configured in httpd
grep -q "`cat /tmp/flash_conf`" /tmp/httpd_conf

# Append the backburner httpd configuration section to the httpd
# configuration file if not present
if ( $status == 1 ) then
    cat ${INST_FLASH}/flashmonitor_httpd_conf >> ${HTTPD_CONF}/httpd.conf
endif

rm -f /tmp/flash_conf
rm -f /tmp/httpd_conf

# Make sure the HTTPD server is turned on, and restart it.
#
echo "Restarting httpd server ..."
/sbin/chkconfig httpd on
/etc/init.d/httpd restart

# Warn if SELinux is turned on
#
if ( -f ${SELINUX_CONF} ) then
  egrep "enforced|permissive" ${SELINUX_CONF} | grep -v "#"
  if ( $status == 0 ) then
    echo; echo Warning: SELinux enabled.  This may prevent connections to this host.
    echo Edit ${SELINUX_CONF} to disable it.
  endif
endif

# Show URL
#
echo; echo Autodesk Backburner Monitor successfully installed.
echo; echo The monitor can be accessed with a web browser using the URL below:
echo http://`hostname -f`/Backburner; echo

