Browse Source

Validate email/hostname non interactive install (#2532)

* Validate email/hostname non interactive install

+ Move FM / PHPMailer to a earlier step to prevent mail system failure when nginx / apache2 doesn't restart

* Update spacing.

* Update spacing.

Co-authored-by: Raphael <rs@scit.ch>
Jaap Marcus 3 years ago
parent
commit
46d8c2fe76
2 changed files with 91 additions and 87 deletions
  1. 43 40
      install/hst-install-debian.sh
  2. 48 47
      install/hst-install-ubuntu.sh

+ 43 - 40
install/hst-install-debian.sh

@@ -603,41 +603,42 @@ if [ "$interactive" = 'yes' ]; then
         echo 'Goodbye'
         exit 1
     fi
+fi
 
-    # Asking for contact email
-    if [ -z "$email" ]; then
-        while validate_email; do
+# Validate Email / Hostname even when interactive = no 
+# Asking for contact email
+if [ -z "$email" ]; then
+    while validate_email; do
         echo -e "\nPlease use a valid emailadress (ex. info@domain.tld)."
         read -p 'Please enter admin email address: ' email
-        done
-    else
-      if validate_email; then
-      echo "Please use a valid emailadress (ex. info@domain.tld)."
-      exit 1
-      fi
+    done
+else
+    if validate_email; then
+        echo "Please use a valid emailadress (ex. info@domain.tld)."
+        exit 1
     fi
+fi
 
-    # Asking to set FQDN hostname
-    if [ -z "$servername" ]; then
-        # Ask and validate FQDN hostname.
-        read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
+# Asking to set FQDN hostname
+if [ -z "$servername" ]; then
+    # Ask and validate FQDN hostname.
+    read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
 
-        # Set hostname if it wasn't set
-        if [ -z "$servername" ]; then
-            servername=$(hostname -f)
-        fi
+    # Set hostname if it wasn't set
+    if [ -z "$servername" ]; then
+        servername=$(hostname -f)
+    fi
 
-        # Validate Hostname, go to loop if the validation fails.
-        while validate_hostname; do
-            echo -e "\nPlease use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
-            read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
-        done
-    else
-        # Validate FQDN hostname if it is preset
-        if validate_hostname; then
-            echo "Please use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
-            exit 1
-        fi
+    # Validate Hostname, go to loop if the validation fails.
+    while validate_hostname; do
+        echo -e "\nPlease use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
+        read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
+    done
+else
+    # Validate FQDN hostname if it is preset
+    if validate_hostname; then
+        echo "Please use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
+        exit 1
     fi
 fi
 
@@ -1886,6 +1887,20 @@ if [ "$sieve" = 'yes' ]; then
     systemctl restart exim4 > /dev/null 2>&1
 fi
 
+#----------------------------------------------------------#
+#                  Configure File Manager                  #
+#----------------------------------------------------------#
+
+echo "[ * ] Configuring File Manager..."
+$HESTIA/bin/v-add-sys-filemanager quiet
+
+#----------------------------------------------------------#
+#                  Configure PHPMailer                     #
+#----------------------------------------------------------#
+
+echo "[ * ] Configuring PHPMailer..."
+$HESTIA/bin/v-add-sys-phpmailer quiet
+
 #----------------------------------------------------------#
 #                       Configure API                      #
 #----------------------------------------------------------#
@@ -2022,12 +2037,6 @@ chmod 755 /backup/
 # create cronjob to generate ssl 
 echo "@reboot root sleep 10 && rm /etc/cron.d/hestia-ssl && PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:' && /usr/local/hestia/bin/v-add-letsencrypt-host" > /etc/cron.d/hestia-ssl
 
-#----------------------------------------------------------#
-#                  Configure File Manager                  #
-#----------------------------------------------------------#
-
-echo "[ * ] Configuring File Manager..."
-$HESTIA/bin/v-add-sys-filemanager quiet
 
 #----------------------------------------------------------#
 #              Set hestia.conf default values              #
@@ -2058,12 +2067,6 @@ write_config_value "SERVER_SMTP_PASSWD" ""
 write_config_value "SERVER_SMTP_ADDR" ""
 write_config_value "POLICY_CSRF_STRICTNESS" "1"
 
-#----------------------------------------------------------#
-#                  Configure PHPMailer                     #
-#----------------------------------------------------------#
-
-echo "[ * ] Configuring PHPMailer..."
-$HESTIA/bin/v-add-sys-phpmailer quiet
 
 #----------------------------------------------------------#
 #                   Hestia Access Info                     #

+ 48 - 47
install/hst-install-ubuntu.sh

@@ -575,44 +575,45 @@ if [ "$interactive" = 'yes' ]; then
         echo 'Goodbye'
         exit 1
     fi
+fi
 
-  # Asking for contact email
-  if [ -z "$email" ]; then
-      while validate_email; do
-      echo -e "\nPlease use a valid emailadress (ex. info@domain.tld)."
-      read -p 'Please enter admin email address: ' email
-      done
-  else
+# Validate Email / Hostname even when interactive = no 
+# Asking for contact email
+if [ -z "$email" ]; then
+    while validate_email; do
+        echo -e "\nPlease use a valid emailadress (ex. info@domain.tld)."
+        read -p 'Please enter admin email address: ' email
+    done
+else
     if validate_email; then
-    echo "Please use a valid emailadress (ex. info@domain.tld)."
-    exit 1
-    fi
-  fi
-  
-    # Asking to set FQDN hostname
-    if [ -z "$servername" ]; then
-        # Ask and validate FQDN hostname.
-        read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
-
-        # Set hostname if it wasn't set
-        if [ -z "$servername" ]; then
-            servername=$(hostname -f)
-        fi
-
-        # Validate Hostname, go to loop if the validation fails.
-        while validate_hostname; do
-            echo -e "\nPlease use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
-            read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
-        done
-    else
-        # Validate FQDN hostname if it is preset
-        if validate_hostname; then
-            echo "Please use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
-            exit 1
-        fi
+      echo "Please use a valid emailadress (ex. info@domain.tld)."
+      exit 1
     fi
 fi
 
+  # Asking to set FQDN hostname
+  if [ -z "$servername" ]; then
+      # Ask and validate FQDN hostname.
+      read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
+
+      # Set hostname if it wasn't set
+      if [ -z "$servername" ]; then
+          servername=$(hostname -f)
+      fi
+
+      # Validate Hostname, go to loop if the validation fails.
+      while validate_hostname; do
+          echo -e "\nPlease use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
+          read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
+      done
+  else
+      # Validate FQDN hostname if it is preset
+      if validate_hostname; then
+          echo "Please use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
+          exit 1
+      fi
+  fi
+
 # Generating admin password if it wasn't set
 if [ -z "$vpass" ]; then
     vpass=$(gen_pass)
@@ -1910,6 +1911,20 @@ else
     $HESTIA/bin/v-change-sys-api disable
 fi
 
+#----------------------------------------------------------#
+#                  Configure File Manager                  #
+#----------------------------------------------------------#
+
+echo "[ * ] Configuring File Manager..."
+$HESTIA/bin/v-add-sys-filemanager quiet
+
+#----------------------------------------------------------#
+#                  Configure PHPMailer                     #
+#----------------------------------------------------------#
+
+echo "[ * ] Configuring PHPMailer..."
+$HESTIA/bin/v-add-sys-phpmailer quiet
+
 
 #----------------------------------------------------------#
 #                   Configure IP                           #
@@ -2048,13 +2063,6 @@ chmod 755 /backup/
 # create cronjob to generate ssl 
 echo "@reboot root sleep 10 && rm /etc/cron.d/hestia-ssl && PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:' && /usr/local/hestia/bin/v-add-letsencrypt-host" > /etc/cron.d/hestia-ssl
 
-#----------------------------------------------------------#
-#                  Configure File Manager                  #
-#----------------------------------------------------------#
-
-echo "[ * ] Configuring File Manager..."
-$HESTIA/bin/v-add-sys-filemanager quiet
-
 #----------------------------------------------------------#
 #              Set hestia.conf default values              #
 #----------------------------------------------------------#
@@ -2084,13 +2092,6 @@ write_config_value "SERVER_SMTP_PASSWD" ""
 write_config_value "SERVER_SMTP_ADDR" ""
 write_config_value "POLICY_CSRF_STRICTNESS" "1"
 
-#----------------------------------------------------------#
-#                  Configure PHPMailer                     #
-#----------------------------------------------------------#
-
-echo "[ * ] Configuring PHPMailer..."
-$HESTIA/bin/v-add-sys-phpmailer quiet
-
 #----------------------------------------------------------#
 #                   Hestia Access Info                     #
 #----------------------------------------------------------#