Commits

Zhang Huangbin committed 3755fba

Improve FreeBSD support:
* Switch to dovecot-2
* Switch to Amavisd-new-2.7.x
* Create binary package by default while installing packages with ports tree
* Fix incorrect path to Postfix config file

  • Participants
  • Parent commits 78b65df

Comments (0)

Files changed (9)

File iRedMail/conf/amavisd

 
     # Override location of command 'altermime'
     export ALTERMIME_BIN='/usr/local/bin/altermime'
-else
-    :
+
+    export AMAVISD_DB_MYSQL_TMPL="${SAMPLE_DIR}/amavisd-2.7.0.mysql"
 fi
 
 # Syslog setting, 'YES' or 'NO'

File iRedMail/conf/core

         unset VAR VALUE
     fi
 }
+
+freebsd_add_make_conf()
+{
+    # USAGE: freebsd_add_make_conf VAR VALUE
+    [ -f /etc/make.conf ] || touch /etc/make.conf
+    if [ X"$#" == X'2' ]; then
+        var="${1}"
+        value="${2}"
+        final_option="${1}=${2}"
+        comment_mark="# ${PROG_NAME}-${var}"
+        if ! grep "^${comment_mark}$" /etc/make.conf &>/dev/null; then
+            ECHO_DEBUG "Add make option in /etc/make.conf: ${final_option}"
+            echo "${comment_mark}" >> /etc/make.conf
+            echo "${final_option}" >> /etc/make.conf
+        else
+            ECHO_DEBUG "Skip adding option in /etc/make.conf: ${final_option}"
+        fi
+    fi
+}
+

File iRedMail/conf/dovecot

 export ENABLE_DOVECOT="YES"
 export ENABLE_DOVECOT_SSL="YES"
 
+# Dovecot major version number
+export DOVECOT_VERSION='2'
+
 # Dovecot user & group.
 export DOVECOT_USER='dovecot'
 export DOVECOT_GROUP='dovecot'
 export DOVECOT_GLOBAL_SIEVE_FILE="${SIEVE_DIR}/${SIEVE_RULE_FILENAME}"
 
 if [ X"${DISTRO}" == X"RHEL" ]; then
-    export DOVECOT_VERSION='2'
     export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
     export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
     export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
     fi
     export DOVECOT_DELIVER='/usr/libexec/dovecot/deliver'
 elif [ X"${DISTRO}" == X"SUSE" ]; then
-    # openSUSE 12.1 and later versions ship 2.0.x
-    export DOVECOT_VERSION='2'
-
     export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
     export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
     export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
         if [ X"${DISTRO_CODENAME}" == X"lucid" ]; then
             # Ubuntu 10.04
             export DOVECOT_VERSION='1.2'
-        else
-            # Ubuntu 11.10+
-            export DOVECOT_VERSION='2'
         fi
     fi
 
     export DOVECOT_DELIVER='/usr/lib/dovecot/deliver'
 
 elif [ X"${DISTRO}" == X"GENTOO" ]; then
-    export DOVECOT_VERSION='2'
     export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
     export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
     export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
     export DOVECOT_DELIVER='/usr/libexec/dovecot/deliver'
 
 elif [ X"${DISTRO}" == X"FREEBSD" ]; then
-    export DOVECOT_VERSION='1.2'
     export DOVECOT_CONF='/usr/local/etc/dovecot.conf'
     export DOVECOT_LDAP_CONF='/usr/local/etc/dovecot-ldap.conf'
     export DOVECOT_MYSQL_CONF='/usr/local/etc/dovecot-mysql.conf'

File iRedMail/conf/postfix

 export POSTFIX_ROOTDIR='/etc/postfix'
 export POSTFIX_RC_SCRIPT_NAME='postfix'
 
+# Log file
+export MAILLOG='/var/log/maillog'
+
 # Mail log files.
-if [ X"${DISTRO}" == X"RHEL" -o X"${DISTRO}" == X"FREEBSD" ]; then
-    # RHEL, CentOS
-    export MAILLOG='/var/log/maillog'
-elif [ X"${DISTRO}" == X"SUSE" ]; then
+if [ X"${DISTRO}" == X"SUSE" ]; then
     export MAILLOG='/var/log/mail'
     export MAILLOG_INFO='/var/log/mail.info'
     export MAILLOG_ERROR='/var/log/mail.err'
     export MAILLOG_WARN='/var/log/mail.warn'
     export POSTFIX_SYSCONFIG_CONF="${ETC_SYSCONFIG_DIR}/postfix"
 elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
-    # Debian, Ubuntu
     export MAILLOG='/var/log/mail.log'
     export MAILLOG_INFO='/var/log/mail.info'
     export MAILLOG_ERROR='/var/log/mail.err'
     export MAILLOG_WARN='/var/log/mail.warn'
-elif [ X"${DISTRO}" == X"GENTOO" ]; then
-    # Gentoo
-    export MAILLOG='/var/log/maillog'
-elif [ X"${DISTRO}" == X"FREEBSD" ]; then
-    # FreeBSD
+elif [ X"${DISTRO}" == X'FREEBSD' ]; then
     export POSTFIX_ROOTDIR='/usr/local/etc/postfix'
-    export MAILLOG='/var/log/maillog'
 fi
 
 # You do *NOT* need to modify them.

File iRedMail/conf/postgresql

     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"
+
+elif [ X"${DISTRO}" == X'FREEBSD' ]; then
+    export PGSQL_CONF_DIR='/usr/local/pgsql/data'
+    export PGSQL_CONF_POSTGRESQL="${PGSQL_CONF_DIR}/postgresql.conf"
+    export PGSQL_CONF_PG_HBA="${PGSQL_CONF_DIR}/pg_hba.conf"
+    export PGSQL_DATA_DIR="${PGSQL_CONF_DIR}"
+
 else
     export PGSQL_CONF_DIR="/etc/postgresql/${PGSQL_VERSION}/main"
     export PGSQL_CONF_POSTGRESQL="${PGSQL_CONF_DIR}/postgresql.conf"

File iRedMail/functions/iredapd.sh

     ECHO_INFO "Configure iRedAPD (postfix policy daemon)."
 
     # Create a low privilege user as daemon user.
-    if [ X"${DISTRO}" == X"FreeBSD" ]; then
+    if [ X"${DISTRO}" == X'FreeBSD' ]; then
         pw useradd -m -d ${IREDAPD_HOME_DIR} -s ${SHELL_NOLOGIN} -c "iRedAPD daemon user" -n ${IREDAPD_DAEMON_USER}
     elif [ X"${DISTRO}" == X"SUSE" ]; then
         groupadd ${IREDAPD_DAEMON_GROUP}
         # Enable plugins.
         perl -pi -e 's#^(plugins).*#${1} = ldap_maillist_access_policy, block_amavisd_blacklisted_senders#' iredapd.ini
 
-    elif [ X"${BACKEND}" == X"MYSQL" ]; then
+    elif [ X"${BACKEND}" == X"MYSQL" -o X"${BACKEND}" == X'PGSQL' ]; then
         # Set backend.
-        perl -pi -e 's#^(backend).*#${1} = mysql#' iredapd.ini
+        if [ X"${BACKEND}" == X'MYSQL' ]; then
+            perl -pi -e 's#^(backend).*#${1} = mysql#' iredapd.ini
+        else
+            perl -pi -e 's#^(backend).*#${1} = pgsql#' iredapd.ini
+        fi
 
         # Configure MySQL server related stuffs.
-        perl -pi -e 's#^(server).*#${1} = $ENV{MYSQL_SERVER}#' iredapd.ini
+        perl -pi -e 's#^(server).*#${1} = $ENV{SQL_SERVER}#' iredapd.ini
+        perl -pi -e 's#^(port).*#${1} = $ENV{SQL_SERVER_PORT}#' iredapd.ini
         perl -pi -e 's#^(db).*#${1} = $ENV{VMAIL_DB}#' iredapd.ini
         perl -pi -e 's#^(user).*#${1} = $ENV{VMAIL_DB_BIND_USER}#' iredapd.ini
         perl -pi -e 's#^(password).*#${1} = $ENV{VMAIL_DB_BIND_PASSWD}#' iredapd.ini

File iRedMail/functions/packages.sh

     elif [ X"${BACKEND}" == X"PGSQL" ]; then
         ENABLED_SERVICES="${ENABLED_SERVICES} ${PGSQL_RC_SCRIPT_NAME}"
 
-        # iRedAPD doesn't work with PGSQL
-        export USE_IREDAPD='NO'
-
         # PGSQL server & client.
         if [ X"${DISTRO}" == X"RHEL" ]; then
             ALL_PKGS="${ALL_PKGS} postgresql-server postgresql-contrib"
     # iRedAPD.
     #
     if [ X"${USE_IREDAPD}" == X"YES" ]; then
+        # Don't append 'iredapd' to ${ENABLED_SERVICES} since we don't have
+        # RC script ready in early stage.
+
         [ X"${DISTRO}" == X"RHEL" ] && ALL_PKGS="${ALL_PKGS} python-ldap${PKG_ARCH}"
         [ X"${DISTRO}" == X"SUSE" ] && ALL_PKGS="${ALL_PKGS} python-ldap"
-        [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ] && ALL_PKGS="${ALL_PKGS} python-ldap"
-        # Don't append 'iredapd' to ${ENABLED_SERVICES} since we don't have
-        # RC script ready in early stage.
-        #ENABLED_SERVICES="${ENABLED_SERVICES} iredapd"
+        [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ] && ALL_PKGS="${ALL_PKGS} python-ldap python-psycopg2 python-mysqldb"
     fi
 
     # iRedAdmin.

File iRedMail/functions/packages_freebsd.sh

 install_all()
 {
     ALL_PKGS=''             # Binary package names. e.g. mysql-server, dovecot.
-    ALL_PORTS=''            # Port name under /usr/ports/. e.g. mail/dovecot, databases/mysql50.
+    ALL_PORTS=''            # Port name under /usr/ports/. e.g. mail/dovecot2.
     ENABLED_SERVICES=''     # Scripts under /usr/local/etc/rc.d/
     DISABLED_SERVICES=''    # Scripts under /usr/local/etc/rc.d/
 
     # Make it don't popup dialog while building ports.
     export BATCH='yes'
 
-    cat >> /etc/make.conf <<EOF
-# Without X-Window/GUI.
-WITHOUT_X11=yes
-# Use MySQL-5.0.x as default.
-WANT_MYSQL_VER=50
-# Use python-2.6 as default.
-PYTHON_DEFAULT_VERSION=python2.6
-# Use apache-2.2.
-APACHE_PORT=www/apache22
-# Use OpenLDAP 2.4.
-WANT_OPENLDAP_VER=24
-WITH_SASL=yes
-WANT_BDB_VER=46
-EOF
+    freebsd_add_make_conf 'WITHOUT_X11' 'yes'
+    freebsd_add_make_conf 'WANT_MYSQL_VER' '55'
+    freebsd_add_make_conf 'WANT_PGSQL_VER' '91'
+    freebsd_add_make_conf 'PYTHON_DEFAULT_VERSION' 'python2.7'
+    freebsd_add_make_conf 'APACHE_PORT' 'www/apache22'
+    freebsd_add_make_conf 'WANT_OPENLDAP_VER' '24'
+    freebsd_add_make_conf 'WITH_SASL' 'yes'
 
-    for i in m4 libiconv cyrus-sasl2 perl openslp mysql-server openldap24 dovecot \
+    for i in m4 libiconv cyrus-sasl2 perl openslp mysql openldap24 dovecot2 \
         ca_root_nss libssh2 curl libusb pth gnupg p5-IO-Socket-SSL \
         p5-Archive-Tar p5-Net-DNS p5-Mail-SpamAssassin p5-Authen-SASL \
         amavisd-new clamav apr python26 apache22 php5 php5-extensions \
 WITH_ASYNC_API=true
 EOF
 
-    # MySQL-server. REQUIRED.
-    cat > /var/db/ports/mysql-server/options <<EOF
-WITH_CHARSET=utf8
-WITH_XCHARSET=all
-WITH_OPENSSL=yes
-WITH_COLLATION=utf8_general_ci
-EOF
-    ALL_PKGS="${ALL_PKGS} mysql-server mysql-client"
-    ALL_PORTS="${ALL_PORTS} databases/mysql50-server"
-
-    ENABLED_SERVICES="${ENABLED_SERVICES} mysql-server"
-
     # OpenLDAP v2.4. REQUIRED for LDAP backend.
     if [ X"${BACKEND}" == X"OPENLDAP" ]; then
         cat > /var/db/ports/openldap24/options <<EOF
         ALL_PORTS="${ALL_PORTS} net/openldap24-server"
         ENABLED_SERVICES="${ENABLED_SERVICES} slapd"
 
+    elif [ X"${BACKEND}" == X'PGSQL' ]; then
+        cat > /var/db/ports/postgresql91/options <<EOF
+WITH_NLS=true
+WITHOUT_DTRACE=true
+WITHOUT_PAM=true
+WITHOUT_LDAP=true
+WITHOUT_MIT_KRB5=true
+WITHOUT_HEIMDAL_KRB5=true
+WITHOUT_GSSAPI=true
+WITHOUT_OPTIMIZED_CFLAGS=true
+WITH_XML=true
+WITH_TZDATA=true
+WITHOUT_DEBUG=true
+WITH_ICU=true
+WITH_INTDATE=true
+WITH_SSL=true
+EOF
+
+        ALL_PKGS="${ALL_PKGS} postgresql91-server postgresql91-client postgresql91-contrib"
+        ALL_PORTS="${ALL_PORTS} databases/postgresql91-server databases/postgresql91-contrib"
+        ENABLED_SERVICES="${ENABLED_SERVICES} ${PGSQL_RC_SCRIPT_NAME}"
+    fi
+
+    # MySQL server. Required in both backend OpenLDAP and MySQL.
+    if [ X"${BACKEND}" == X'OPENLDAP' -o X"${BACKEND}" == X'MYSQL' ]; then
+        cat > /var/db/ports/mysql/options <<EOF
+WITH_OPENSSL=true
+WITHOUT_FASTMTX=true
+EOF
+        ALL_PKGS="${ALL_PKGS} mysql-server mysql-client"
+        ALL_PORTS="${ALL_PORTS} databases/mysql55-server"
+
+        ENABLED_SERVICES="${ENABLED_SERVICES} mysql-server"
     fi
 
     # Dovecot v1.2.x. REQUIRED.
-    cat > /var/db/ports/dovecot/options <<EOF
+    cat > /var/db/ports/dovecot2/options <<EOF
 WITH_KQUEUE=true
 WITH_SSL=true
-WITH_MANAGESIEVE=true
-WITH_GSSAPI=true
+WITHOUT_GSSAPI=true
 WITHOUT_VPOPMAIL=true
-WITH_BDB=true
 WITH_LDAP=true
-WITHOUT_PGSQL=true
+WITH_PGSQL=true
 WITH_MYSQL=true
 WITHOUT_SQLITE=true
 EOF
 
     # Note: dovecot-sieve will install dovecot first.
     ALL_PKGS="${ALL_PKGS} dovecot-sieve dovecot-managesieve"
-    ALL_PORTS="${ALL_PORTS} mail/dovecot-sieve mail/dovecot-managesieve"
+    ALL_PORTS="${ALL_PORTS} mail/dovecot2 mail/dovecot2-pigeonhole"
     ENABLED_SERVICES="${ENABLED_SERVICES} dovecot"
 
     # ca_root_nss. DEPENDENCE.
     cat > /var/db/ports/postfix/options <<EOF
 WITH_PCRE=true
 WITHOUT_SASL2=true
-WITH_DOVECOT=true
-WITHOUT_DOVECOT2=true
+WITHOUT_DOVECOT=true
+WITH_DOVECOT2=true
 WITHOUT_SASLKRB5=true
 WITHOUT_SASLKMIT=true
 WITH_TLS=true
 WITH_BDB=true
 WITH_MYSQL=true
-WITHOUT_PGSQL=true
+WITH_PGSQL=true
+WITHOUT_SQLITE=true
 WITH_OPENLDAP=true
+WITH_LDAP_SASL=true
 WITH_CDB=true
 WITHOUT_NIS=true
 WITHOUT_VDA=true
     ENABLED_SERVICES="${ENABLED_SERVICES} postfix"
     DISABLED_SERVICES="${DISABLED_SERVICES} sendmail sendmail_submit sendmail_outbound sendmail_msq_queue"
 
-    # Policyd v1.8x. REQUIRED.
-    ALL_PKGS="${ALL_PKGS} postfix-policyd-sf"
-    ALL_PORTS="${ALL_PORTS} mail/postfix-policyd-sf"
-    ENABLED_SERVICES="${ENABLED_SERVICES} policyd"
+    if [ X"${BACKEND}" == X'OPENLDAP' -o X"${BACKEND}" == X'MYSQL' ]; then
+        # Policyd v1.8x
+        ALL_PKGS="${ALL_PKGS} postfix-policyd-sf"
+        ALL_PORTS="${ALL_PORTS} mail/postfix-policyd-sf"
+        ENABLED_SERVICES="${ENABLED_SERVICES} policyd"
+    elif [ X"${BACKEND}" == X'PGSQL' ]; then
+        # Policyd v2.x
+        ALL_PKGS="${ALL_PKGS} policyd2"
+        ALL_PORTS="${ALL_PORTS} mail/policyd2"
+        ENABLED_SERVICES="${ENABLED_SERVICES} policyd"
+
+        cat > /var/db/ports/policyd2/options <<EOF
+WITH_MYSQL=true
+WITH_PostgreSQL=true
+WITHOUT_SQLite=true
+EOF
+
+    fi
 
     # ClamAV. REQUIRED.
     cat > /var/db/ports/clamav/options <<EOF
 
     # Install all packages.
     ECHO_INFO "==== Install packages ===="
+
     for i in ${ALL_PORTS}; do
         if [ X"${i}" != X'' ]; then
             portname="$( echo ${i} | tr -d '-' | tr -d '/' | tr -d '\.' )"
                 cd /usr/ports/${i} && \
                     make clean && \
                     ECHO_INFO "Installing port: ${i} ..." && \
-                    make BATCH=yes install clean
+                    make DEPENDS_TARGET=package package clean
 
                     if [ X"$?" == X"0" ]; then
                         echo "export status_install_port_${portname}='DONE'" >> ${STATUS_FILE}

File iRedMail/functions/postgresql.sh

 
     # FreeBSD: Start pgsql when system start up.
     # Warning: We must have 'postgresql_enable=YES' before start/stop mysql daemon.
-    [ X"${DISTRO}" == X"FREEBSD" ] && cat >> /etc/rc.conf <<EOF
+    if [ X"${DISTRO}" == X"FREEBSD" ]; then
+        cat >> /etc/rc.conf <<EOF
 # Start PostgreSQL server.
 postgresql_enable="YES"
 EOF
 
+        su - ${PGSQL_SYS_USER} -c "${PGSQL_RC_SCRIPT} initdb" >/dev/null
+    fi
+
     backup_file ${PGSQL_CONF_PG_HBA} ${PGSQL_CONF_POSTGRESQL}
 
     #ECHO_DEBUG "Force all users to connect PGSQL server with password."