#!/usr/bin/env bash

# Author: Zhang Huangbin (zhb _at_ iredmail.org)

#---------------------------------------------------------------------
# This file is part of iRedMail, which is an open source mail server
# solution for Red Hat(R) Enterprise Linux, CentOS, Debian and Ubuntu.
#
# iRedMail 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, either version 3 of the License, or
# (at your option) any later version.
#
# iRedMail 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 iRedMail.  If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------

# path to php program
export PHP_BIN='/usr/bin/php'

# php-fpm
export PHP_FPM_RC_SCRIPT_NAME='php-fpm'
export PHP_FASTCGI_SOCKET='/var/run/php-fpm.socket'
export PHP_FPM_POOL_WWW_CONF='/etc/php-fpm.d/www.conf'

if [ X"${DISTRO}" == X'RHEL' ]; then
    export PHP_INI='/etc/php.ini'
    export PHP_FASTCGI_SOCKET='/var/run/php-fpm/php-fpm.socket'

elif [ X"${DISTRO}" == X'DEBIAN' -o X"${DISTRO}" == X'UBUNTU' ]; then
    [ X"${WEB_SERVER_IS_APACHE}" == X'YES' ] && export PHP_INI='/etc/php5/apache2/php.ini'
    [ X"${WEB_SERVER_IS_NGINX}" == X'YES' ] && export PHP_INI='/etc/php5/fpm/php.ini'

    export PHP_INI_CONF_DIR='/etc/php5/apache2/conf.d/'
    export PHP_FPM_POOL_WWW_CONF='/etc/php5/fpm/pool.d/www.conf'
    export PHP_FPM_RC_SCRIPT_NAME='php5_fpm'

elif [ X"${DISTRO}" == X'FREEBSD' ]; then
    export PHP_BIN='/usr/local/bin/php'

    # Copy from example: /usr/local/etc/php.ini-production
    export PHP_INI='/usr/local/etc/php.ini'
    export PHP_FPM_POOL_WWW_CONF='/usr/local/etc/php-fpm.conf'

elif [ X"${DISTRO}" == X'OPENBSD' ]; then
    export PHP_BIN='/usr/local/bin/php-5.?'
    export PHP_INI="/etc/php-5.?.ini"
    export PHP_FPM_RC_SCRIPT_NAME='php_fpm'
    export PHP_FPM_POOL_WWW_CONF='/etc/php-fpm.conf'
    export PHP_FASTCGI_SOCKET="${HTTPD_SERVERROOT}/run/php-fpm.socket"
fi

export PHP_FASTCGI_SOCKET_FULL="unix:${PHP_FASTCGI_SOCKET}"

# connection type: mysql, mysqli (recommended for MySQL/MariaDB), pgsql.
export PHP_CONN_TYPE='mysqli'
[ X"${BACKEND}" == X'PGSQL' ] && export PHP_CONN_TYPE='pgsql'
