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

Fix rollBack and uninstall improvement #1211

Open
wants to merge 34 commits into
base: unify-unattended
Choose a base branch
from

Conversation

myu1d157h0u54nd
Copy link
Contributor

Related issue
Closes #1210

Description

The script needs to be able to run custom uninstallations:

  • -u all
    • To uninstall all.
  • -u wazuh
    • To uninstall just wazuh.
  • -u elasticsearch
    • To uninstall only elasticsearch.
  • -u kibana
    • To uninstall just Kibana.

verdx
verdx previously approved these changes Jan 31, 2022
Copy link
Contributor

@verdx verdx left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

The function Rollback must call other functions with names uninstallWazuh, uninstallElasticsearch, and uninstallKibana. Those functions must be placed in their respective .sh file, not in common.sh. In common.sh will be only a functions rollBack with this appearance:

function rollBack() {
	component=$1
        if $1 != "all"; then 
        	eval "uninstall$component"
        else
                eval "uninstallWazuh" 
                eval "uninstallElasticsearch"
                eval "uninstallKibana"  
}

Delegating the uninstall component responsibility to their corresponding module (wazuh.sh, elasticsearch.sh, etc).

Please review the other comments

@@ -111,7 +111,7 @@ function getHelp() {
echo -e " -t, --tar <path-to-certs-tar>"
echo -e " Path to tar containing certificate files. By default: ${base_path}/configurations.tar"
echo -e ""
echo -e " -u, --uninstall"
echo -e " -u, --uninstall <app-module-name>"
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
echo -e " -u, --uninstall <app-module-name>"
echo -e " -u, --uninstall <component-name>"

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.

Done

unattended_installer/wazuh_install.sh Outdated Show resolved Hide resolved
unattended_installer/wazuh_install.sh Outdated Show resolved Hide resolved
@myu1d157h0u54nd
Copy link
Contributor Author

The function Rollback must call other functions with names uninstallWazuh, uninstallElasticsearch, and uninstallKibana. Those functions must be placed in their respective .sh file, not in common.sh. In common.sh will be only a functions rollBack with this appearance:

function rollBack() {
	component=$1
        if $1 != "all"; then 
        	eval "uninstall$component"
        else
                eval "uninstallWazuh" 
                eval "uninstallElasticsearch"
                eval "uninstallKibana"  
}

Delegating the uninstall component responsibility to their corresponding module (wazuh.sh, elasticsearch.sh, etc).

Please review the other comments

Done!

Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

Please consider the uninstall_component_name and elasticsearchinstalled, wazuhinstaller, etc unification.

@myu1d157h0u54nd
Copy link
Contributor Author

Improvement for parameter check in the case: --uninstall

wazuh_install.sh --local --development --ignore-health-check --disable-spinner -u all

03/02/2022 06:44:22 INFO: Starting Wazuh unattended installer. Wazuh version: 4.3.0. Wazuh installer version: 0.1
03/02/2022 06:44:22 WARNING: Health-check ignored.
03/02/2022 06:44:22 INFO: Wazuh manager components were not found on the system so it was not uninstalled.
03/02/2022 06:44:22 INFO: Filebeat components were not found on the system so it was not uninstalled.
03/02/2022 06:44:22 INFO: Elasticsearch components were not found on the system so it was not uninstalled.
03/02/2022 06:44:22 INFO: Kibana components were not found on the system so it was not uninstalled.
03/02/2022 06:44:23 INFO: ------------------------------------ Uninstall ------------------------------------
03/02/2022 06:44:23 INFO: Removing components and cleaning the installation.
03/02/2022 06:44:23 INFO: All packages and components will be uninstalled.
03/02/2022 06:44:23 INFO: Wazuh and Filebeat will be uninstalled.
03/02/2022 06:44:23 INFO: Elasticsearch will be uninstalled.
03/02/2022 06:44:23 INFO: Kibana will be uninstalled.
03/02/2022 06:44:23 INFO: Repositories were removed.
03/02/2022 06:44:23 INFO: All components removed.

wazuh_install.sh --local --development --ignore-health-check --disable-spinner -u alla


03/02/2022 06:46:04 INFO: Starting Wazuh unattended installer. Wazuh version: 4.3.0. Wazuh installer version: 0.1
03/02/2022 06:46:04 WARNING: Health-check ignored.
03/02/2022 06:46:04 ERROR: The argument -u|--uninstall only accepts the following parameters: all, manager, elasticsearch or kibana.

@myu1d157h0u54nd
Copy link
Contributor Author

myu1d157h0u54nd commented Feb 3, 2022

wazuh_install.sh --local --development --ignore-health-check --disable-spinner -u all

03/02/2022 08:41:17 INFO: Starting Wazuh unattended installer. Wazuh version: 4.3.0. Wazuh installer version: 0.1
03/02/2022 08:41:17 WARNING: Health-check ignored.
03/02/2022 08:41:19 INFO: ------------------------------------ Uninstall ------------------------------------
03/02/2022 08:41:19 INFO: Removing components and cleaning the installation.
03/02/2022 08:41:19 INFO: All packages and components will be uninstalled.
03/02/2022 08:41:19 INFO: Wazuh and Filebeat will be uninstalled.
03/02/2022 08:41:19 WARNING: Removing Wazuh packages.
03/02/2022 08:41:25 WARNING: Removing Wazuh files.
03/02/2022 08:41:25 WARNING: Removing Filebeat packages.
03/02/2022 08:41:27 WARNING: Removing Filebeat files.
03/02/2022 08:41:27 INFO: Elasticsearch will be uninstalled.
03/02/2022 08:41:27 WARNING: Removing Elasticsearch packages.
03/02/2022 08:41:32 WARNING: Removing Elasticsearch files.
03/02/2022 08:41:32 INFO: Kibana will be uninstalled.
03/02/2022 08:41:32 WARNING: Removing Kibana packages.
03/02/2022 08:41:32 WARNING: Removing Kibana files.
03/02/2022 08:41:32 INFO: Repositories were removed.
03/02/2022 08:41:32 INFO: All components removed.

@myu1d157h0u54nd
Copy link
Contributor Author

Please consider the uninstall_component_name and elasticsearchinstalled, wazuhinstaller, etc unification.

Done!

@myu1d157h0u54nd
Copy link
Contributor Author

Let's see, the first and LEAST important thing that comes to my eyes is the there. We always talk about it, attention to detail. At least it's formatted.
Then, let's see, I have an INFO message that the unattended begins.
Then 4 messages that none of the 4 components were found.
Then Uninstall section. What for what? They have not been found.
Then it says Removing compobnent and cleaning the installation.
Then which packages and components will be uninstalled. But... if they didn't meet, he said at the beginning.
After all the components were removed...

I'm working on this!

@myu1d157h0u54nd
Copy link
Contributor Author

Example of complete uninstall (all) in a scenario where nothing is installed.

bash unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner -u all

03/02/2022 21:07:51 INFO: ------------------------------------ Uninstall ------------------------------------
03/02/2022 21:07:51 INFO: Analyzing components to uninstall and clean.
03/02/2022 21:07:51 INFO: Wazuh manager components were not found on the system so it was not uninstalled.
03/02/2022 21:07:51 INFO: Elasticsearch components were not found on the system so it was not uninstalled.
03/02/2022 21:07:51 INFO: Kibana components were not found on the system so it was not uninstalled.
03/02/2022 21:07:53 INFO: The uninstall process is complete.

@myu1d157h0u54nd
Copy link
Contributor Author

myu1d157h0u54nd commented Feb 7, 2022

Example case where the host has all packages installed (AIO). And only one package (kibana) is uninstalled.
In this case, the deletion of the repository file is not performed.

bash unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner -u kibana

03/02/2022 21:24:00 INFO: ------------------------------------ Uninstall ------------------------------------
03/02/2022 21:24:00 INFO: Analyzing components to uninstall and clean.
03/02/2022 21:24:00 INFO: Kibana will be uninstalled.
03/02/2022 21:24:00 WARNING: Removing Kibana packages.
03/02/2022 21:24:05 WARNING: Removing Kibana files.
03/02/2022 21:24:06 WARNING: Some Wazuh components are still installed on this host.
03/02/2022 21:24:06 INFO: The uninstall process is complete.

Case with the example of removing only one component (kibana). When this component is no longer installed.

bash unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner -u kibana

03/02/2022 22:12:13 INFO: ------------------------------------ Uninstall ------------------------------------
03/02/2022 22:12:13 INFO: Analyzing components to uninstall and clean.
03/02/2022 22:12:13 INFO: Kibana components were not found on the system so it was not uninstalled.
03/02/2022 22:12:14 WARNING: Some Wazuh components are still installed on this host.
03/02/2022 22:12:14 INFO: The uninstall process is complete.

@myu1d157h0u54nd
Copy link
Contributor Author

myu1d157h0u54nd commented Feb 8, 2022

Example of uninstallation of the only package in the system (manager).

sudo bash /tmp/unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner --uninstall manager

04/02/2022 07:08:55 INFO: ------------------------------------ Uninstall ------------------------------------
04/02/2022 07:08:55 INFO: Analyzing components to uninstall and clean.
04/02/2022 07:08:55 INFO: Wazuh and Filebeat will be uninstalled.
04/02/2022 07:08:55 WARNING: Removing Wazuh packages.
04/02/2022 07:09:00 WARNING: Removing Filebeat packages.
04/02/2022 07:09:01 WARNING: Removing Wazuh files.
04/02/2022 07:09:01 WARNING: Removing Filebeat files.
04/02/2022 07:09:02 INFO: Repositories were removed.
04/02/2022 07:09:02 INFO: The uninstall process is complete.

Example of uninstallation of the only package in the system (elasticsearch).

sudo bash /tmp/unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner --uninstall elasticsearch

04/02/2022 07:18:39 INFO: ------------------------------------ Uninstall ------------------------------------
04/02/2022 07:18:39 INFO: Analyzing components to uninstall and clean.
04/02/2022 07:18:39 INFO: Elasticsearch will be uninstalled.
04/02/2022 07:18:39 WARNING: Removing Elasticsearch packages.
04/02/2022 07:18:41 WARNING: Removing Elasticsearch files.
04/02/2022 07:18:43 INFO: Repositories were removed.
04/02/2022 07:18:43 INFO: The uninstall process is complete.

Example of uninstallation of the only package in the system (kibana).

sudo bash /tmp/unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner --uninstall kibana

04/02/2022 07:34:03 INFO: ------------------------------------ Uninstall ------------------------------------
04/02/2022 07:34:03 INFO: Analyzing components to uninstall and clean.
04/02/2022 07:34:03 INFO: Kibana will be uninstalled.
04/02/2022 07:34:03 WARNING: Removing Kibana files.
04/02/2022 07:34:05 INFO: Repositories were removed.
04/02/2022 07:34:05 INFO: The uninstall process is complete.

Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

04/02/2022 07:08:55 INFO: ------------------------------------ Uninstall ------------------------------------
04/02/2022 07:08:55 INFO: Analyzing components to uninstall and clean.
04/02/2022 07:08:55 INFO: Wazuh and Filebeat will be uninstalled.
04/02/2022 07:08:55 WARNING: Removing Wazuh packages.
04/02/2022 07:09:00 WARNING: Removing Filebeat packages.
04/02/2022 07:09:01 WARNING: Removing Wazuh files.
04/02/2022 07:09:01 WARNING: Removing Filebeat files.
04/02/2022 07:09:02 INFO: Repositories were removed.
04/02/2022 07:09:02 INFO: The uninstall process is complete.

This output says: Wazuh and Filebeat will be uninstalled. Then, all components have a WARNING message for removal. Only Filebeat and Wazuh must appear.

The Elasticsearch and Kibana examples are good.
Please review the requested changes.

elif [ "${sys_type}" == "apt-get" ]; then
eval "apt remove --purge wazuh-manager -y ${debug}"
fi
# Uninstall case!
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the !?

Suggested change
# Uninstall case!
# Uninstall case

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
c3fc835

eval "zypper -n remove filebeat ${debug}"
elif [ "${sys_type}" == "apt-get" ]; then
eval "apt remove --purge filebeat -y ${debug}"
# rollBack case!
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the !?

Suggested change
# rollBack case!
# rollBack case

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 c3fc835

eval "rm -rf /usr/share/filebeat/ ${debug}"
eval "rm -rf /etc/filebeat/ ${debug}"
if [ -n "${wazuhinstalled}" ] || [ -n "${wazuh_remaining_files}" ] || [ -n "${filebeatinstalled}" ] || [ -n "${filebeat_remaining_files}" ] || [ -n "${elasticsearchinstalled}" ] || [ -n "${elastic_remaining_files}" ] || [ -n "${kibanainstalled}" ] || [ -n "${kibana_remaining_files}" ]; then
logger -w "Some Wazuh components are still installed on this host."
Copy link
Contributor

Choose a reason for hiding this comment

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

When could this casuistic happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the process of uninstalling a component is done. And there are others installed.

Consider if when uninstalling a component. And there is still another one installed that should:

  • be notified, hence the -w
  • And also, the repository configuration will not be deleted. This should be uninstalled only when it is verified that there are no components left installed.

@@ -169,6 +170,43 @@ function installElasticsearch() {

}

function uninstallelasticsearch() {
logger "Elasticsearch will be uninstalled."
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a blank line separator from the first function line to function definition

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 c3fc835

kibanainstalled="1"
logger "Kibana installation finished."
fi

}

function uninstallkibana() {
logger "Kibana will be uninstalled."
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

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 c3fc835


logger "Wazuh and Filebeat will be uninstalled."

# remove packages
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
# remove packages
# Remove packages

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 c3fc835

fi
fi

# remove files
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
# remove files
# Remove files

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 c3fc835


# remove packages
if [[ -n "${wazuhinstalled}" ]];then
logger -w "Removing Wazuh packages."
Copy link
Contributor

Choose a reason for hiding this comment

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

Why packages? It's only one.

Suggested change
logger -w "Removing Wazuh packages."
logger -w "Removing Wazuh manager."

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 c3fc835

fi

if [[ -n "${filebeatinstalled}" ]]; then
logger -w "Removing Filebeat packages."
Copy link
Contributor

Choose a reason for hiding this comment

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

Why packages?

Suggested change
logger -w "Removing Filebeat packages."
logger -w "Removing Filebeat."

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 c3fc835

@myu1d157h0u54nd
Copy link
Contributor Author

This output says: Wazuh and Filebeat will be uninstalled. Then, all components have a WARNING message for removal. Only Filebeat and Wazuh must appear.

The Elasticsearch and Kibana examples are good. Please review the requested changes.

Done d29d1ad

@myu1d157h0u54nd
Copy link
Contributor Author

Merge branch 'unify-unattended' into unify-unatteded-uninstall-chose-component

It is pending testing. This merge was really hard, I want to be able to do a full install test again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants