#!/usr/bin/env bash # Author: Zhang Huangbin #--------------------------------------------------------------------- # 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 . #--------------------------------------------------------------------- install_all() { # Port name under /usr/ports/. e.g. mail/dovecot. ALL_PORTS='' # Ports which are going to be bulit with Python 2. # Installed with command `make USES=python2.7 install clean`. PY2_PORTS='' # Extension used for backup file during in-place editing. SED_EXTENSION="iredmail" CMD_SED="sed -i ${SED_EXTENSION}" # Make it don't popup dialog while building ports. export PACKAGE_BUILDING='yes' export BATCH='yes' # Preferred package versions. Don't forget to update DEFAULT_VERSIONS below. export PREFERRED_OPENLDAP_VER='24' export PREFERRED_MARIADB_VER='104' export PREFERRED_BDB_VER='5' export PREFERRED_PHP_VER='74' export PREFERRED_PY3_VER='3.8' if [ X"${WEB_SERVER}" == X'NGINX' ]; then export IREDMAIL_USE_PHP='YES' fi freebsd_make_conf_add 'WANT_OPENLDAP_VER' "${PREFERRED_OPENLDAP_VER}" freebsd_make_conf_add 'WANT_OPENLDAP_SASL' "YES" freebsd_make_conf_add 'WANT_PGSQL_VER' "${PGSQL_VERSION}" freebsd_make_conf_add 'WANT_BDB_VER' "${PREFERRED_BDB_VER}" freebsd_make_conf_add 'DEFAULT_VERSIONS' "ssl=libressl python=${PREFERRED_PY3_VER} python2=2.7 python3=${PREFERRED_PY3_VER} pgsql=${PGSQL_VERSION} php=7.4 mysql=10.4m ruby=2.7" freebsd_make_conf_plus_option 'OPTIONS_SET' 'SASL' freebsd_make_conf_plus_option 'OPTIONS_UNSET' 'X11' freebsd_make_conf_plus_option 'LICENSES_ACCEPTED' 'DCC' for p in \ archivers_arj \ archivers_p5-Archive-Tar \ archivers_p7zip \ archivers_rar \ converters_libiconv \ databases_postgresql${PGSQL_VERSION}-client \ databases_postgresql${PGSQL_VERSION}-contrib \ databases_postgresql${PGSQL_VERSION}-server \ databases_mariadb${PREFERRED_MARIADB_VER}-server \ databases_mariadb${PREFERRED_MARIADB_VER}-client \ databases_py-sqlalchemy10 \ devel_cmake \ devel_apr1 \ devel_dbus \ devel_m4 \ devel_py-Jinja2 \ devel_py-babel \ devel_sope4 \ dns_p5-Net-DNS \ dns_py-dnspython \ ftp_curl \ mail_spamassassin \ lang_perl5.20 \ lang_php${PREFERRED_PHP_VER} \ lang_php${PREFERRED_PHP_VER}-extensions \ www_mod_php${PREFERRED_PHP_VER} \ graphics_php${PREFERRED_PHP_VER}-gd \ graphics_cairo \ www_pecl-APC \ lang_python27 \ mail_dovecot \ mail_postfix \ mail_roundcube \ net_openldap${PREFERRED_OPENLDAP_VER}-client \ net_openldap${PREFERRED_OPENLDAP_VER}-sasl-client \ net_openldap${PREFERRED_OPENLDAP_VER}-server \ net_openslp \ net_py-ldap \ net-mgmt_netdata \ security_amavisd-new \ security_ca_root_nss \ security_clamav \ security_cyrus-sasl2 \ security_gnupg \ security_libssh2 \ security_p5-Authen-SASL \ security_p5-IO-Socket-SSL \ www_nginx \ www_uwsgi \ www_sogo4; do mkdir -p /var/db/ports/${p} >> ${INSTALL_LOG} 2>&1 done # cmake. DEPENDENCE cat > /var/db/ports/devel_cmake/options < /var/db/ports/devel_dbus/options < /var/db/ports/devel_m4/options < /var/db/ports/converters_libiconv/options < /var/db/ports/archivers_arj/options < /var/db/ports/security_cyrus-sasl2/options < /var/db/ports/lang_perl5.20/options < /var/db/ports/net_openslp/options < /var/db/ports/net_openldap${PREFERRED_OPENLDAP_VER}-server/options < /var/db/ports/net_openldap${PREFERRED_OPENLDAP_VER}-client/options < /var/db/ports/net_openldap${PREFERRED_OPENLDAP_VER}-sasl-client/options < /var/db/ports/databases_postgresql${PGSQL_VERSION}-server/options < /var/db/ports/databases_postgresql${PGSQL_VERSION}-client/options < /var/db/ports/databases_mariadb${PREFERRED_MARIADB_VER}-server/options < /var/db/ports/databases_mariadb${PREFERRED_MARIADB_VER}-client/options < /var/db/ports/mail_dovecot/options </dev/null # ca_root_nss. DEPENDENCE. cat > /var/db/ports/security_ca_root_nss/options < /var/db/ports/security_libssh2/options < /var/db/ports/ftp_curl/options < /var/db/ports/security_gnupg/options < /var/db/ports/security_p5-IO-Socket-SSL/options < /var/db/ports/archivers_p5-Archive-Tar/options < /var/db/ports/archivers_p7zip/options < /var/db/ports/archivers_rar/options < /var/db/ports/dns_p5-Net-DNS/options < /var/db/ports/dns_py-dnspython/options < /var/db/ports/mail_spamassassin/options </dev/null ALL_PORTS="${ALL_PORTS} mail/spamassassin" cat > /var/db/ports/security_p5-Authen-SASL/options < /var/db/ports/security_amavisd-new/options </dev/null ALL_PORTS="${ALL_PORTS} security/amavisd-new" # Postfix. REQUIRED. cat > /var/db/ports/mail_postfix/options </dev/null ALL_PORTS="${ALL_PORTS} mail/postfix" # Apr. DEPENDENCE. cat > /var/db/ports/devel_apr1/options </dev/null # Python v2.7 cat > /var/db/ports/lang_python27/options < /var/db/ports/www_nginx/options < /var/db/ports/www_uwsgi/options < /var/db/ports/lang_php${PREFERRED_PHP_VER}/options < /var/db/ports/lang_php${PREFERRED_PHP_VER}-extensions/options </dev/null cat > /var/db/ports/graphics_php${PREFERRED_PHP_VER}-gd/options < /var/db/ports/graphics_cairo/options < /var/db/ports/www_mod_php${PREFERRED_PHP_VER}/options < /var/db/ports/www_pecl-APC/options < /var/db/ports/security_clamav/options < /var/db/ports/mail_roundcube/options </dev/null cat > /var/db/ports/devel_py-Jinja2/options < /var/db/ports/devel_py-babel/options < /var/db/ports/devel_sope4/options < /var/db/ports/www_sogo4/options </dev/null fi # Python database interfaces if [ X"${BACKEND}" == X'OPENLDAP' ]; then ALL_PORTS="${ALL_PORTS} net/py-ldap databases/py-pymysql" PY2_PORTS="${PY2_PORTS} net/py-ldap databases/py-pymysql" elif [ X"${BACKEND}" == X'MYSQL' ]; then ALL_PORTS="${ALL_PORTS} databases/py-pymysql" PY2_PORTS="${PY2_PORTS} databases/py-pymysql" elif [ X"${BACKEND}" == X'PGSQL' ]; then ALL_PORTS="${ALL_PORTS} databases/py-psycopg2" fi # py-sqlalchemy ALL_PORTS="${ALL_PORTS} databases/py-sqlalchemy10" cat > /var/db/ports/databases_py-sqlalchemy10/options < /var/db/ports/net_py-ldap/options < /var/db/ports/net-mgmt_netdata/options <> ${STATUS_FILE} else ECHO_ERROR "Tarballs were not downloaded correctly, please fix it manually and then re-execute iRedMail.sh." exit 255 fi else ECHO_SKIP "Fetching all distfiles for port ${i} and dependencies" fi fi done echo "export status_fetch_all_src_tarballs='DONE'" >> ${STATUS_FILE} } install_port() { # Usage: install_port [make_flags] _port="${1}" shift 1 _flags="$@" ECHO_INFO "Install port: ${_port}" start_time="$(date +%s)" if [ X"${_port}" != X'' ]; then # Remove special characters in port name: -, /, '.'. _portname="$( echo ${_port} | tr '/' '_' | tr -d '[-\.]')" _status="\$status_install_port_${IREDMAIL_PORT_PKG_NAME_PREFIX}${_portname}" _status_name="$(echo ${_status} | tr -d '$')" if [ X"$(eval echo ${_status})" != X"DONE" ]; then _port_dir="${PORT_WORKDIRPREFIX}/${_port}" if [[ ! -d ${_port_dir} ]]; then echo "Port directory ${_port_dir} doesn't exist." exit 255 fi cd ${_port_dir} ECHO_INFO "Installing port: ${_port} ($(date '+%Y-%m-%d %H:%M:%S')) ..." echo "export ${_status_name}='processing'" >> ${STATUS_FILE} if echo "${_port}" | grep '/py' &>/dev/null; then # Some ports use zip archive instead of default `.tar.gz`. if grep '^USES' ${_port_dir}/Makefile | grep '\' &>/dev/null; then _flags="${_flags} USES+=zip" fi fi # Get time as a UNIX timestamp (seconds elapsed since Jan 1, 1970 0:00 UTC) port_start_time="$(date +%s)" # Clean up and compile make clean make \ DISABLE_MAKE_JOBS=yes \ ${_flags} \ install clean if [ X"$?" == X"0" ]; then # Log used time used_time="$(($(date +%s)-port_start_time))" echo "export ${_status_name}='DONE' # ${used_time} seconds, ~= $((used_time/60)) minute(s)." >> ${STATUS_FILE} else ECHO_ERROR "Port was not successfully installed, please fix it manually and then re-execute this script." exit 255 fi else ECHO_SKIP "Installing port: ${_port}." fi fi } # Install all packages. install_all_ports() { ECHO_INFO "All ports: ${ALL_PORTS}" ECHO_INFO "All ports for Python 2: ${PY2_PORTS}" start_time="$(date +%s)" for _port in ${ALL_PORTS}; do if echo "${_port}" | grep -E '(/py|uwsgi)' &>/dev/null; then # Install modules for Python 3. install_port ${_port} USES=python:${PREFERRED_PY3_VER} else install_port ${_port} fi done export IREDMAIL_PORT_PKG_NAME_PREFIX='py27_' for _port in ${PY2_PORTS}; do # Install for Python 2. install_port ${_port} USES=python:2.7 done unset IREDMAIL_PORT_PKG_NAME_PREFIX # Log and print used time all_used_time="$(($(date +%s)-start_time))" ECHO_INFO "Total time of ports compiling: ${all_used_time} seconds, ~= $((all_used_time/60)) minute(s)" } # Install all packages. post_install_cleanup() { ECHO_DEBUG "Post-install cleanup." ECHO_DEBUG "Create symbol links for python2/3." ln -sf /usr/local/bin/python2.7 /usr/local/bin/python2 ln -sf /usr/local/bin/python${PREFERRED_PY3_VER} /usr/local/bin/python3 # Create syslog.d and logrotate.d mkdir -p ${SYSLOG_CONF_DIR} >> ${INSTALL_LOG} 2>&1 mkdir -p ${LOGROTATE_DIR} >> ${INSTALL_LOG} 2>&1 echo "export status_post_install_cleanup='DONE'" >> ${STATUS_FILE} } check_status_before_run fetch_all_src_tarballs # Do not run it with 'check_status_before_run', so that we can always # install missed packages and enable/disable new services while re-run # iRedMail installer. install_all_ports check_status_before_run post_install_cleanup }