diff --git a/unattended_installer/install_functions/opendistro/checks.sh b/unattended_installer/install_functions/opendistro/checks.sh index 95ba765c03..dfc83e1db4 100644 --- a/unattended_installer/install_functions/opendistro/checks.sh +++ b/unattended_installer/install_functions/opendistro/checks.sh @@ -31,7 +31,6 @@ function checkArguments() { fi # -------------- Overwrite -------------------------------------- - 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 @@ -64,6 +63,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." @@ -78,6 +78,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." @@ -91,6 +92,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." @@ -123,6 +125,10 @@ function checkArguments() { # -------------- Cluster start ---------------------------------- + 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 + 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 @@ -140,39 +146,54 @@ function checkArguments() { 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 -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 -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 - 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 @@ -319,8 +340,29 @@ function checkPreviousCertificates() { function checkSpecs() { - cores=$(cat /proc/cpuinfo | grep -c processor ) - ram_gb=$(free -m | awk '/^Mem:/{print $2}') + coresFile="/proc/cpuinfo" + if [ -f "$coresFile" ]; then + cores=$(cat "$coresFile" | grep -c processor ) + else + logger -e "The $coresFile does not exist." + fi + + 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 $memFile does not exist." + fi + fi + + + + + } @@ -341,3 +383,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}. Those tools are necessary for the correct use of this tool." + exit 1 + + fi + +} \ No newline at end of file diff --git a/unattended_installer/wazuh_install.sh b/unattended_installer/wazuh_install.sh index 5ccf4c5a0c..90dc956381 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 + if [ -z "${uninstall}" ]; then logger "Starting Wazuh unattended installer. Wazuh version: ${wazuh_version}. Wazuh installer version: ${wazuh_install_vesion}" fi @@ -360,6 +362,7 @@ function main() { # -------------- Uninstall case ------------------------------------ if [ -n "${uninstall}" ]; then + importFunction "wazuh.sh" importFunction "filebeat.sh" importFunction "elasticsearch.sh" @@ -369,6 +372,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 @@ -407,14 +418,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