Commits

Zhang Huangbin committed 94fcc8c

PostgreSQL backend is now working on RHEL/CentOS 6.

  • Participants
  • Parent commits 19c4a5d

Comments (0)

Files changed (7)

File iRedMail/conf/postgresql

 export PGSQL_INIT_SQL_SAMPLE="${CONF_DIR}/pgsql_init.pgsql"
 
 if [ X"${DISTRO}" == X'RHEL' ]; then
+    if [ X"${DISTRO_VERSION}" == X'5' ]; then
+        export PGSQL_VERSION='8.1'
+    elif [ X"${DISTRO_VERSION}" == X'6' ]; then
+        export PGSQL_VERSION='8.4'
+    fi
     export PGSQL_SYS_USER_HOME='/var/lib/pgsql'
     export PGSQL_DATA_DIR="${PGSQL_SYS_USER_HOME}/data"
 

File iRedMail/functions/cleanup.sh

 {
     ECHO_DEBUG "Force all users to connect PGSQL server with password."
 
-    if [ X"${DISTRO}" == X'UBUNTU' ]; then
+    if [ X"${DISTRO}" == X'RHEL' ]; then
+        perl -pi -e 's#^(local.*)ident#${1}md5#' ${PGSQL_CONF_PG_HBA}
+        perl -pi -e 's#^(host.*)ident#${1}md5#' ${PGSQL_CONF_PG_HBA}
+    elif [ X"${DISTRO}" == X'UBUNTU' ]; then
         perl -pi -e 's#^(local.*)peer#${1}md5#' ${PGSQL_CONF_PG_HBA}
     elif [ X"${DISTRO}" == X'FREEBSD' ]; then
         # FreeBSD

File iRedMail/functions/cluebringer.sh

 FLUSH PRIVILEGES;
 EOF
         elif [ X"${BACKEND}" == X"PGSQL" ]; then
+            export shipped_pgsql_temp="$(eval ${LIST_FILES_IN_PKG} ${PKG_CLUEBRINGER} | grep '/policyd.pgsql.sql$')"
+            perl -pi -e 's=^(#.*)=/*${1}*/=' ${shipped_pgsql_temp}
             cat > ${tmp_sql} <<EOF
 CREATE DATABASE ${CLUEBRINGER_DB_NAME} WITH TEMPLATE template0 ENCODING 'UTF8';
 CREATE USER ${CLUEBRINGER_DB_USER} WITH ENCRYPTED PASSWORD '${CLUEBRINGER_DB_PASSWD}' NOSUPERUSER NOCREATEDB NOCREATEROLE;
 \c ${CLUEBRINGER_DB_NAME};
 
 -- Import SQL structure template.
-SOURCE $(eval ${LIST_FILES_IN_PKG} ${PKG_CLUEBRINGER} | grep '/policyd.pgsql.sql$');
+\i ${shipped_pgsql_temp};
 EOF
+
+            unset shipped_pgsql_temp
         fi
 
     elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then

File iRedMail/functions/dovecot2.sh

     elif [ X"${BACKEND}" == X"PGSQL" ]; then
 
         backup_file ${DOVECOT_PGSQL_CONF}
-        cp -f ${SAMPLE_DIR}/dovecot/dovecot-sql.conf ${DOVECOT_PGSQL_CONF}
+        if [ X"${DISTRO}" == X'RHEL' ]; then
+            # PGSQL 8.x
+            cp -f ${SAMPLE_DIR}/dovecot/dovecot-pgsql-8.x.conf ${DOVECOT_PGSQL_CONF}
+        else
+            cp -f ${SAMPLE_DIR}/dovecot/dovecot-sql.conf ${DOVECOT_PGSQL_CONF}
+        fi
 
         perl -pi -e 's#PH_SQL_DRIVER#pgsql#' ${DOVECOT_PGSQL_CONF}
         perl -pi -e 's#PH_SQL_SERVER#$ENV{PGSQL_SERVER}#' ${DOVECOT_PGSQL_CONF}

File iRedMail/functions/packages.sh

         if [ X"${DISTRO}" == X"RHEL" ]; then
             ALL_PKGS="${ALL_PKGS} postgresql-server${PKG_ARCH} postgresql-contrib${PKG_ARCH}"
 
+            # For Awstats.
+            [ X"${USE_AWSTATS}" == X"YES" ] && ALL_PKGS="${ALL_PKGS} mod_auth_pgsql${PKG_ARCH}"
+
         elif [ X"${DISTRO}" == X"SUSE" ]; then
             ALL_PKGS="${ALL_PKGS} postgresql-server postgresql-contrib postfix-postgresql"
 
     #
     ENABLED_SERVICES="${ENABLED_SERVICES} ${HTTPD_RC_SCRIPT_NAME}"
     if [ X"${DISTRO}" == X"RHEL" ]; then
-        ALL_PKGS="${ALL_PKGS} httpd${PKG_ARCH} mod_ssl${PKG_ARCH} php${PKG_ARCH} php-common${PKG_ARCH} php-gd${PKG_ARCH} php-xml${PKG_ARCH} php-mysql${PKG_ARCH} php-ldap${PKG_ARCH}"
+        ALL_PKGS="${ALL_PKGS} httpd${PKG_ARCH} mod_ssl${PKG_ARCH} php${PKG_ARCH} php-common${PKG_ARCH} php-gd${PKG_ARCH} php-xml${PKG_ARCH} php-mysql${PKG_ARCH} php-ldap${PKG_ARCH} php-pgsql${PKG_ARCH}"
         if [ X"${DISTRO_VERSION}" == X"5" ]; then
             ALL_PKGS="${ALL_PKGS} php-imap${PKG_ARCH} libmcrypt${PKG_ARCH} php-mcrypt${PKG_ARCH} php-mhash${PKG_ARCH} php-mbstring${PKG_ARCH}"
         fi

File iRedMail/functions/postgresql.sh

     # Warning: We must have 'postgresql_enable=YES' before start/stop mysql daemon.
     if [ X"${DISTRO}" == X'FREEBSD' ]; then
         freebsd_enable_service_in_rc_conf 'postgresql_enable' 'YES'
+        ${PGSQL_RC_SCRIPT} initdb &>/dev/null
     fi
 
-    if [ X"${DISTRO}" == X'RHEL' -o X"${DISTRO}" == X'FREEBSD' ]; then
-        ${PGSQL_RC_SCRIPT} initdb &>/dev/null
+    if [ X"${DISTRO}" == X'RHEL' ]; then
+        if [ X"${DISTRO_VERSION}" == X'5' ]; then
+            if [ -d ${PGSQL_DATA_DIR} ]; then
+                # Remove it to force /etc/init.d/postgresql initialize database
+                mv ${PGSQL_DATA_DIR} ${PGSQL_DATA_DIR}-backup &>/dev/null
+            fi
+        elif [ X"${DISTRO_VERSION}" == X'6' ]; then
+            ${PGSQL_RC_SCRIPT} initdb &>/dev/null
+        fi
     fi
 
     backup_file ${PGSQL_CONF_PG_HBA} ${PGSQL_CONF_POSTGRESQL}
 -- Create database to store mail accounts
 CREATE DATABASE ${VMAIL_DB} WITH TEMPLATE template0 ENCODING 'UTF8';
 \c ${VMAIL_DB};
+EOF
+
+    # PostgreSQL 8.x
+    # - Create language plpgsql
+    # - Create extension dblink via importing SQL file
+    if [ X"${DISTRO}" == X'RHEL' ]; then
+        cat >> ${PGSQL_INIT_SQL_SAMPLE} <<EOF
+CREATE LANGUAGE plpgsql;
+\i /usr/share/pgsql/contrib/dblink.sql;
+EOF
+    fi
+
+    cat >> ${PGSQL_INIT_SQL_SAMPLE} <<EOF
 \i ${PGSQL_DATA_DIR}/vmail.sql;
+EOF
 
+    # PostgreSQL 9.x can create extension directly
+    if [ X"${DISTRO}" != X'RHEL' ]; then
+        cat >> ${PGSQL_INIT_SQL_SAMPLE} <<EOF
 -- Create extension dblink.
 -- Used to change password through Roundcube webmail
 CREATE EXTENSION dblink;
+EOF
+    fi
 
+    cat >> ${PGSQL_INIT_SQL_SAMPLE} <<EOF
 -- Crete roles:
 -- + vmail: read-only
 -- + vmailadmin: read, write

File iRedMail/samples/dovecot/dovecot-pgsql-8.x.conf

+driver = pgsql
+default_pass_scheme = CRYPT
+connect = host=PH_SQL_SERVER dbname=PH_VMAIL_DB user=PH_VMAIL_DB_BIND_USER password=PH_VMAIL_DB_BIND_PASSWD
+password_query = SELECT password FROM mailbox WHERE username='%u' AND active='1'
+user_query = SELECT \
+    mailbox.storagebasedirectory || '/' || mailbox.storagenode || '/' || mailbox.maildir AS home, \
+    '*:bytes=' || mailbox.quota*1048576 AS quota_rule \
+FROM mailbox,domain \
+WHERE mailbox.username='%u' \
+    AND mailbox.domain='%d' \
+    AND mailbox.enable%Ls%Lc=1 \
+    AND mailbox.domain=domain.domain \
+    AND domain.backupmx=0 \
+    AND domain.active=1 \
+    AND mailbox.active=1