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
38 changes: 36 additions & 2 deletions unattended_installer/install_functions/opendistro/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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."
Expand All @@ -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."
Expand Down Expand Up @@ -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 <elasticsearch-node-name>."
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
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
fi




# -------------- Global -----------------------------------------

if [ -z "${AIO}" ] && [ -z "${elasticsearch}" ] && [ -z "${kibana}" ] && [ -z "${wazuh}" ] && [ -z "${start_elastic_cluster}" ] && [ -z "${configurations}" ] && [ -z "${uninstall}"]; then
Expand All @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Include echo, cat, grep, rm, touch, kill, cp, mv, export, mkdir, curl, chown, sudo, chmod, in the list. Then, don't exit in the first not found command. Instead of this, make a list of not-found dependencies and print the list, avoiding the re-run for every command.

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Installation simulation, modifying the list of tools by adding the false commands 'badbad' and 'notsobad'.

sudo bash /tmp/unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner --all-in-one

03/02/2022 16:41:02 INFO: ---------------------------------- Missing tool -----------------------------------
03/02/2022 16:41:02 INFO: Missing tool report: badbad, notsobad,  are not installed. All this command's are necessary for the correct use of this tool.


eval "rm -rf ${elements_to_remove[*]}"

for command in "${toolList[@]}"
do
if [ -z "$(command -v $command)" ]; then
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
logger_cert -e "$command not installed. This command is necessary for the correct operation of this script."
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
done

}

function checkHealth() {

checkSpecs
Expand Down
33 changes: 17 additions & 16 deletions unattended_installer/wazuh_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
if [ -z "${configurations}" ] && [ -z "${AIO}" ]; then
checkPreviousCertificates
fi
Expand All @@ -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.
Expand Down Expand Up @@ -398,14 +407,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