From 4b8cda99592d5d767e09569ebec5919a20686add Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Sat, 29 Jan 2022 16:04:45 -0300 Subject: [PATCH 1/9] Fix use of rollBack with overwrite, start_elastic_cluster and add function checkTools --- .../install_functions/opendistro/checks.sh | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/unattended_installer/install_functions/opendistro/checks.sh b/unattended_installer/install_functions/opendistro/checks.sh index aefa1281b8..4180ccb10d 100644 --- a/unattended_installer/install_functions/opendistro/checks.sh +++ b/unattended_installer/install_functions/opendistro/checks.sh @@ -74,6 +74,7 @@ function checkArguments() { if [ -n "${wazuhinstalled}" ] || [ -n "${wazuh_remaining_files}" ] || [ -n "${elasticsearchinstalled}" ] || [ -n "${elastic_remaining_files}" ] || [ -n "${filebeatinstalled}" ] || [ -n "${filebeat_remaining_files}" ] || [ -n "${kibanainstalled}" ] || [ -n "${kibana_remaining_files}" ]; then if [ -n "${overwrite}" ]; then + uninstall_module_name="wazuh" rollBack else logger -e "Some the Wazuh components were found on this host. If you want to overwrite the current installation, run this script back using the option -o/--overwrite. NOTE: This will erase all the existing configuration and data." @@ -88,6 +89,7 @@ function checkArguments() { if [ -n "${elasticsearchinstalled}" ] || [ -n "${elastic_remaining_files}" ]; then if [ -n "${overwrite}" ]; then + uninstall_module_name="elasticsearch" rollBack else logger -e "Elasticsearch is already installed in this node or some of its files haven't been erased. Use option -o|--overwrite to overwrite all components." @@ -101,6 +103,7 @@ function checkArguments() { if [ -n "${kibana}" ]; then if [ -n "${kibanainstalled}" ] || [ -n "${kibana_remaining_files}" ]; then if [ -n "${overwrite}" ]; then + uninstall_module_name="kibana" rollBack else logger -e "Kibana is already installed in this node or some of its files haven't been erased. Use option -o|--overwrite to overwrite all components." @@ -133,11 +136,19 @@ function checkArguments() { # -------------- Cluster start ---------------------------------- - if [[ -n "${start_elastic_cluster}" && ( -n "${AIO}" || -n "${elasticsearch}" || -n "${kibana}" || -n "${wazuh}" || -n "${overwrite}" || -n "${configurations}" || -n "${tar_conf}" || -n "${uninstall}") ]]; then - logger -e "The argument -s|--start-cluster can't be used with -a, -k, -e or -w arguments." + if [[ -n "${start_elastic_cluster}" && ( -z "${elasticsearchinstalled}" || -z "${elastic_remaining_files}") ]]; then + logger -e "The argument -s|--start-cluster need elasticsearch installed. Run the script with the parameter first --elasticsearch ." exit 1 + else + if [[ -n "${start_elastic_cluster}" && ( -n "${AIO}" || -n "${elasticsearch}" || -n "${kibana}" || -n "${wazuh}" || -n "${overwrite}" || -n "${configurations}" || -n "${tar_conf}" || -n "${uninstall}") ]]; then + logger -e "The argument -s|--start-cluster can't be used with -a, -k, -e or -w arguments." + exit 1 + fi fi + + + # -------------- Global ----------------------------------------- if [ -z "${AIO}" ] && [ -z "${elasticsearch}" ] && [ -z "${kibana}" ] && [ -z "${wazuh}" ] && [ -z "${start_elastic_cluster}" ] && [ -z "${configurations}" ] && [ -z "${uninstall}"]; then @@ -147,6 +158,29 @@ function checkArguments() { } +function checkTools() { + + # -------------- Check tools required to run the script (awk, sed, etc.) ----------------------------------------- + + toolList=( "uname" + "free" + "tar" + "awk" + "free" + "sed") + + eval "rm -rf ${elements_to_remove[*]}" + + for command in "${toolList[@]}" + do + if [ -z "$(command -v $command)" ]; then + logger_cert -e "$command not installed. This command is necessary for the correct operation of this script." + exit 1 + fi + done + +} + function checkHealth() { checkSpecs From 45302959cee3f03a0ed16c040aa903189ef36ba9 Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Sat, 29 Jan 2022 16:07:16 -0300 Subject: [PATCH 2/9] Add function checkTools and fix initial stage flow --- unattended_installer/wazuh_install.sh | 33 ++++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/unattended_installer/wazuh_install.sh b/unattended_installer/wazuh_install.sh index 0b758a268b..0937d11b39 100755 --- a/unattended_installer/wazuh_install.sh +++ b/unattended_installer/wazuh_install.sh @@ -338,19 +338,17 @@ function main() { logger "Starting Wazuh unattended installer. Wazuh version: ${wazuh_version}. Wazuh installer version: ${wazuh_install_vesion}" -# -------------- Uninstall case ------------------------------------ +# -------------- Prerequisites and Wazuh repo ---------------------- - checkIfInstalled - if [ -n "${uninstall}" ]; then - logger "------------------------------------ Uninstall ------------------------------------" - logger "Removing all installed components." - rollBack - logger "All components removed." - exit 0 + if [ -n "${AIO}" ] || [ -n "${elasticsearch}" ] || [ -n "${kibana}" ] || [ -n "${wazuh}" ]; then + logger "---------------------------------- Dependencies -----------------------------------" + installPrerequisites + addWazuhrepo fi # -------------- Preliminary checks -------------------------------- + checkTools if [ -z "${configurations}" ] && [ -z "${AIO}" ]; then checkPreviousCertificates fi @@ -366,6 +364,17 @@ function main() { fi checkArguments +# -------------- Uninstall case ------------------------------------ + + checkIfInstalled + if [ -n "${uninstall}" ]; then + logger "------------------------------------ Uninstall ------------------------------------" + logger "Removing all installed components." + rollBack + logger "All components removed." + exit 0 + fi + # -------------- Configuration creation case ----------------------- # Creation certificate case: Only AIO and -c option can create certificates. @@ -398,14 +407,6 @@ function main() { checkNames fi -# -------------- Prerequisites and Wazuh repo ---------------------- - - if [ -n "${AIO}" ] || [ -n "${elasticsearch}" ] || [ -n "${kibana}" ] || [ -n "${wazuh}" ]; then - logger "---------------------------------- Dependencies -----------------------------------" - installPrerequisites - addWazuhrepo - fi - # -------------- Elasticsearch or Start Elasticsearch cluster case--- if [ -n "${elasticsearch}" ] || [ -n "${start_elastic_cluster}" ] ; then From dcdd5e3b99d32f9e431147eb4ed1a331598b9cd8 Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Mon, 31 Jan 2022 12:18:45 -0300 Subject: [PATCH 3/9] Remove unnecessary eval. --- unattended_installer/install_functions/opendistro/checks.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/unattended_installer/install_functions/opendistro/checks.sh b/unattended_installer/install_functions/opendistro/checks.sh index 4180ccb10d..b6a2934560 100644 --- a/unattended_installer/install_functions/opendistro/checks.sh +++ b/unattended_installer/install_functions/opendistro/checks.sh @@ -169,8 +169,6 @@ function checkTools() { "free" "sed") - eval "rm -rf ${elements_to_remove[*]}" - for command in "${toolList[@]}" do if [ -z "$(command -v $command)" ]; then From c79f38ea7d1480821fac06affedb5e2bf51f5350 Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Wed, 2 Feb 2022 01:38:16 -0300 Subject: [PATCH 4/9] fix function checkTools --- .../install_functions/opendistro/checks.sh | 29 ++++++++++++------- unattended_installer/wazuh_install.sh | 4 ++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/unattended_installer/install_functions/opendistro/checks.sh b/unattended_installer/install_functions/opendistro/checks.sh index 4180ccb10d..fdd37cc9bc 100644 --- a/unattended_installer/install_functions/opendistro/checks.sh +++ b/unattended_installer/install_functions/opendistro/checks.sh @@ -162,22 +162,31 @@ function checkTools() { # -------------- Check tools required to run the script (awk, sed, etc.) ----------------------------------------- - toolList=( "uname" - "free" - "tar" - "awk" - "free" - "sed") - - eval "rm -rf ${elements_to_remove[*]}" + toolList=( "awk" "cat" "chown" "cp" "curl" "echo" "export" + "free" "grep" "kill" "mkdir" "mv" "rm" "sed" + "sudo" "tar" "touch" "uname") + missingtoolsList=() for command in "${toolList[@]}" do if [ -z "$(command -v $command)" ]; then - logger_cert -e "$command not installed. This command is necessary for the correct operation of this script." - exit 1 + missingtoolsList+=($command) + missingtoolsStatus="true" fi done + + if [ -n "${missingtoolsStatus}" ]; then + + logger "---------------------------------- Missing tool -----------------------------------" + logger "Missing tool report:" + for tool in "${missingtoolsList[@]}"; do + if [ -n "$($command -L -n | grep DROP | grep $port)" ]; then + logger " ...$missingtoolsList is not installed. " + done + logger " ...All this command's are necessary for the correct use of this tool." + exit 1 + + fi } diff --git a/unattended_installer/wazuh_install.sh b/unattended_installer/wazuh_install.sh index 0937d11b39..0eaa1bb16e 100755 --- a/unattended_installer/wazuh_install.sh +++ b/unattended_installer/wazuh_install.sh @@ -336,6 +336,8 @@ function main() { importFunction "wazuh-cert-tool.sh" importFunction "wazuh-passwords-tool.sh" + checkTools + logger "Starting Wazuh unattended installer. Wazuh version: ${wazuh_version}. Wazuh installer version: ${wazuh_install_vesion}" # -------------- Prerequisites and Wazuh repo ---------------------- @@ -347,8 +349,8 @@ function main() { fi # -------------- Preliminary checks -------------------------------- + - checkTools if [ -z "${configurations}" ] && [ -z "${AIO}" ]; then checkPreviousCertificates fi From 78c6d9a95fd772e75d08c9088f87adaa14920297 Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Wed, 2 Feb 2022 01:58:52 -0300 Subject: [PATCH 5/9] fix checkSpecs (coresFile) --- .../install_functions/opendistro/checks.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/unattended_installer/install_functions/opendistro/checks.sh b/unattended_installer/install_functions/opendistro/checks.sh index fdd37cc9bc..885f884745 100644 --- a/unattended_installer/install_functions/opendistro/checks.sh +++ b/unattended_installer/install_functions/opendistro/checks.sh @@ -351,7 +351,12 @@ function checkPreviousCertificates() { function checkSpecs() { - cores=$(cat /proc/cpuinfo | grep -c processor ) + coresFile=/etc/resolv.conf + if [ -f "$coresFile" ]; then + cores=$(cat "$coresFile" | grep -c processor ) + else + logger -e "The $coresFile does not exist." + fi ram_gb=$(free -m | awk '/^Mem:/{print $2}') } From 9579597109328b3dda7925d9726a2d6d2d80d7a9 Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Fri, 4 Feb 2022 16:19:15 -0300 Subject: [PATCH 6/9] Fix function checkArguments (Cluster start), function checkHealth --- .../install_functions/opendistro/checks.sh | 117 +++++++++--------- unattended_installer/wazuh_install.sh | 28 ++--- 2 files changed, 75 insertions(+), 70 deletions(-) diff --git a/unattended_installer/install_functions/opendistro/checks.sh b/unattended_installer/install_functions/opendistro/checks.sh index 885f884745..17c2c0796b 100644 --- a/unattended_installer/install_functions/opendistro/checks.sh +++ b/unattended_installer/install_functions/opendistro/checks.sh @@ -1,4 +1,4 @@ -# Wazuh installer - checks.sh functions. +# Wazuh installer - checks.sh functions. # Copyright (C) 2015, Wazuh Inc. # # This program is a free software; you can redistribute it @@ -32,7 +32,7 @@ function checkArguments() { # -------------- Overwrite -------------------------------------- - if [ -n "${overwrite}" ] && [ -z "${AIO}" ] && [ -z "${elasticsearch}" ] && [ -z "${kibana}" ] && [ -z "${wazuh}" ]; then + if [ -n "${overwrite}" ] && [ -z "${AIO}" ] && [ -z "${elasticsearch}" ] && [ -z "${kibana}" ] && [ -z "${wazuh}" ]; then logger -e "The argument -o|--overwrite must be used with -a, -k, -e or -w. If you want to uninstall all the components use -u|--uninstall" exit 1 fi @@ -91,7 +91,7 @@ function checkArguments() { if [ -n "${overwrite}" ]; then uninstall_module_name="elasticsearch" rollBack - else + else logger -e "Elasticsearch is already installed in this node or some of its files haven't been erased. Use option -o|--overwrite to overwrite all components." exit 1 fi @@ -105,7 +105,7 @@ function checkArguments() { if [ -n "${overwrite}" ]; then uninstall_module_name="kibana" rollBack - else + else logger -e "Kibana is already installed in this node or some of its files haven't been erased. Use option -o|--overwrite to overwrite all components." exit 1 fi @@ -118,7 +118,7 @@ function checkArguments() { if [ -n "${wazuhinstalled}" ] || [ -n "${wazuh_remaining_files}" ]; then if [ -n "${overwrite}" ]; then rollBack - else + else logger -e "Wazuh is already installed in this node or some of its files haven't been erased. Use option -o|--overwrite to overwrite all components." exit 1 fi @@ -139,22 +139,18 @@ function checkArguments() { if [[ -n "${start_elastic_cluster}" && ( -z "${elasticsearchinstalled}" || -z "${elastic_remaining_files}") ]]; then logger -e "The argument -s|--start-cluster need elasticsearch installed. Run the script with the parameter first --elasticsearch ." exit 1 - else - if [[ -n "${start_elastic_cluster}" && ( -n "${AIO}" || -n "${elasticsearch}" || -n "${kibana}" || -n "${wazuh}" || -n "${overwrite}" || -n "${configurations}" || -n "${tar_conf}" || -n "${uninstall}") ]]; then - logger -e "The argument -s|--start-cluster can't be used with -a, -k, -e or -w arguments." - exit 1 - fi fi - - - + if [[ -n "${start_elastic_cluster}" && ( -n "${AIO}" || -n "${elasticsearch}" || -n "${kibana}" || -n "${wazuh}" || -n "${overwrite}" || -n "${configurations}" || -n "${tar_conf}" || -n "${uninstall}") ]]; then + logger -e "The argument -s|--start-cluster can't be used with -a, -k, -e or -w arguments." + exit 1 + fi # -------------- Global ----------------------------------------- - if [ -z "${AIO}" ] && [ -z "${elasticsearch}" ] && [ -z "${kibana}" ] && [ -z "${wazuh}" ] && [ -z "${start_elastic_cluster}" ] && [ -z "${configurations}" ] && [ -z "${uninstall}"]; then + if [ -z "${AIO}" ] && [ -z "${elasticsearch}" ] && [ -z "${kibana}" ] && [ -z "${wazuh}" ] && [ -z "${start_elastic_cluster}" ] && [ -z "${configurations}" ] && [ -z "${uninstall}" ]; then logger -e "At least one of these arguments is necessary -a|--all-in-one, -c|--create-configurations, -e|--elasticsearch , -k|--kibana , -s|--start-cluster, -w|--wazuh-server , -u|--uninstall" exit 1 - fi + fi } @@ -169,63 +165,72 @@ function checkTools() { missingtoolsList=() for command in "${toolList[@]}" do - if [ -z "$(command -v $command)" ]; then - missingtoolsList+=($command) - missingtoolsStatus="true" + if [ -z "$(command -v ${command})" ]; then + missingtoolsList+="${command}, " fi done - if [ -n "${missingtoolsStatus}" ]; then + if [ -n "${missingtoolsList}" ]; then logger "---------------------------------- Missing tool -----------------------------------" - logger "Missing tool report:" - for tool in "${missingtoolsList[@]}"; do - if [ -n "$($command -L -n | grep DROP | grep $port)" ]; then - logger " ...$missingtoolsList is not installed. " - done - logger " ...All this command's are necessary for the correct use of this tool." + logger "Missing tool report: ${missingtoolsList} are not installed. All this command's are necessary for the correct use of this tool." exit 1 fi - + } function checkHealth() { checkSpecs - if [ -n "${elasticsearch}" ]; then - if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then - logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements." - exit 1 - else - logger "Check recommended minimum hardware requirements for Elasticsearch done." - fi + if [ -z "${cores}" ]; then + logger -w "The script needs to parse the file '${coresFile}' to check the minimum required hardware of CPU cores." + logger -w "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check." + exit 1 + fi + if [ -z "${ram_gb}" ]; then + logger - w "The command 'free' is required to check the minimum required hardware of RAM." + logger -w "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check." + exit 1 fi - if [ -n "${kibana}" ]; then - if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then - logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements." - exit 1 - else - logger "Check recommended minimum hardware requirements for Kibana done." + if [ -n "${cores}" ] && [ -n "${ram_gb}" ]; then + + if [ -n "${elasticsearch}" ]; then + if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then + logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements." + exit 1 + else + logger "Check recommended minimum hardware requirements for Elasticsearch done." + fi fi - fi - if [ -n "${wazuh}" ]; then - if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 1700 ]; then - logger -e "Your system does not meet the recommended minimum hardware requirements of 2Gb of RAM and 2 CPU cores . If you want to proceed with the installation use the -i option to ignore these requirements." - exit 1 - else - logger "Check recommended minimum hardware requirements for Wazuh Manager done." + if [ -n "${kibana}" ]; then + if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then + logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements." + exit 1 + else + logger "Check recommended minimum hardware requirements for Kibana done." + fi fi - fi - if [ -n "${aio}" ]; then - if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then - logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements." - exit 1 - else - logger "Check recommended minimum hardware requirements for AIO done." + if [ -n "${wazuh}" ]; then + if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 1700 ]; then + logger -e "Your system does not meet the recommended minimum hardware requirements of 2Gb of RAM and 2 CPU cores . If you want to proceed with the installation use the -i option to ignore these requirements." + exit 1 + else + logger "Check recommended minimum hardware requirements for Wazuh Manager done." + fi + fi + + if [ -n "${aio}" ]; then + echo "${cores}" + if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then + logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements." + exit 1 + else + logger "Check recommended minimum hardware requirements for AIO done." + fi fi fi @@ -283,7 +288,7 @@ function checkIfInstalled() { } -# This function ensures different names in the config.yml file. +# This function ensures different names in the config.yml file. function checkNames() { if [ -n "${einame}" ] && [ -n "${kiname}" ] && [ "${einame}" == "${kiname}" ]; then @@ -304,7 +309,7 @@ function checkNames() { if [ -n "${winame}" ] && [ -z "$(echo "${wazuh_servers_node_names[@]}" | grep -w "${winame}")" ]; then logger -e "The Wazuh server node name ${winame} does not appear on the configuration file." exit 1 - fi + fi if [ -n "${einame}" ] && [ -z "$(echo "${elasticsearch_node_names[@]}" | grep -w "${einame}")" ]; then logger -e "The Elasticsearch node name ${einame} does not appear on the configuration file." @@ -351,7 +356,7 @@ function checkPreviousCertificates() { function checkSpecs() { - coresFile=/etc/resolv.conf + coresFile="/proc/cpuinfo" if [ -f "$coresFile" ]; then cores=$(cat "$coresFile" | grep -c processor ) else diff --git a/unattended_installer/wazuh_install.sh b/unattended_installer/wazuh_install.sh index 0eaa1bb16e..2fedf8790d 100755 --- a/unattended_installer/wazuh_install.sh +++ b/unattended_installer/wazuh_install.sh @@ -39,9 +39,9 @@ debug=">> ${logfile} 2>&1" trap cleanExit SIGINT function cleanExit() { - + rollback_conf="" - + if [ -n "$spin_pid" ]; then eval "kill -9 $spin_pid ${debug}" fi @@ -52,7 +52,7 @@ function cleanExit() { done if [[ "${rollback_conf}" =~ [N|n] ]]; then exit 1 - else + else rollBack exit 1 fi @@ -141,7 +141,7 @@ function importFunction() { if [ $has_main = 0 ]; then echo 'main $@' >> "${base_path}/${functions_path}/${1}" fi - else + else logger -e "Unable to find resource in path ${base_path}/${functions_path}/${1}." exit 1 fi @@ -190,7 +190,7 @@ function logger() { esac done fi - + if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then echo "${now} ${mtype} ${message}" | tee -a ${logfile} fi @@ -313,8 +313,8 @@ function main() { getHelp esac - # This assignment will be present during all testing stages. - # It must be removed when the unattended installer is published. + # This assignment will be present during all testing stages. + # It must be removed when the unattended installer is published. development=1 done @@ -349,7 +349,7 @@ function main() { fi # -------------- Preliminary checks -------------------------------- - + if [ -z "${configurations}" ] && [ -z "${AIO}" ]; then checkPreviousCertificates @@ -364,11 +364,11 @@ function main() { if [ -n "${AIO}" ] ; then rm -f "${tar_file}" fi + checkIfInstalled checkArguments # -------------- Uninstall case ------------------------------------ - checkIfInstalled if [ -n "${uninstall}" ]; then logger "------------------------------------ Uninstall ------------------------------------" logger "Removing all installed components." @@ -379,7 +379,7 @@ function main() { # -------------- Configuration creation case ----------------------- - # Creation certificate case: Only AIO and -c option can create certificates. + # Creation certificate case: Only AIO and -c option can create certificates. if [ -n "${configurations}" ] || [ -n "${AIO}" ]; then logger "------------------------------- Configuration files -------------------------------" if [ -n "${configurations}" ]; then @@ -391,7 +391,7 @@ function main() { fi gen_file="${base_path}/certs/password_file.yml" generatePasswordFile - # Using cat instead of simple cp because OpenSUSE unknown error. + # Using cat instead of simple cp because OpenSUSE unknown error. eval "cat '${config_file}' > '${base_path}/certs/config.yml'" eval "tar -zcf '${tar_file}' -C '${base_path}/certs/' . ${debug}" eval "rm -rf '${base_path}/certs' ${debug}" @@ -403,7 +403,7 @@ function main() { readConfig rm -f "${config_file}" fi - + # Distributed architecture: node names must be different if [[ -z "${AIO}" && ( -n "${elasticsearch}" || -n "${kibana}" || -n "${wazuh}" )]]; then checkNames @@ -439,7 +439,7 @@ function main() { importFunction "kibana.sh" - installKibana + installKibana configureKibana changePasswords startService "kibana" @@ -457,7 +457,7 @@ function main() { installWazuh if [ -n "${wazuh_servers_node_types[*]}" ]; then - configureWazuhCluster + configureWazuhCluster fi startService "wazuh-manager" installFilebeat From 2decde47b36499909e69927da37fc43fad5058de Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Tue, 8 Feb 2022 00:55:32 -0300 Subject: [PATCH 7/9] Fix checkHealth (logger), fix checkSpecs (free use for check ram), checkTools (order a-z) --- .../install_functions/opendistro/checks.sh | 78 +++++++++++-------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/unattended_installer/install_functions/opendistro/checks.sh b/unattended_installer/install_functions/opendistro/checks.sh index 4dfbf77d05..fc386f5a1d 100644 --- a/unattended_installer/install_functions/opendistro/checks.sh +++ b/unattended_installer/install_functions/opendistro/checks.sh @@ -161,43 +161,17 @@ function checkArguments() { } -function checkTools() { - - # -------------- Check tools required to run the script (awk, sed, etc.) ----------------------------------------- - - toolList=( "awk" "cat" "chown" "cp" "curl" "echo" "export" - "free" "grep" "kill" "mkdir" "mv" "rm" "sed" - "sudo" "tar" "touch" "uname") - - missingtoolsList=() - for command in "${toolList[@]}" - do - if [ -z "$(command -v ${command})" ]; then - missingtoolsList+="${command}, " - fi - done - - if [ -n "${missingtoolsList}" ]; then - - logger "---------------------------------- Missing tool -----------------------------------" - logger "Missing tool report: ${missingtoolsList} are not installed. All this command's are necessary for the correct use of this tool." - exit 1 - - fi - -} - function checkHealth() { checkSpecs if [ -z "${cores}" ]; then - logger -w "The script needs to parse the file '${coresFile}' to check the minimum required hardware of CPU cores." - logger -w "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check." + logger -e "The script needs to parse the file '${coresFile}' to check the minimum required hardware of CPU cores." + logger "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check." exit 1 fi if [ -z "${ram_gb}" ]; then - logger - w "The command 'free' is required to check the minimum required hardware of RAM." - logger -w "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check." + logger -e "The command 'free' is required to check the minimum required hardware of RAM." + logger "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check." exit 1 fi @@ -369,7 +343,23 @@ function checkSpecs() { else logger -e "The $coresFile does not exist." fi - ram_gb=$(free -m | awk '/^Mem:/{print $2}') + + if [ -n "$(command -v free)" ]; then + ram_gb=$(free -m | awk '/^Mem:/{print $2}') + else + memFile="/proc/meminfo" + if [ -f "$memFile" ]; then + MEMinKB=$(cat "$memFile" | grep MemTotal | awk '/^MemTotal:/{print $2}') + ram_gb=$(( $MEMinKB / 1024 )) + else + logger -e "The $coresFile does not exist." + fi + fi + + + + + } @@ -390,3 +380,29 @@ function checkSystem() { fi } + +function checkTools() { + + # -------------- Check tools required to run the script (awk, sed, etc.) ----------------------------------------- + + toolList=( "awk" "cat" "chown" "cp" "curl" "echo" "export" + "free" "grep" "kill" "mkdir" "mv" "rm" "sed" + "sudo" "tar" "touch" "uname") + + missingtoolsList=() + for command in "${toolList[@]}" + do + if [ -z "$(command -v ${command})" ]; then + missingtoolsList+="${command}, " + fi + done + + if [ -n "${missingtoolsList}" ]; then + + logger "---------------------------------- Missing tools -----------------------------------" + logger "The following command or commands are not present in the system: ${missingtoolsList} and must it is / they are necessary for the correct use of this tool." + exit 1 + + fi + +} \ No newline at end of file From 75ae8a8763249fa395bd8923c9da4546c19b7efe Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Tue, 8 Feb 2022 00:56:09 -0300 Subject: [PATCH 8/9] Restore call to: Prerequisites and Wazuh repo --- unattended_installer/wazuh_install.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unattended_installer/wazuh_install.sh b/unattended_installer/wazuh_install.sh index 967e2ac5e9..3deee0846d 100755 --- a/unattended_installer/wazuh_install.sh +++ b/unattended_installer/wazuh_install.sh @@ -369,6 +369,14 @@ function main() { exit 0 fi +# -------------- Prerequisites and Wazuh repo ---------------------- + + if [ -n "${AIO}" ] || [ -n "${elasticsearch}" ] || [ -n "${kibana}" ] || [ -n "${wazuh}" ]; then + logger "---------------------------------- Dependencies -----------------------------------" + installPrerequisites + addWazuhrepo + fi + # -------------- Preliminary steps -------------------------------- if [ -z "${configurations}" ] && [ -z "${AIO}" ]; then From 276182192b1545711fe5dfe2ab424bf0cf8bf8e6 Mon Sep 17 00:00:00 2001 From: Nicolas Lastra Date: Wed, 9 Feb 2022 02:35:35 -0300 Subject: [PATCH 9/9] Fix logger --- unattended_installer/install_functions/opendistro/checks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unattended_installer/install_functions/opendistro/checks.sh b/unattended_installer/install_functions/opendistro/checks.sh index cb14c5c28c..dfc83e1db4 100644 --- a/unattended_installer/install_functions/opendistro/checks.sh +++ b/unattended_installer/install_functions/opendistro/checks.sh @@ -355,7 +355,7 @@ function checkSpecs() { MEMinKB=$(cat "$memFile" | grep MemTotal | awk '/^MemTotal:/{print $2}') ram_gb=$(( $MEMinKB / 1024 )) else - logger -e "The $coresFile does not exist." + logger -e "The $memFile does not exist." fi fi @@ -403,7 +403,7 @@ function checkTools() { if [ -n "${missingtoolsList}" ]; then logger "---------------------------------- Missing tools -----------------------------------" - logger "The following command or commands are not present in the system: ${missingtoolsList} and must it is / they are necessary for the correct use of this tool." + logger "The following command or commands are not present in the system: ${missingtoolsList}. Those tools are necessary for the correct use of this tool." exit 1 fi