diff --git a/unattended_installer/builder.sh b/unattended_installer/builder.sh index 867b5f541b..2e89e00804 100755 --- a/unattended_installer/builder.sh +++ b/unattended_installer/builder.sh @@ -99,6 +99,12 @@ function buildInstaller() { ## JAVA_HOME echo "export JAVA_HOME=\"/usr/share/wazuh-indexer/jdk/\"" >> "${output_script_path}" + echo "set -o pipefail" >> "${output_script_path}" + echo "shopt -s expand_aliases" >> "${output_script_path}" + + echo "alias try=\"(set -e;\"" >> "${output_script_path}" + echo "alias catch=\" ); Error \\\$? || \"" >> "${output_script_path}" + ## Functions for all install function modules install_modules=($(find "${resources_installer}" -type f)) install_modules_names=($(eval "echo \"${install_modules[*]}\" | sed 's,${resources_installer}/,,g'")) diff --git a/unattended_installer/common_functions/common.sh b/unattended_installer/common_functions/common.sh index 199d7ef630..bbba33f55a 100644 --- a/unattended_installer/common_functions/common.sh +++ b/unattended_installer/common_functions/common.sh @@ -68,9 +68,9 @@ function common_checkInstalled() { dashboard_installed="" if [ "${sys_type}" == "yum" ]; then - wazuh_installed=$(yum list installed 2>/dev/null | grep wazuh-manager) + wazuh_installed=$(yum list installed 2>/dev/null | grep wazuh-manager || true) elif [ "${sys_type}" == "apt-get" ]; then - wazuh_installed=$(apt list --installed 2>/dev/null | grep wazuh-manager) + wazuh_installed=$(apt list --installed 2>/dev/null | grep wazuh-manager || true) fi if [ -d "/var/ossec" ]; then @@ -78,9 +78,9 @@ function common_checkInstalled() { fi if [ "${sys_type}" == "yum" ]; then - indexer_installed=$(yum list installed 2>/dev/null | grep wazuh-indexer) + indexer_installed=$(yum list installed 2>/dev/null | grep wazuh-indexer || true) elif [ "${sys_type}" == "apt-get" ]; then - indexer_installed=$(apt list --installed 2>/dev/null | grep wazuh-indexer) + indexer_installed=$(apt list --installed 2>/dev/null | grep wazuh-indexer || true) fi if [ -d "/var/lib/wazuh-indexer/" ] || [ -d "/usr/share/wazuh-indexer" ] || [ -d "/etc/wazuh-indexer" ] || [ -f "${base_path}/search-guard-tlstool*" ]; then @@ -88,9 +88,9 @@ function common_checkInstalled() { fi if [ "${sys_type}" == "yum" ]; then - filebeat_installed=$(yum list installed 2>/dev/null | grep filebeat) + filebeat_installed=$(yum list installed 2>/dev/null | grep filebeat || true) elif [ "${sys_type}" == "apt-get" ]; then - filebeat_installed=$(apt list --installed 2>/dev/null | grep filebeat) + filebeat_installed=$(apt list --installed 2>/dev/null | grep filebeat || true) fi if [ -d "/var/lib/filebeat/" ] || [ -d "/usr/share/filebeat" ] || [ -d "/etc/filebeat" ]; then @@ -98,9 +98,9 @@ function common_checkInstalled() { fi if [ "${sys_type}" == "yum" ]; then - dashboard_installed=$(yum list installed 2>/dev/null | grep wazuh-dashboard) + dashboard_installed=$(yum list installed 2>/dev/null | grep wazuh-dashboard || true) elif [ "${sys_type}" == "apt-get" ]; then - dashboard_installed=$(apt list --installed 2>/dev/null | grep wazuh-dashboard) + dashboard_installed=$(apt list --installed 2>/dev/null | grep wazuh-dashboard || true) fi if [ -d "/var/lib/wazuh-dashboard/" ] || [ -d "/usr/share/wazuh-dashboard" ] || [ -d "/etc/wazuh-dashboard" ] || [ -d "/run/wazuh-dashboard/" ]; then diff --git a/unattended_installer/install_functions/error.sh b/unattended_installer/install_functions/error.sh new file mode 100644 index 0000000000..14b51b5b85 --- /dev/null +++ b/unattended_installer/install_functions/error.sh @@ -0,0 +1,15 @@ +# Wazuh installer - dashboard.sh functions. +# Copyright (C) 2015, Wazuh Inc. +# +# This program is a free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License (version 2) as published by the FSF - Free Software +# Foundation. + +function Error() { + local retVal=$1 + if [[ $retVal -gt 0 ]] + then + return 1 + fi +} \ No newline at end of file diff --git a/unattended_installer/install_functions/installMain.sh b/unattended_installer/install_functions/installMain.sh index fd49ae3d19..1a757f224a 100755 --- a/unattended_installer/install_functions/installMain.sh +++ b/unattended_installer/install_functions/installMain.sh @@ -254,11 +254,17 @@ function main() { # -------------- Wazuh indexer case ------------------------------- if [ -n "${indexer}" ]; then - common_logger "--- Wazuh indexer ---" - indexer_install - indexer_configure - installCommon_startService "wazuh-indexer" - indexer_initialize + try { + common_logger "--- Wazuh indexer ---" + indexer_install + indexer_configure + installCommon_startService "wazuh-indexer" + indexer_initialize + } catch { + common_logger "Wazuh-indexer installation failed" + indexer_installed="true" + installCommon_rollBack + } fi # -------------- Start Wazuh indexer cluster case ------------------ @@ -273,11 +279,17 @@ function main() { if [ -n "${dashboard}" ]; then common_logger "--- Wazuh dashboard ----" - dashboard_install - dashboard_configure - installCommon_startService "wazuh-dashboard" - installCommon_changePasswords - dashboard_initialize + try { + dashboard_install + dashboard_configure + installCommon_startService "wazuh-dashboard" + installCommon_changePasswords + dashboard_initialize + } catch { + common_logger "Wazuh-dashboard installation failed" + dashboard_installed="true" + installCommon_rollBack + } fi @@ -285,39 +297,56 @@ function main() { if [ -n "${wazuh}" ]; then common_logger "--- Wazuh server ---" - - manager_install - if [ -n "${server_node_types[*]}" ]; then - manager_startCluster - fi - installCommon_startService "wazuh-manager" - filebeat_install - filebeat_configure - installCommon_changePasswords - installCommon_startService "filebeat" + try { + manager_install + if [ -n "${server_node_types[*]}" ]; then + manager_startCluster + fi + installCommon_startService "wazuh-manager" + } catch { + common_logger "Wazuh-manager installation failed" + wazuh_installed="true" + installCommon_rollBack + } + + try { + filebeat_install + filebeat_configure + installCommon_changePasswords + installCommon_startService "filebeat" + } catch { + common_logger "Filebeat installation failed" + filebeat_installed="true" + installCommon_rollBack + } fi # -------------- AIO case ------------------------------------------ if [ -n "${AIO}" ]; then - common_logger "--- Wazuh indexer ---" - indexer_install - indexer_configure - installCommon_startService "wazuh-indexer" - indexer_initialize - common_logger "--- Wazuh server ---" - manager_install - installCommon_startService "wazuh-manager" - filebeat_install - filebeat_configure - installCommon_startService "filebeat" - common_logger "--- Wazuh dashboard ---" - dashboard_install - dashboard_configure - installCommon_startService "wazuh-dashboard" - installCommon_changePasswords - dashboard_initializeAIO + try { + common_logger "--- Wazuh indexer ---" + indexer_install + indexer_configure + installCommon_startService "wazuh-indexer" + indexer_initialize + common_logger "--- Wazuh server ---" + manager_install + installCommon_startService "wazuh-manager" + filebeat_install + filebeat_configure + installCommon_startService "filebeat" + common_logger "--- Wazuh dashboard ---" + dashboard_install + dashboard_configure + installCommon_startService "wazuh-dashboard" + installCommon_changePasswords + dashboard_initializeAIO + } catch { + common_logger "AIO installation failed" + installCommon_rollBack + } fi