#!/bin/sh

# Installation of JFFNMS

TMPDIR=/tmp
BUILDDIR=$TMPDIR/jffnms.build-$$
JFFNMS_FILE_CACHE=/usr/src/jffnms
MYSQL_PREFIX=/usr/local/mysql
APACHE_PREFIX=/usr/local/apache

PROFILE_D=/etc/profile.d
MYSQL_PATH_SH=$PROFILE_D/mysql.sh
APACHE_PATH_SH=$PROFILE_D/apache.sh

mkdir $BUILDDIR
cd $BUILDDIR



echo Compiling / Installing Apache

cd $BUILDDIR

echo Untarring apache openssl and mod_ssl

tar zxf $JFFNMS_FILE_CACHE/apache*
tar zxf $JFFNMS_FILE_CACHE/openssl*
tar zxf $JFFNMS_FILE_CACHE/mod_ssl*

cd $BUILDDIR/openssl*
echo Configuring OpenSSL
./config
echo Making OpenSSL
make

cd $BUILDDIR

MOD_SSL=`ls -1 | grep mod_ssl`
echo $MOD_SSL

OPEN_SSL=`ls -1 | grep openssl`
echo $OPEN_SSL

APACHE=`ls -1 | grep apache`
echo $APACHE

cd $BUILDDIR/mod_ssl*

# patch apache source with mod_ssl
./configure \
              --with-apache=../$APACHE \
              --with-ssl=../$OPEN_SSL \
              --prefix=$APACHE_PREFIX


cd $BUILDDIR/apache*

# enable dso's and all of them
./configure --prefix=/usr/local/apache --enable-module=all --enable-shared=ssl --enable-shared=max

make

# This is if you want to isntall a test https cert.
make certificate

make install

touch $APACHE_PATH_SH
chmod +x $APACHE_PATH_SH

cat << EOF > $APACHE_PATH_SH
# Apache Path Initialisation Script
# James McDonald

if [ ! \`echo \$PATH | grep $APACHE_PATH_SH/bin\` ] ; then

	PATH=\$PATH:$APACHE_PATH_SH/bin

fi
export PATH

EOF

echo Adding start up script to rc.local
echo "$APACHE_PREFIX/bin/bin/apachectl startssl" >> /etc/rc.d/rc.local

echo Starting apache webserver

$APACHE_PREFIX/bin/apachectl startssl



