Commits

Zhang Huangbin committed cf0e346

Fix incorrect policyd package name on RHEL/SUSE.
New variables for automate installation:
- AUTO_USE_EXISTING_CONFIG_FILE
- AUTO_INSTALL_WITHOUT_CONFIRM
- AUTO_CLEANUP_REMOVE_SENDMAIL
- AUTO_CLEANUP_REMOVE_MOD_PYTHON
- AUTO_CLEANUP_REPLACE_IPTABLES_RULE
- AUTO_CLEANUP_RESTART_IPTABLES
- AUTO_CLEANUP_REPLACE_MYSQL_CONFIG
- AUTO_CLEANUP_RESTART_POSTFIX

Comments (0)

Files changed (5)

iRedMail/conf/core

         if [ X"$?" == X"0" ]; then
             echo -e " [FOUND]"
             ECHO_QUESTION -n "Use it for mail server setting? [y|N]"
-            read ANSWER
-
-            case  $ANSWER in
+            read_setting ${AUTO_USE_EXISTING_CONFIG_FILE}
+            case $ANSWER in
                 Y|y )
                     ECHO_INFO "Use config file: ${CONFIG_FILE} for mail server setting."
                     . ${CONFIG_FILE}
     fi
 }
 
+read_setting()
+{
+    answer="${1}"
+    if [ ! -z "${answer}" ]; then
+        ANSWER="${answer}"
+        echo ${ANSWER}
+    else
+        read ANSWER
+    fi
+}
+
 hash_domain()
 {
     # Usage: hash_domain domain

iRedMail/conf/policy_server

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

iRedMail/dialog/config_via_dialog.sh

 EOF
 
 ECHO_QUESTION -n "Continue? [y|N]"
-read ANSWER
-
+read_setting ${AUTO_INSTALL_WITHOUT_CONFIRM}
 case ${ANSWER} in
     Y|y) : ;;
     N|n|*)

iRedMail/functions/cleanup.sh

 # along with iRedMail.  If not, see <http://www.gnu.org/licenses/>.
 #---------------------------------------------------------------------
 
+# Available variables for automate installation (value should be 'y' or 'n'):
+#   AUTO_CLEANUP_REMOVE_SENDMAIL
+#   AUTO_CLEANUP_REMOVE_MOD_PYTHON
+#   AUTO_CLEANUP_REPLACE_IPTABLES_RULE
+#   AUTO_CLEANUP_RESTART_IPTABLES
+#   AUTO_CLEANUP_REPLACE_MYSQL_CONFIG
+#   AUTO_CLEANUP_RESTART_POSTFIX
+#
+# Usage:
+#   # AUTO_CLEANUP_REMOVE_SENDMAIL=y [...] bash iRedMail.sh
+
 # -------------------------------------------
 # Misc.
 # -------------------------------------------
 
     if [ X"$?" == X"0" ]; then
         ECHO_QUESTION -n "Would you like to *REMOVE* sendmail now? [Y|n]"
-        read ANSWER
+        read_setting ${AUTO_CLEANUP_REMOVE_SENDMAIL}
         case $ANSWER in
             N|n )
                 ECHO_INFO "Disable sendmail, it is replaced by Postfix." && \
 
     if [ X"$?" == X"0" ]; then
         ECHO_QUESTION -n "iRedAdmin doesn't work with mod_python, *REMOVE* it now? [Y|n]"
-        read ANSWER
+        read_setting ${AUTO_CLEANUP_REMOVE_MOD_PYTHON}
         case $ANSWER in
             N|n ) : ;;
             Y|y|* ) eval ${remove_pkg} mod_python ;;
 
     ECHO_QUESTION "Would you like to use firewall rules shipped within iRedMail now?"
     ECHO_QUESTION -n "File: ${IPTABLES_CONFIG}, with SSHD port: ${sshd_port}. [Y|n]"
-    read ANSWER
+    read_setting ${AUTO_CLEANUP_REPLACE_IPTABLES_RULE}
     case $ANSWER in
         N|n ) ECHO_INFO "Skip firewall rules." ;;
         Y|y|* ) 
 
             # Prompt to restart iptables.
             ECHO_QUESTION -n "Restart firewall now (with SSHD port ${sshd_port})? [y|N]"
-            read ANSWER
+            read_setting ${AUTO_CLEANUP_RESTART_IPTABLES}
             case $ANSWER in
                 Y|y )
                     ECHO_INFO "Restarting firewall ..."
 cleanup_replace_mysql_config()
 {
     if [ X"${BACKEND}" == X"MYSQL" -o X"${BACKEND}" == X"OPENLDAP" ]; then
-        # Both MySQL and OpenLDAP will need MySQL database server, so prompt
+        # Both MySQL and OpenLDAP backend need MySQL database server, so prompt
         # this config file replacement.
         ECHO_QUESTION "Would you like to use MySQL configuration file shipped within iRedMail now?"
         ECHO_QUESTION -n "File: ${MYSQL_MY_CNF}. [Y|n]"
-        read ANSWER
+        read_setting ${AUTO_CLEANUP_REPLACE_MYSQL_CONFIG}
         case $ANSWER in
             N|n ) ECHO_INFO "Skip copy and modify MySQL config file." ;;
             Y|y|* )
 {
     # Start postfix without reboot your system.
     ECHO_QUESTION -n "Would you like to start postfix now? [y|N]"
-    read ANSWER
+    read_setting ${AUTO_CLEANUP_RESTART_POSTFIX}
     case ${ANSWER} in
         Y|y )
             # Disable SELinux.

iRedMail/functions/packages.sh

 
     # Policyd.
     if [ X"${DISTRO}" == X"RHEL" ]; then
-        ALL_PKGS="${ALL_PKGS} cluebringer"
-        ENABLED_SERVICES="${ENABLED_SERVICES} ${CLUEBRINGER_RC_SCRIPT_NAME}"
+        if [ X"${USE_POLICYD}" == X'YES' ]; then
+            ALL_PKGS="${ALL_PKGS} policyd${PKG_ARCH}"
+            ENABLED_SERVICES="${ENABLED_SERVICES} ${POLICYD_RC_SCRIPT_NAME}"
+        else
+            ALL_PKGS="${ALL_PKGS} cluebringer"
+            ENABLED_SERVICES="${ENABLED_SERVICES} ${CLUEBRINGER_RC_SCRIPT_NAME}"
+        fi
     elif [ X"${DISTRO}" == X"SUSE" ]; then
-        ALL_PKGS="${ALL_PKGS} cluebringer"
-        ENABLED_SERVICES="${ENABLED_SERVICES} ${POLICYD_RC_SCRIPT_NAME}"
+        if [ X"${USE_POLICYD}" == X'YES' ]; then
+            ALL_PKGS="${ALL_PKGS} policyd"
+            ENABLED_SERVICES="${ENABLED_SERVICES} ${POLICYD_RC_SCRIPT_NAME}"
+        else
+            ALL_PKGS="${ALL_PKGS} cluebringer"
+            ENABLED_SERVICES="${ENABLED_SERVICES} ${CLUEBRINGER_RC_SCRIPT_NAME}"
+        fi
     elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
         if [ X"${DISTRO_CODENAME}" == X"oneiric" \
             -o X"${DISTRO_CODENAME}" == X"precise" \