Zhang Huangbin avatar Zhang Huangbin committed 19c4a5d

Enable PostgreSQL backend on RHEL/CentOS 6. Not completed yet.

Comments (0)

Files changed (13)

iRedMail/ChangeLog

 iRedMail-0.8.0-beta3:
-    * Enable PostgreSQL support on FreeBSD.
+    * Enable PostgreSQL support on FreeBSD, RHEL/CentOS 6.
     * Add shell scripts to backup OpenLDAP and/or MySQL in cron by default.
     * Use Dovecot-2.0 instead of 1.2.x on openSUSE-12.1.
     * Drop support for below distributions and releases:

iRedMail/conf/cluebringer

 export CLUEBRINGER_LOGROTATE_FILE='/etc/logrotate.d/policyd'
 export CLUEBRINGER_LOG_FILE='/var/log/cbpolicyd.log'
 
-if [ X"${DISTRO}" == X"RHEL" ]; then
-    export PKG_CLUEBRINGER='policyd'
-    export CLUEBRINGER_CONF='/etc/policyd.conf'
-    export CLUEBRINGER_WEBUI_CONF="/etc/cluebringer/cluebringer-webui.conf"
-    export CLUEBRINGER_PID_FILE='/var/run/cluebringer/cbpolicyd.pid'
-    export CLUEBRINGER_HTTPD_ROOT=''
-
-    # Path of policyd-clean
-    export CLUEBRINGER_CLEANUP_BIN='/usr/sbin/policyd-cleanup'
-
-elif [ X"${DISTRO}" == X"SUSE" ]; then
-    export PKG_CLUEBRINGER='policyd'
-    export CLUEBRINGER_CONF='/etc/cluebringer/cluebringer.conf'
-    export CLUEBRINGER_WEBUI_CONF="/etc/cluebringer/cluebringer-webui.conf"
-    export CLUEBRINGER_PID_FILE='/var/run/cluebringer/cbpolicyd.pid'
-    export CLUEBRINGER_HTTPD_ROOT=''
-
-    # Path of policyd-clean
-    export CLUEBRINGER_CLEANUP_BIN='/usr/lib/policyd/cleanup'
+if [ X"${DISTRO}" == X"RHEL" -o X"${DISTRO}" == X'SUSE' ]; then
+    export PKG_CLUEBRINGER='cluebringer'
+    export CLUEBRINGER_RC_SCRIPT_NAME='cbpolicyd'
+    export CLUEBRINGER_CONF='/etc/policyd/cluebringer.conf'
+    export CLUEBRINGER_WEBUI_CONF="/etc/policyd/webui.conf"
+    export CLUEBRINGER_PID_FILE='/var/run/cbpolicyd.pid'
+    export CLUEBRINGER_HTTPD_ROOT='/usr/share/cluebringer/webui/'
 
     # Override default setting.
-    export CLUEBRINGER_USER_HOME='/var/lib/empty'
+    export CLUEBRINGER_USER_HOME='/home/cbpolicyd'
 
 elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
     export PKG_CLUEBRINGER='postfix-cluebringer'
     export CLUEBRINGER_PID_FILE='/var/run/cluebringer/cbpolicyd.pid'
     export CLUEBRINGER_HTTPD_ROOT='/usr/share/postfix-cluebringer-webui/webui'
 
-    # Path of policyd-clean
-    export CLUEBRINGER_CLEANUP_BIN='/usr/lib/postfix-policyd/cleanup'
-
 elif [ X"${DISTRO}" == X"FREEBSD" ]; then
     export CLUEBRINGER_USER='policyd'
     export CLUEBRINGER_GROUP='policyd'
     export CLUEBRINGER_PID_FILE='/var/run/cbpolicyd.pid'
     export CLUEBRINGER_HTTPD_ROOT='/usr/share/cluebringer/webui'
 
-    # Path of policyd-clean
-    export CLUEBRINGER_CLEANUP_BIN='/usr/local/sbin/postfix-policyd-sf-cleanup'
-
-else
-    :
 fi
 
 export CLUEBRINGER_RC_SCRIPT="${DIR_RC_SCRIPTS}/${CLUEBRINGER_RC_SCRIPT_NAME}"

iRedMail/conf/global

             export PKG_ARCH=''
         fi
 
+        # Enable PostgreSQL backend on RHEL/CentOS 6.
+        if [ X"${DISTRO_VERSION}" == X'6' ]; then
+            export ENABLE_BACKEND_PGSQL='YES'
+        fi
+
     elif [ -f /etc/SuSE-release ]; then
         # openSUSE
         export DISTRO='SUSE'

iRedMail/conf/phppgadmin

 # along with iRedMail.  If not, see <http://www.gnu.org/licenses/>.
 #---------------------------------------------------------------------
 
-export PHPPGADMIN_VERSION='5.0.3'
+export PHPPGADMIN_VERSION='5.0.4'
 export PHPPGADMIN_TARBALL="phpPgAdmin-${PHPPGADMIN_VERSION}.tar.bz2"
 
 # Install phpPgAdmin with source tarball.

iRedMail/conf/policy_server

 export USE_POLICYD='YES'
 
 # Use Policyd-2.x (cluebringer).
-if [ X"${DISTRO}" == X'UBUNTU' ]; then
+if [ X"${DISTRO}" == X'RHEL' ]; then
+    if [ X"${BACKEND}" == X'PGSQL' ]; then
+        export USE_CLUEBRINGER='YES'
+        export USE_POLICYD='NO'
+    fi
+elif [ X"${DISTRO}" == X'UBUNTU' ]; then
     if [ X"${DISTRO_CODENAME}" == X"oneiric" \
         -o X"${DISTRO_CODENAME}" == X"precise" \
         ]; then

iRedMail/conf/postgresql

 export PGSQL_VERSION='9.1'  # Required on Gentoo
 export PGSQL_RC_SCRIPT_NAME='postgresql'
 
-if [ X"${DISTRO}" == X"GENTOO" ]; then
-    export PGSQL_RC_SCRIPT="${DIR_RC_SCRIPTS}/postgresql-${PGSQL_VERSION}"
-else
-    export PGSQL_RC_SCRIPT="${DIR_RC_SCRIPTS}/postgresql"
-fi
-
 export PGSQL_VMAIL_STRUCTURE_SAMPLE="${SAMPLE_DIR}/iredmail.pgsql"
 export PGSQL_INIT_SQL_SAMPLE="${CONF_DIR}/pgsql_init.pgsql"
 
-if [ X"${DISTRO}" == X'GENTOO' ]; then
+if [ X"${DISTRO}" == X'RHEL' ]; then
+    export PGSQL_SYS_USER_HOME='/var/lib/pgsql'
+    export PGSQL_DATA_DIR="${PGSQL_SYS_USER_HOME}/data"
+
+    export PGSQL_CONF_DIR="${PGSQL_DATA_DIR}"
+    export PGSQL_CONF_POSTGRESQL="${PGSQL_DATA_DIR}/postgresql.conf"
+    export PGSQL_CONF_PG_HBA="${PGSQL_DATA_DIR}/pg_hba.conf"
+
+elif [ X"${DISTRO}" == X'SUSE' ]; then
+    :
+
+elif [ X"${DISTRO}" == X'GENTOO' ]; then
     export PGSQL_CONF_DIR="/etc/postgresql-${PGSQL_VERSION}"
     export PGSQL_CONF_POSTGRESQL="${PGSQL_CONF_DIR}/postgresql.conf"
     export PGSQL_CONF_PG_HBA="${PGSQL_CONF_DIR}/pg_hba.conf"
     export PGSQL_DATA_DIR="/var/lib/postgresql/${PGSQL_VERSION}/data"
 
+    export PGSQL_RC_SCRIPT_NAME="postgresql-${PGSQL_VERSION}"
+
 elif [ X"${DISTRO}" == X'FREEBSD' ]; then
     export PGSQL_SYS_USER='pgsql'
     export PGSQL_SYS_GROUP='pgsql'
     export PGSQL_DATA_DIR="/var/lib/postgresql/${PGSQL_VERSION}/main"
 fi
 
+export PGSQL_RC_SCRIPT="${DIR_RC_SCRIPTS}/${PGSQL_RC_SCRIPT_NAME}"
+
 # ~/.pgpass
 export PGSQL_DOT_PGPASS="${PGSQL_SYS_USER_HOME}/.pgpass"
 

iRedMail/functions/cluebringer.sh

 {
     ECHO_DEBUG "Add user and group for policyd: ${CLUEBRINGER_USER}:${CLUEBRINGER_GROUP}."
 
-    if [ X"${DISTRO}" == X"UBUNTU" ]; then
+    if [ X"${DISTRO}" == X'RHEL' ]; then
+        groupadd ${CLUEBRINGER_GROUP}
+        useradd -m -d ${CLUEBRINGER_USER_HOME} -s ${SHELL_NOLOGIN} -g ${CLUEBRINGER_GROUP} ${CLUEBRINGER_USER}
+    elif [ X"${DISTRO}" == X"UBUNTU" ]; then
         if [ X"${DISTRO_CODENAME}" == X"oneiric" \
             -o X"${DISTRO_CODENAME}" == X"precise" \
             ]; then
 
 cluebringer_config()
 {
-    ECHO_DEBUG "Initialize MySQL database of policyd."
+    ECHO_DEBUG "Initialize SQL database for policyd."
 
     backup_file ${CLUEBRINGER_CONF}
 
     if [ X"${DISTRO}" == X"RHEL" -o X"${DISTRO}" == X"SUSE" ]; then
         if [ X"${BACKEND}" == X"OPENLDAP" -o X"${BACKEND}" == X"MYSQL" ]; then
             cat > ${tmp_sql} <<EOF
-# Import SQL structure template.
+-- Import SQL structure template.
 SOURCE $(eval ${LIST_FILES_IN_PKG} ${PKG_CLUEBRINGER} | grep '/DATABASE.mysql$');
 
-# Grant privileges.
+-- Grant privileges.
 GRANT SELECT,INSERT,UPDATE,DELETE ON ${CLUEBRINGER_DB_NAME}.* TO "${CLUEBRINGER_DB_USER}"@localhost IDENTIFIED BY "${CLUEBRINGER_DB_PASSWD}";
 FLUSH PRIVILEGES;
 EOF
         elif [ X"${BACKEND}" == X"PGSQL" ]; then
-            :
+            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$');
+EOF
         fi
 
     elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then

iRedMail/functions/packages.sh

 
         # PGSQL server & client.
         if [ X"${DISTRO}" == X"RHEL" ]; then
-            ALL_PKGS="${ALL_PKGS} postgresql-server postgresql-contrib"
+            ALL_PKGS="${ALL_PKGS} postgresql-server${PKG_ARCH} postgresql-contrib${PKG_ARCH}"
 
         elif [ X"${DISTRO}" == X"SUSE" ]; then
             ALL_PKGS="${ALL_PKGS} postgresql-server postgresql-contrib postfix-postgresql"
 
     # Policyd.
     if [ X"${DISTRO}" == X"RHEL" ]; then
-        ALL_PKGS="${ALL_PKGS} policyd${PKG_ARCH}"
-        ENABLED_SERVICES="${ENABLED_SERVICES} ${POLICYD_RC_SCRIPT_NAME}"
+        ALL_PKGS="${ALL_PKGS} cluebringer"
+        ENABLED_SERVICES="${ENABLED_SERVICES} ${CLUEBRINGER_RC_SCRIPT_NAME}"
     elif [ X"${DISTRO}" == X"SUSE" ]; then
-        ALL_PKGS="${ALL_PKGS} policyd"
+        ALL_PKGS="${ALL_PKGS} cluebringer"
         ENABLED_SERVICES="${ENABLED_SERVICES} ${POLICYD_RC_SCRIPT_NAME}"
     elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
         if [ X"${DISTRO_CODENAME}" == X"oneiric" \
     ENABLED_SERVICES="${ENABLED_SERVICES} ${AMAVISD_RC_SCRIPT_NAME} ${CLAMAV_CLAMD_RC_SCRIPT_NAME}"
     if [ X"${DISTRO}" == X"RHEL" ]; then
         ALL_PKGS="${ALL_PKGS} clamd${PKG_ARCH} clamav${PKG_ARCH} clamav-db${PKG_ARCH} spamassassin${PKG_ARCH} altermime${PKG_ARCH} perl-LDAP.noarch"
+
         if [ X"${DISTRO_VERSION}" == X"5" ]; then
             ALL_PKGS="${ALL_PKGS} amavisd-new${PKG_ARCH} perl-IO-Compress.noarch"
         else
             ALL_PKGS="${ALL_PKGS} amavisd-new.noarch"
         fi
+
+        if [ X"${BACKEND}" == X'PGSQL' ]; then
+            ALL_PKGS="${ALL_PKGS} perl-DBD-Pg"
+        fi
+
         DISABLED_SERVICES="${DISABLED_SERVICES} spamassassin"
 
     elif [ X"${DISTRO}" == X"SUSE" ]; then

iRedMail/functions/postgresql.sh

 
     # FreeBSD: Start pgsql when system start up.
     # Warning: We must have 'postgresql_enable=YES' before start/stop mysql daemon.
-    if [ X"${DISTRO}" == X"FREEBSD" ]; then
+    if [ X"${DISTRO}" == X'FREEBSD' ]; then
         freebsd_enable_service_in_rc_conf 'postgresql_enable' 'YES'
+    fi
 
+    if [ X"${DISTRO}" == X'RHEL' -o X"${DISTRO}" == X'FREEBSD' ]; then
         ${PGSQL_RC_SCRIPT} initdb &>/dev/null
     fi
 
 -- Create database to store mail accounts
 CREATE DATABASE ${VMAIL_DB} WITH TEMPLATE template0 ENCODING 'UTF8';
 \c ${VMAIL_DB};
-\i ${PGSQL_SYS_USER_HOME}/vmail.sql;
+\i ${PGSQL_DATA_DIR}/vmail.sql;
 
 -- Create extension dblink.
 -- Used to change password through Roundcube webmail
 EOF
 
     ECHO_DEBUG "Import postfix virtual hosts/users: ${PGSQL_INIT_SQL_SAMPLE}."
-    cp -f ${PGSQL_VMAIL_STRUCTURE_SAMPLE} ${PGSQL_SYS_USER_HOME}/vmail.sql >/dev/null
-    cp -f ${PGSQL_INIT_SQL_SAMPLE} ${PGSQL_SYS_USER_HOME}/init.sql >/dev/null
-    chmod 0777 ${PGSQL_SYS_USER_HOME}/{vmail,init}.sql >/dev/null
-    su - ${PGSQL_SYS_USER} -c "psql -d template1 -f ${PGSQL_SYS_USER_HOME}/init.sql" >/dev/null
-    rm -f ${PGSQL_SYS_USER_HOME}/{vmail,init}.sql >/dev/null
+    cp -f ${PGSQL_VMAIL_STRUCTURE_SAMPLE} ${PGSQL_DATA_DIR}/vmail.sql >/dev/null
+    cp -f ${PGSQL_INIT_SQL_SAMPLE} ${PGSQL_DATA_DIR}/init.sql >/dev/null
+    chmod 0777 ${PGSQL_DATA_DIR}/{vmail,init}.sql >/dev/null
+    su - ${PGSQL_SYS_USER} -c "psql -d template1 -f ${PGSQL_DATA_DIR}/init.sql" >/dev/null
+    #rm -f ${PGSQL_DATA_DIR}/{vmail,init}.sql >/dev/null
 
     cat >> ${TIP_FILE} <<EOF
 Virtual Users:

iRedMail/pkgs/MD5.misc

 78ca61eb5d7913963f8e42eb3b4f0e95  misc/phpldapadmin-1.2.2.tgz
 ab181a3fffc89e5d5c4ebd62ccfe396b  misc/phpMyAdmin-3.4.9-all-languages.tar.bz2
 e615fc6b21f523371ce2f8679a361846  misc/iRedAPD-1.3.7.tar.bz2
+ea3030b376d389bbe447f88dfaf832f2  misc/phpPgAdmin-5.0.4.tar.bz2

iRedMail/pkgs/MD5.opensuse

 3f9ee778c5c34357a0233c1f0e024d00  misc/web.py-0.36.tar.gz
+ea3030b376d389bbe447f88dfaf832f2  misc/phpPgAdmin-5.0.4.tar.bz2
+ea3030b376d389bbe447f88dfaf832f2  misc/phpPgAdmin-5.0.4.tar.bz2

iRedMail/pkgs/MD5.ubuntu.lucid

 ddd7ba4271056e9ce6b230420fd9b66b  misc/iRedAdmin-0.1.6.tar.bz2
 529bd9131e796e368b68b9aec9c885d0  misc/roundcubemail-0.7.2.tar.gz
 e615fc6b21f523371ce2f8679a361846  misc/iRedAPD-1.3.7.tar.bz2
+ea3030b376d389bbe447f88dfaf832f2  misc/phpPgAdmin-5.0.4.tar.bz2

iRedMail/samples/iredmail.pgsql

 -- ---------------------------------------------------------------------
 
 -- Used to store domain admin accounts
-CREATE TABLE IF NOT EXISTS admin (
+CREATE TABLE admin (
     username VARCHAR(255) NOT NULL DEFAULT '',
     password VARCHAR(255) NOT NULL DEFAULT '',
     name VARCHAR(255) NOT NULL DEFAULT '',
 CREATE INDEX idx_admin_active ON admin (active);
 
 -- Used to store mail alias accounts
-CREATE TABLE IF NOT EXISTS alias (
+CREATE TABLE alias (
     address VARCHAR(255) NOT NULL DEFAULT '',
     goto TEXT NOT NULL DEFAULT '',
     name VARCHAR(255) NOT NULL DEFAULT '',
 CREATE INDEX idx_alias_active ON alias (active);
 
 -- Used to store virtual mail domains
-CREATE TABLE IF NOT EXISTS domain (
+CREATE TABLE domain (
     -- mail domain name. e.g. iredmail.org.
     domain VARCHAR(255) NOT NULL DEFAULT '',
     description TEXT NOT NULL DEFAULT '',
 CREATE INDEX idx_domain_active ON domain (active);
 
 -- Used to store alias domains
-CREATE TABLE IF NOT EXISTS alias_domain (
+CREATE TABLE alias_domain (
     alias_domain VARCHAR(255) NOT NULL,
     target_domain VARCHAR(255) NOT NULL,
     created TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '1970-01-01 00:00:00',
 CREATE INDEX idx_alias_domain_active ON alias_domain (active);
 
 -- Used to store domain <=> admin relationship
-CREATE TABLE IF NOT EXISTS domain_admins (
+CREATE TABLE domain_admins (
     username VARCHAR(255) NOT NULL DEFAULT '',
     domain VARCHAR(255) NOT NULL DEFAULT '',
     created TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '1970-01-01 00:00:00',
 CREATE INDEX idx_domain_admins_active ON domain_admins (active);
 
 -- Used to store virtual mail accounts
-CREATE TABLE IF NOT EXISTS mailbox (
+CREATE TABLE mailbox (
     username VARCHAR(255) NOT NULL,
     password VARCHAR(255) NOT NULL DEFAULT '',
     name VARCHAR(255) NOT NULL DEFAULT '',
 CREATE INDEX idx_mailbox_expired ON mailbox (expired);
 CREATE INDEX idx_mailbox_active ON mailbox (active);
 
-CREATE TABLE IF NOT EXISTS sender_bcc_domain (
+CREATE TABLE sender_bcc_domain (
     domain VARCHAR(255) NOT NULL DEFAULT '',
     bcc_address VARCHAR(255) NOT NULL DEFAULT '',
     created TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '1970-01-01 00:00:00',
 CREATE INDEX idx_sender_bcc_domain_expired ON sender_bcc_domain (expired);
 CREATE INDEX idx_sender_bcc_domain_active ON sender_bcc_domain (active);
 
-CREATE TABLE IF NOT EXISTS sender_bcc_user (
+CREATE TABLE sender_bcc_user (
     username VARCHAR(255) NOT NULL DEFAULT '',
     bcc_address VARCHAR(255) NOT NULL DEFAULT '',
     domain VARCHAR(255) NOT NULL DEFAULT '',
 --
 -- Table structure for table recipient_bcc_domain
 --
-CREATE TABLE IF NOT EXISTS recipient_bcc_domain (
+CREATE TABLE recipient_bcc_domain (
     domain VARCHAR(255) NOT NULL DEFAULT '',
     bcc_address VARCHAR(255) NOT NULL DEFAULT '',
     created TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '1970-01-01 00:00:00',
 --
 -- Table structure for table recipient_bcc_user
 --
-CREATE TABLE IF NOT EXISTS recipient_bcc_user (
+CREATE TABLE recipient_bcc_user (
     username VARCHAR(255) NOT NULL DEFAULT '',
     bcc_address VARCHAR(255) NOT NULL DEFAULT '',
     domain VARCHAR(255) NOT NULL DEFAULT '',
 -- IMAP shared folders. User 'from_user' shares folders to user 'to_user'.
 -- WARNING: Works only with Dovecot 1.2+.
 --
-CREATE TABLE IF NOT EXISTS share_folder (
+CREATE TABLE share_folder (
     from_user VARCHAR(255) NOT NULL,
     to_user VARCHAR(255) NOT NULL,
     dummy CHAR(1),
 -- Table used_quota. Used to store realtime mailbox quota in Dovecot.
 -- WARNING: Works only with Dovecot 1.2+.
 --
-CREATE TABLE IF NOT EXISTS used_quota (
+CREATE TABLE used_quota (
     username VARCHAR(255) NOT NULL,
     bytes INT8 NOT NULL DEFAULT 0,
     messages INT8 NOT NULL DEFAULT 0,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.