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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fa9939f
Fix rollBack and uninstall improvement
myu1d157h0u54nd Jan 27, 2022
039d2df
Change app-module-name for component-name
myu1d157h0u54nd Feb 2, 2022
f6f3406
Merge branch 'unify-unattended' into unify-unatteded-uninstall-chose-…
myu1d157h0u54nd Feb 2, 2022
064cb16
Fix rollBack and uninstall
myu1d157h0u54nd Feb 2, 2022
6d224d3
Removed trims and help output rework
alberpilot Feb 2, 2022
a0c00c0
Style minor change
alberpilot Feb 2, 2022
5387d9b
Fix rollBack (rework)
myu1d157h0u54nd Feb 3, 2022
76e3e1b
Fix checkArguments.
myu1d157h0u54nd Feb 3, 2022
4c1261b
Fix function uninstallelasticsearch, uninstallkibana, uninstallmanager.
myu1d157h0u54nd Feb 3, 2022
5c15e06
Fix function rollBack.
myu1d157h0u54nd Feb 3, 2022
9e78493
Fix work flow in wazuh-install for uninstall case.
myu1d157h0u54nd Feb 3, 2022
98253de
Fix rollBack for overwrite case.
myu1d157h0u54nd Feb 3, 2022
a72f607
Fix function uninstallelasticsearch, uninstallkibana, uninstallmanager.
myu1d157h0u54nd Feb 3, 2022
51af2ab
Fix function uninstall*
myu1d157h0u54nd Feb 8, 2022
fb60732
Fix logger and call to rollBack from wazuh_install*
myu1d157h0u54nd Feb 8, 2022
5d1267f
Big rework in function rollBack (uninstall case, overwrite case and r…
myu1d157h0u54nd Feb 8, 2022
b819306
Improved array definition
alberpilot Feb 8, 2022
c3fc835
Minor change fix.
myu1d157h0u54nd Feb 8, 2022
6654ab1
Merge branch 'unify-unatteded-uninstall-chose-component' of github.co…
myu1d157h0u54nd Feb 8, 2022
d29d1ad
Fix logger for uninstallmanager case.
myu1d157h0u54nd Feb 8, 2022
641d6aa
Merge branch 'unify-unattended' into unify-unatteded-uninstall-chose-…
myu1d157h0u54nd Feb 9, 2022
7b5b465
Fix merge, change elasticsearch>wazuh-indexer, change kibana>wazuh-da…
myu1d157h0u54nd Feb 9, 2022
c777d90
Fix merge, call to functions.
myu1d157h0u54nd Feb 9, 2022
1338351
Fix checks_arguments
myu1d157h0u54nd Feb 10, 2022
4a0eebe
Fix common_rollBack
myu1d157h0u54nd Feb 10, 2022
5a57fb7
Fix call to common_rollBack, for installation failed
myu1d157h0u54nd Feb 10, 2022
ea3e3ad
Fix functions import, Uninstall and Overwrite
myu1d157h0u54nd Feb 10, 2022
ba07f87
Fix wazuh-dashboards to wazuh-dashboard
myu1d157h0u54nd Feb 10, 2022
999ffa3
Fix wazuh-dashboards renames
myu1d157h0u54nd Feb 10, 2022
17f67c7
Fix wazuh-dashboards to wazuh-dashboard in yml files
myu1d157h0u54nd Feb 10, 2022
5c362fe
Fix logger
myu1d157h0u54nd Feb 10, 2022
8d5ed5f
Changed dashboards for dashboard in unattended pytest
verdx Feb 11, 2022
524b366
Merge remote-tracking branch 'origin/unify-unattended' into unify-una…
verdx Feb 11, 2022
7af196b
Removed accidentally added file
alberpilot Feb 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 76 additions & 36 deletions unattended_installer/install_functions/opendistro/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,28 @@ function restoreWazuhrepo() {
}

function rollBack() {

if [ -z "${uninstall}" ]; then
if [ ! -z "${uninstall}" ] || [ ! -z "${uninstall_module_name}" ]; then
logger "Cleaning the installation."
fi

if [ "${uninstall_module_name}" == "wazuh" ]; then
logger "Cleaning the installation. Wazuh and Filebeat will be uninstalled."
rollBackWazuh
fi
if [ "${uninstall_module_name}" == "elasticsearch" ]; then
logger "Cleaning the installation. Elasticsearch will be uninstalled."
rollBackElasticsearch
fi
if [ "${uninstall_module_name}" == "kibana" ]; then
logger "Cleaning the installation. Kibana will be uninstalled."
rollBackKibana
fi
if [ "${uninstall_module_name}" == "all" ]; then
logger "Cleaning the installation. All packages and components will be uninstalled."
rollBackWazuh
rollBackElasticsearch
rollBackKibana
fi
fi

if [ -f "/etc/yum.repos.d/wazuh.repo" ]; then
eval "rm /etc/yum.repos.d/wazuh.repo"
Expand All @@ -286,6 +304,18 @@ function rollBack() {
eval "rm /etc/apt/sources.list.d/wazuh.list"
fi

if [ -z "${uninstall}" ]; then
if [ -n "${rollback_conf}" ] || [ -n "${overwrite}" ]; then
logger "Installation cleaned."
else
logger "Installation cleaned. Check the ${logfile} file to learn more about the issue."
fi
fi

}

function rollBackWazuh() {

if [[ -n "${wazuhinstalled}" && ( -n "${wazuh}" || -n "${AIO}" || -n "${uninstall}" ) ]];then
logger -w "Removing the Wazuh manager."
if [ "${sys_type}" == "yum" ]; then
Expand All @@ -302,6 +332,34 @@ function rollBack() {
eval "rm -rf /var/ossec/ ${debug}"
fi

if [[ -n "${filebeatinstalled}" && ( -n "${wazuh}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
logger -w "Removing Filebeat."
if [ "${sys_type}" == "yum" ]; then
eval "yum remove filebeat -y ${debug}"
elif [ "${sys_type}" == "zypper" ]; then
eval "zypper -n remove filebeat ${debug}"
elif [ "${sys_type}" == "apt-get" ]; then
eval "apt remove --purge filebeat -y ${debug}"
fi
fi

if [[ ( -n "${filebeat_remaining_files}" || -n "${filebeatinstalled}" ) && ( -n "${wazuh}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
eval "rm -rf /var/lib/filebeat/ ${debug}"
eval "rm -rf /usr/share/filebeat/ ${debug}"
eval "rm -rf /etc/filebeat/ ${debug}"
fi

elements_to_remove=( "/var/log/filebeat/"
"/etc/systemd/system/multi-user.target.wants/wazuh-manager.service"
"/etc/systemd/system/multi-user.target.wants/filebeat.service"
)

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

}

function rollBackElasticsearch() {

if [[ -n "${elasticsearchinstalled}" && ( -n "${elasticsearch}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
logger -w "Removing Elasticsearch."
if [ "${sys_type}" == "yum" ]; then
Expand All @@ -321,22 +379,20 @@ function rollBack() {
eval "rm -rf /etc/elasticsearch/ ${debug}"
fi

if [[ -n "${filebeatinstalled}" && ( -n "${wazuh}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
logger -w "Removing Filebeat."
if [ "${sys_type}" == "yum" ]; then
eval "yum remove filebeat -y ${debug}"
elif [ "${sys_type}" == "zypper" ]; then
eval "zypper -n remove filebeat ${debug}"
elif [ "${sys_type}" == "apt-get" ]; then
eval "apt remove --purge filebeat -y ${debug}"
fi
fi
elements_to_remove=( "/var/log/elasticsearch/"
"/etc/systemd/system/elasticsearch.service.wants/"
"/securityadmin_demo.sh"
"/etc/systemd/system/multi-user.target.wants/elasticsearch.service"
"/etc/systemd/system/multi-user.target.wants/kibana.service"
"/etc/systemd/system/kibana.service"
"/lib/firewalld/services/kibana.xml"
"/lib/firewalld/services/elasticsearch.xml" )

if [[ ( -n "${filebeat_remaining_files}" || -n "${filebeatinstalled}" ) && ( -n "${wazuh}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
eval "rm -rf /var/lib/filebeat/ ${debug}"
eval "rm -rf /usr/share/filebeat/ ${debug}"
eval "rm -rf /etc/filebeat/ ${debug}"
fi
eval "rm -rf ${elements_to_remove[*]}"

}

function rollBackKibana() {

if [[ -n "${kibanainstalled}" && ( -n "${kibana}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
logger -w "Removing Kibana."
Expand All @@ -355,28 +411,12 @@ function rollBack() {
eval "rm -rf /etc/kibana/ ${debug}"
fi

elements_to_remove=( "/var/log/elasticsearch/"
"/var/log/filebeat/"
"/etc/systemd/system/elasticsearch.service.wants/"
"/securityadmin_demo.sh"
"/etc/systemd/system/multi-user.target.wants/wazuh-manager.service"
"/etc/systemd/system/multi-user.target.wants/filebeat.service"
"/etc/systemd/system/multi-user.target.wants/elasticsearch.service"
"/etc/systemd/system/multi-user.target.wants/kibana.service"
elements_to_remove=( "/etc/systemd/system/multi-user.target.wants/kibana.service"
"/etc/systemd/system/kibana.service"
"/lib/firewalld/services/kibana.xml"
"/lib/firewalld/services/elasticsearch.xml" )
"/lib/firewalld/services/kibana.xml" )

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

if [ -z "${uninstall}" ]; then
if [ -n "${rollback_conf}" ] || [ -n "${overwrite}" ]; then
logger "Installation cleaned."
else
logger "Installation cleaned. Check the ${logfile} file to learn more about the issue."
fi
fi

}

function startService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function initializeElasticsearch() {

function installElasticsearch() {

uninstall_module_name="elasticsearch"
logger "Starting Open Distro for Elasticsearch installation."

if [ "${sys_type}" == "yum" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function copyCertificatesFilebeat() {

function installFilebeat() {

uninstall_module_name="filebeat"
logger "Starting filebeat installation."

if [ "${sys_type}" == "zypper" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function initializeKibanaAIO() {

function installKibana() {

uninstall_module_name="kibana"
logger "Starting Kibana installation."
if [ "${sys_type}" == "zypper" ]; then
eval "zypper -n install opendistroforelasticsearch-kibana=${opendistro_version} ${debug}"
Expand Down
1 change: 1 addition & 0 deletions unattended_installer/install_functions/opendistro/wazuh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function configureWazuhCluster() {

function installWazuh() {

uninstall_module_name="wazuh"
logger "Starting the Wazuh manager installation."
if [ "${sys_type}" == "zypper" ]; then
eval "${sys_type} -n install wazuh-manager=${wazuh_version}-${wazuh_revision} ${debug}"
Expand Down
10 changes: 8 additions & 2 deletions unattended_installer/wazuh_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

echo -e " Uninstalls all Wazuh components. NOTE: This will erase all the existing configuration and data."
echo -e ""
echo -e " -v, --verbose"
Expand Down Expand Up @@ -284,8 +284,14 @@ function main() {
shift 2
;;
"-u"|"--uninstall")
if [ -z "${2}" ]; then
logger -e "Error on arguments. Probably missing <app-module-name> after -u|--uninstall."
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
getHelp
exit 1
fi
uninstall=1
shift 1
uninstall_module_name="${2}"
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
shift 2
;;
"-v"|"--verbose")
debugEnabled=1
Expand Down