Zhang Huangbin avatar Zhang Huangbin committed 85bce8a

Enable PostgreSQL support on FreeBSD.

Comments (0)

Files changed (12)

iRedMail/ChangeLog

 iRedMail-0.8.0-beta3:
+    * Enable PostgreSQL support on FreeBSD.
     * 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:
           Thanks Martin Kuchar for the report.
     * Package update:
         + Roundcube -> 0.7.2
+        + MySQL -> 5.5 (FreeBSD)
+        + Dovecot -> 2.0 (FreeBSD)
 
 iRedMail-0.8.0-beta2:
     * It now works perfectly on Gentoo.

iRedMail/conf/cluebringer

     export CLUEBRINGER_CLEANUP_BIN='/usr/lib/postfix-policyd/cleanup'
 
 elif [ X"${DISTRO}" == X"FREEBSD" ]; then
-    export PKG_CLUEBRINGER='postfix-policyd-sf'
-    export CLUEBRINGER_CONF='/usr/local/etc/postfix-policyd-sf.conf'
+    export CLUEBRINGER_USER='policyd'
+    export CLUEBRINGER_GROUP='policyd'
+
+    export PKG_CLUEBRINGER='policyd2'
+    export CLUEBRINGER_CONF='/usr/local/etc/cluebringer.conf'
     export CLUEBRINGER_WEBUI_CONF="/usr/local/etc/cluebringer/cluebringer-webui.conf"
     export CLUEBRINGER_PID_FILE='var/run/cluebringer/cbpolicyd.pid'
     export CLUEBRINGER_HTTPD_ROOT=''

iRedMail/conf/core

     fi
 }
 
+enable_service_freebsd()
+{
+    :
+}
+disable_service_freebsd()
+{
+    :
+}
+
 freebsd_add_make_conf()
 {
     # USAGE: freebsd_add_make_conf VAR VALUE

iRedMail/conf/global

     export GENTOO_CONF_PACKAGE_UNMASK='/etc/portage/package.unmask'
 
 elif [ X"${DISTRO}" == X"FREEBSD" ]; then
+    export ENABLE_BACKEND_PGSQL='YES'
+
     # System user: root.
     export SYS_ROOT_USER='root'
     export SYS_ROOT_GROUP='wheel'

iRedMail/conf/policy_server

 # along with iRedMail.  If not, see <http://www.gnu.org/licenses/>.
 #---------------------------------------------------------------------
 
-if [ X"${DISTRO_CODENAME}" == X"oneiric" \
-    -o X"${DISTRO_CODENAME}" == X"precise" \
-    ]; then
-    # Use Policyd-2.x (cluebringer).
-    export USE_CLUEBRINGER='YES'
-    export USE_POLICYD='NO'
+# Use policyd-1.8 by default
+export USE_CLUEBRINGER='NO'
+export USE_POLICYD='YES'
 
-    . ${CONF_DIR}/cluebringer
-else
-    # Use Policyd-1.x.
-    export USE_CLUEBRINGER='NO'
-    export USE_POLICYD='YES'
+# Use Policyd-2.x (cluebringer).
+if [ X"${DISTRO}" == X'UBUNTU' ]; then
+    if [ X"${DISTRO_CODENAME}" == X"oneiric" \
+        -o X"${DISTRO_CODENAME}" == X"precise" \
+        ]; then
+        export USE_CLUEBRINGER='YES'
+        export USE_POLICYD='NO'
+    fi
+elif [ X"${DISTRO}" == X'FREEBSD' ]; then
+    if [ X"${BACKEND}" == X'PGSQL' ]; then
+        export USE_CLUEBRINGER='YES'
+        export USE_POLICYD='NO'
+    fi
+fi
 
+if [ X"${USE_POLICYD}" == X'YES' ]; then
     . ${CONF_DIR}/policyd
 fi
+
+if [ X"${USE_CLUEBRINGER}" == X'YES' ]; then
+    . ${CONF_DIR}/cluebringer
+fi

iRedMail/conf/postgresql

     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_SYS_USER='pgsql'
+    export PGSQL_SYS_GROUP='pgsql'
+    export PGSQL_SYS_USER_HOME='/usr/local/pgsql'
+
+    export PGSQL_CONF_DIR="${PGSQL_SYS_USER_HOME}/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}"

iRedMail/functions/cluebringer.sh

             :
         fi
     fi
-    #if [ X"${DISTRO}" == X"FREEBSD" ]; then
-    #    pw useradd -n ${CLUEBRINGER_USER} -s ${SHELL_NOLOGIN} -d ${CLUEBRINGER_USER_HOME} -m
-    #elif [ X"${DISTRO}" == X"SUSE" ]; then
+    #if [ X"${DISTRO}" == X"SUSE" ]; then
     #    # Not need to add user/group.
     #    :
     #else
 
     backup_file ${CLUEBRINGER_CONF}
 
+    # FreeBSD: Generate config file by copying a sample file
+    [ X"${DISTRO}" == X'FREBSD' ] && cp ${CLUEBRINGER_CONF}.sample ${CLUEBRINGER_CONF} >/dev/null
+
     #
     # Configure '[server]' section.
     #
 {
     ECHO_DEBUG "Configure webui of Policyd (cluebringer)."
 
-    backup_file ${CLUEBRINGER_CONF}
+    backup_file ${CLUEBRINGER_WEBUI_CONF}
+
+    # FreeBSD: Generate config file by copying a sample file
+    [ X"${DISTRO}" == X'FREBSD' ] && \
+        cp /usr/local/share/policyd2/contrib/httpd/cluebringer-httpd.conf ${CLUEBRINGER_WEBUI_CONF}
 
     # Make Cluebringer accessible via HTTPS.
     perl -pi -e 's#(</VirtualHost>)#Alias /cluebringer "$ENV{CLUEBRINGER_HTTPD_ROOT}/"\n${1}#' ${HTTPD_SSL_CONF}

iRedMail/functions/dovecot2.sh

 {
     ECHO_INFO "Configure Dovecot (pop3/imap server, version ${DOVECOT_VERSION})."
 
-    [ X"${ENABLE_DOVECOT}" == X"YES" ] && \
-        backup_file ${DOVECOT_CONF} && \
-        chmod 0664 ${DOVECOT_CONF} && \
-        ECHO_DEBUG "Configure dovecot: ${DOVECOT_CONF}."
+    backup_file ${DOVECOT_CONF}
+
+    ECHO_DEBUG "Configure dovecot: ${DOVECOT_CONF}."
 
     cp ${SAMPLE_DIR}/conf/dovecot2.conf ${DOVECOT_CONF}
+    chmod 0664 ${DOVECOT_CONF}
 
     # Base directory.
     perl -pi -e 's#PH_BASE_DIR#$ENV{DOVECOT_BASE_DIR}#' ${DOVECOT_CONF}

iRedMail/functions/packages_freebsd.sh

     DISABLED_SERVICES=''    # Scripts under /usr/local/etc/rc.d/
 
     # Make it don't popup dialog while building ports.
+    export PACKAGE_BUILDING='yes'
     export BATCH='yes'
+    export WANT_OPENLDAP_VER='24'
+    export WANT_MYSQL_VER='55'
+    export WANT_PGSQL_VER='91'
+    export WANT_POSTFIX_VER='27'
 
     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 'WANT_OPENLDAP_VER' "${WANT_OPENLDAP_VER}"
+    freebsd_add_make_conf 'WANT_MYSQL_VER' "${WANT_MYSQL_VER}"
+    freebsd_add_make_conf 'WANT_PGSQL_VER' "${WANT_PGSQL_VER}"
     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 openldap24 dovecot2 \
+    for i in openldap${WANT_OPENLDAP_VER} mysql postgresql${WANT_PGSQL_VER} postgresql${WANT_PGSQL_VER}-contrib \
+        m4 libiconv cyrus-sasl2 perl openslp dovecot2 policyd2 \
         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 python27 apache22 php5 php5-extensions \
 WITH_ASYNC_API=true
 EOF
 
+    # LDAP/MySQL/PGSQL client libraries and tools
+    ALL_PORTS="${ALL_PORTS} net/openldap${WANT_OPENLDAP_VER}-client databases/mysql${WANT_MYSQL_VER}-client databases/postgresql${WANT_PGSQL_VER}-client"
+
     # OpenLDAP v2.4. REQUIRED for LDAP backend.
     if [ X"${BACKEND}" == X"OPENLDAP" ]; then
-        cat > /var/db/ports/openldap24/options <<EOF
+        cat > /var/db/ports/openldap${WANT_OPENLDAP_VER}/options <<EOF
 WITH_SASL=true
 WITH_FETCH=true
 WITH_DYNACL=true
 EOF
 
         ALL_PKGS="${ALL_PKGS} openldap-sasl-server openldap-sasl-client"
-        ALL_PORTS="${ALL_PORTS} net/openldap24-server"
+        ALL_PORTS="${ALL_PORTS} net/openldap${WANT_OPENLDAP_VER}-server"
         ENABLED_SERVICES="${ENABLED_SERVICES} slapd"
 
     elif [ X"${BACKEND}" == X'PGSQL' ]; then
-        cat > /var/db/ports/postgresql91/options <<EOF
+        cat > /var/db/ports/postgresql${WANT_PGSQL_VER}/options <<EOF
 WITH_NLS=true
 WITHOUT_DTRACE=true
 WITHOUT_PAM=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"
+        cat > /var/db/ports/postgresql${WANT_PGSQL_VER}-contrib/options <<EOF
+WITHOUT_OSSP_UUID=true
+EOF
+
+        ALL_PKGS="${ALL_PKGS} postgresql${WANT_PGSQL_VER}-server postgresql${WANT_PGSQL_VER}-contrib"
+        ALL_PORTS="${ALL_PORTS} databases/postgresql${WANT_PGSQL_VER}-server databases/postgresql${WANT_PGSQL_VER}-contrib"
         ENABLED_SERVICES="${ENABLED_SERVICES} ${PGSQL_RC_SCRIPT_NAME}"
     fi
 
 WITHOUT_FASTMTX=true
 EOF
         ALL_PKGS="${ALL_PKGS} mysql-server mysql-client"
-        ALL_PORTS="${ALL_PORTS} databases/mysql55-server"
+        ALL_PORTS="${ALL_PORTS} databases/mysql${WANT_MYSQL_VER}-server"
 
         ENABLED_SERVICES="${ENABLED_SERVICES} mysql-server"
     fi
 EOF
 
     ALL_PKGS="${ALL_PKGS} pcre postfix"
-    ALL_PORTS="${ALL_PORTS} devel/pcre mail/postfix27"
+    ALL_PORTS="${ALL_PORTS} devel/pcre mail/postfix${WANT_POSTFIX_VER}"
     ENABLED_SERVICES="${ENABLED_SERVICES} postfix"
     DISABLED_SERVICES="${DISABLED_SERVICES} sendmail sendmail_submit sendmail_outbound sendmail_msq_queue"
 
-    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
-WITH_ARC=true
-WITH_ARJ=true
-WITH_LHA=true
-WITH_UNZOO=true
-WITH_UNRAR=true
-WITH_ICONV=true
-WITHOUT_MILTER=true
-WITHOUT_LDAP=true
-WITHOUT_STDERR=true
-WITHOUT_EXPERIMENTAL=true
-EOF
-
-    ALL_PKGS="${ALL_PKGS} clamav"
-    ALL_PORTS="${ALL_PORTS} security/clamav"
-    ENABLED_SERVICES="${ENABLED_SERVICES} clamav-clamd clamav-freshclam"
-
     # Apr. DEPENDENCE.
     cat > /var/db/ports/apr/options <<EOF
 WITH_THREADS=true
 WITHOUT_JIS=true
 EOF
 
+    # PHP extensions
+    if [ X"${REQUIRE_PHP}" == X"YES" -o X"${USE_WEBMAIL}" == X"YES" ]; then
+        ALL_PKGS="${ALL_PKGS} php5-gd php5-imap php5-zip php5-bz2 php5-zlib php5-gettext php5-mbstring php5-mcrypt php5-mysql php5-mysqli php5-openssl php5-session php5-ldap php5-ctype php5-hash php5-iconv php5-pspell php5-dom php5-xml php5-sqlite"
+        ALL_PORTS="${ALL_PORTS} mail/php5-imap graphics/php5-gd archivers/php5-zip archivers/php5-bz2 archivers/php5-zlib devel/php5-gettext converters/php5-mbstring security/php5-mcrypt databases/php5-mysql security/php5-openssl www/php5-session net/php5-ldap textproc/php5-ctype security/php5-hash converters/php5-iconv textproc/php5-pspell textproc/php5-dom textproc/php5-xml databases/php5-sqlite databases/php5-mysqli"
+    fi
+
+    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
+WITH_ARC=true
+WITH_ARJ=true
+WITH_LHA=true
+WITH_UNZOO=true
+WITH_UNRAR=true
+WITH_ICONV=true
+WITHOUT_MILTER=true
+WITHOUT_LDAP=true
+WITHOUT_STDERR=true
+WITHOUT_EXPERIMENTAL=true
+EOF
+
+    ALL_PKGS="${ALL_PKGS} clamav"
+    ALL_PORTS="${ALL_PORTS} security/clamav"
+    ENABLED_SERVICES="${ENABLED_SERVICES} clamav-clamd clamav-freshclam"
+
     # Roundcube.
     cat > /var/db/ports/roundcube/options <<EOF
 WITH_MYSQL=true
 WITH_MYSQLCLIENT_R=true
 EOF
 
-    # PHP extensions
-    if [ X"${REQUIRE_PHP}" == X"YES" -o X"${USE_WEBMAIL}" == X"YES" ]; then
-        ALL_PKGS="${ALL_PKGS} php5-gd php5-imap php5-zip php5-bz2 php5-zlib php5-gettext php5-mbstring php5-mcrypt php5-mysql php5-mysqli php5-openssl php5-session php5-ldap php5-ctype php5-hash php5-iconv php5-pspell php5-dom php5-xml php5-sqlite"
-        ALL_PORTS="${ALL_PORTS} mail/php5-imap graphics/php5-gd archivers/php5-zip archivers/php5-bz2 archivers/php5-zlib devel/php5-gettext converters/php5-mbstring security/php5-mcrypt databases/php5-mysql security/php5-openssl www/php5-session net/php5-ldap textproc/php5-ctype security/php5-hash converters/php5-iconv textproc/php5-pspell textproc/php5-dom textproc/php5-xml databases/php5-sqlite databases/php5-mysqli"
-    fi
-
     # Roundcube webmail.
     if [ X"${USE_RCM}" == X"YES" ]; then
         ALL_PKGS="${ALL_PKGS} roundcube"
         ALL_PORTS="${ALL_PORTS} databases/phpmyadmin"
     fi
 
+    # phpPgAdmin
+    if [ X"${USE_PHPPGADMIN}" == X"YES" ]; then
+        ALL_PKGS="${ALL_PKGS} phppgadmin"
+        ALL_PORTS="${ALL_PORTS} databases/phppgadmin"
+    fi
+
     # iRedAPD.
     if [ X"${USE_IREDAPD}" == X"YES" ]; then
         # python-ldap.
     #fi
 
     # Fetch all source tarballs.
-    ECHO_INFO "==== Fetch all source tarballs of required components (make fetch-recursive) ===="
+    ECHO_INFO "Fetching all distfile for required packages (make fetch-recursive)"
+
     for i in ${ALL_PORTS}; do
         if [ X"${i}" != X'' ]; then
             portname="$( echo ${i} | tr -d '-' | tr -d '/' | tr -d '\.' )"
             status="\$status_fetch_port_$portname"
             if [ X"$(eval echo ${status})" != X"DONE" ]; then
+                ECHO_INFO "Fetching all distfiles for port: ${i}"
                 cd /usr/ports/${i} && make fetch-recursive
                 if [ X"$?" == X"0" ]; then
                     echo "export status_fetch_port_${portname}='DONE'" >> ${STATUS_FILE}
                     exit 255
                 fi
             else
-                ECHO_INFO "Skip fetching tarballs of port: ${i}."
+                ECHO_INFO "[SKIP] Fetching distfiles for port: ${i}."
             fi
         fi
     done
             status="\$status_install_port_$portname"
             if [ X"$(eval echo ${status})" != X"DONE" ]; then
                 cd /usr/ports/${i} && \
+                    ECHO_INFO "Installing port: ${i} ..." && \
                     make clean && \
-                    ECHO_INFO "Installing port: ${i} ..." && \
-                    make DEPENDS_TARGET=package package clean
+                    make install clean
 
                     if [ X"$?" == X"0" ]; then
                         echo "export status_install_port_${portname}='DONE'" >> ${STATUS_FILE}
                         exit 255
                     fi
             else
-                ECHO_INFO "Skip installing port: ${i}."
+                ECHO_INFO "[SKIP] Installing port: ${i}."
             fi
         fi
     done

iRedMail/functions/policy_server.sh

 
 policy_server_config()
 {
-    if [ X"${DISTRO_CODENAME}" != X"oneiric" \
-        -a X"${DISTRO_CODENAME}" != X"precise" \
-        ]; then
+    if [ X"${USE_POLICYD}" == X'YES' ]; then
         . ${FUNCTIONS_DIR}/policyd.sh
 
         ECHO_INFO "Configure Policyd (postfix policy server, version 1.8)."
         check_status_before_run policyd_user
         check_status_before_run policyd_config
-    else
+    fi
+
+    if [ X"${USE_CLUEBRINGER}" == X'YES' ]; then
         . ${FUNCTIONS_DIR}/cluebringer.sh
 
         ECHO_INFO "Configure Policyd (postfix policy server, code name cluebringer)."
         check_status_before_run cluebringer_webui_config
     fi
 
-    # FreeBSD: Start policyd when system start up.
-    freebsd_enable_service_in_rc_conf 'postfix_policyd_sf_enable' 'YES'
-
     echo 'export status_policy_server_config="DONE"' >> ${STATUS_FILE}
 }

iRedMail/functions/policyd.sh

 EOF
     fi
 
+    # FreeBSD: Start policyd when system start up.
+    freebsd_enable_service_in_rc_conf 'postfix_policyd_sf_enable' 'YES'
+
     # Set cron file permission: root:root, 0600.
     chmod 0600 ${CRON_SPOOL_DIR}/${POLICYD_USER}
 

iRedMail/functions/postgresql.sh

     if [ X"${DISTRO}" == X"FREEBSD" ]; then
         freebsd_enable_service_in_rc_conf 'postgresql_enable' 'YES'
 
-        su - ${PGSQL_SYS_USER} -c "${PGSQL_RC_SCRIPT} initdb" >/dev/null
+        ${PGSQL_RC_SCRIPT} initdb >/dev/null
     fi
 
     backup_file ${PGSQL_CONF_PG_HBA} ${PGSQL_CONF_POSTGRESQL}
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.