Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify unatteded uninstall check tools and start cluster #1221

Open
wants to merge 12 commits into
base: unify-unatteded-uninstall-chose-component
Choose a base branch
from
Open
128 changes: 98 additions & 30 deletions unattended_installer/install_functions/opendistro/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand All @@ -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."
Expand All @@ -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."
Expand Down Expand Up @@ -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 <elasticsearch-node-name>."
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
Expand All @@ -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

Expand Down Expand Up @@ -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."
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
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 $coresFile does not exist."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why $coresFile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 2761821

fi
fi






}

Expand All @@ -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} and must it is / they are necessary for the correct use of this tool."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 2761821

exit 1

fi

}
19 changes: 11 additions & 8 deletions unattended_installer/wazuh_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -360,6 +362,7 @@ function main() {
# -------------- Uninstall case ------------------------------------

if [ -n "${uninstall}" ]; then

importFunction "wazuh.sh"
importFunction "filebeat.sh"
importFunction "elasticsearch.sh"
Expand All @@ -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
Expand Down Expand Up @@ -407,14 +418,6 @@ function main() {
checkNames
fi

# -------------- Prerequisites and Wazuh repo ----------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Dependencies installation uneccesary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recovered, this was a mistake

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why is moved before the preliminary steps?
If there is an error with the node names, etc, I prefer to know it before starting installing dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I do not understand. Tell me if I understand correctly please.
Functions import. Line 332. Check the system tools.
Preliminary checks, Line 345. This step checks arguments and parameters.
Prerequisites and Wazuh repo, Line 375. This step installs dependencies
Preliminary steps, Line 383. It only validates checkPreviousCertificates.
I understand this would be correct.


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
Expand Down