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 6 commits
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
18 changes: 9 additions & 9 deletions unattended_installer/install_functions/opendistro/checks.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wazuh installer - checks.sh functions.
# Wazuh installer - checks.sh functions.
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
Expand All @@ -21,8 +21,8 @@ function checkArguments() {
# -------------- Configurations ---------------------------------

if [[ ( -n "${AIO}" || -n "${configurations}" ) && -f "${tar_file}" ]]; then
logger -e "File ${tar_file} exists. Please remove it if you want to use a new configuration."
exit 1
logger -e "File ${tar_file} exists. Please remove it if you want to use a new configuration."
exit 1
fi

if [[ -n "${configurations}" && ( -n "${AIO}" || -n "${elasticsearch}" || -n "${kibana}" || -n "${wazuh}" || -n "${overwrite}" || -n "${start_elastic_cluster}" || -n "${tar_conf}" || -n "${uninstall}" ) ]]; then
Expand Down Expand Up @@ -89,7 +89,7 @@ function checkArguments() {
if [ -n "${elasticsearchinstalled}" ] || [ -n "${elastic_remaining_files}" ]; then
if [ -n "${overwrite}" ]; then
rollBack
else
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."
exit 1
fi
Expand All @@ -102,7 +102,7 @@ function checkArguments() {
if [ -n "${kibanainstalled}" ] || [ -n "${kibana_remaining_files}" ]; then
if [ -n "${overwrite}" ]; then
rollBack
else
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."
exit 1
fi
Expand All @@ -115,7 +115,7 @@ function checkArguments() {
if [ -n "${wazuhinstalled}" ] || [ -n "${wazuh_remaining_files}" ]; then
if [ -n "${overwrite}" ]; then
rollBack
else
else
logger -e "Wazuh is already installed in this node or some of its files haven't been erased. Use option -o|--overwrite to overwrite all components."
exit 1
fi
Expand Down Expand Up @@ -143,7 +143,7 @@ function checkArguments() {
if [ -z "${AIO}" ] && [ -z "${elasticsearch}" ] && [ -z "${kibana}" ] && [ -z "${wazuh}" ] && [ -z "${start_elastic_cluster}" ] && [ -z "${configurations}" ] && [ -z "${uninstall}"]; then
logger -e "At least one of these arguments is necessary -a|--all-in-one, -c|--create-configurations, -e|--elasticsearch <elasticsearch-node-name>, -k|--kibana <kibana-node-name>, -s|--start-cluster, -w|--wazuh-server <wazuh-node-name>, -u|--uninstall"
exit 1
fi
fi

}

Expand Down Expand Up @@ -240,7 +240,7 @@ function checkIfInstalled() {

}

# This function ensures different names in the config.yml file.
# This function ensures different names in the config.yml file.
function checkNames() {

if [ -n "${einame}" ] && [ -n "${kiname}" ] && [ "${einame}" == "${kiname}" ]; then
Expand All @@ -261,7 +261,7 @@ function checkNames() {
if [ -n "${winame}" ] && [ -z "$(echo "${wazuh_servers_node_names[@]}" | grep -w "${winame}")" ]; then
logger -e "The Wazuh server node name ${winame} does not appear on the configuration file."
exit 1
fi
fi

if [ -n "${einame}" ] && [ -z "$(echo "${elasticsearch_node_names[@]}" | grep -w "${einame}")" ]; then
logger -e "The Elasticsearch node name ${einame} does not appear on the configuration file."
Expand Down
112 changes: 20 additions & 92 deletions unattended_installer/install_functions/opendistro/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wazuh installer - common.sh functions.
# Wazuh installer - common.sh functions.
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
Expand Down Expand Up @@ -90,7 +90,7 @@ function changePasswords() {
readUsers
fi
readPasswordFileUsers
else
else
logger -e "Cannot find passwords-file. Exiting"
exit 1
fi
Expand All @@ -99,7 +99,7 @@ function changePasswords() {
createBackUp
generateHash
fi

changePassword

if [ -n "${start_elastic_cluster}" ] || [ -n "${AIO}" ]; then
Expand Down Expand Up @@ -191,7 +191,7 @@ User:
name: kibanaserver
password: kibanaserverpassword"

exit 1
exit 1
fi

sfileusers=$(grep name: "${p_file}" | awk '{ print substr( $2, 1, length($2) ) }')
Expand Down Expand Up @@ -222,11 +222,11 @@ User:
finalusers=()
finalpasswords=()

if [ -n "${kibanainstalled}" ] && [ -n "${kibana}" ]; then
if [ -n "${kibanainstalled}" ] && [ -n "${kibana}" ]; then
users=( kibanaserver admin )
fi

if [ -n "${filebeatinstalled}" ] && [ -n "${wazuh}" ]; then
if [ -n "${filebeatinstalled}" ] && [ -n "${wazuh}" ]; then
users=( admin )
fi

Expand Down Expand Up @@ -274,8 +274,18 @@ function restoreWazuhrepo() {

function rollBack() {

if [ -z "${uninstall}" ]; then
logger "Cleaning the installation."
logger "Cleaning the installation."
component=$1
if [ -n "${AIO}" ] ; then
component="all"
fi
if $component != "all"; then
eval "uninstall$component"
else
logger "Cleaning the installation. All packages and components will be uninstalled."
eval "uninstallWazuh"
eval "uninstallElasticsearch"
eval "uninstallKibana"
fi

if [ -f "/etc/yum.repos.d/wazuh.repo" ]; then
Expand All @@ -285,89 +295,7 @@ function rollBack() {
elif [ -f "/etc/apt/sources.list.d/wazuh.list" ]; then
eval "rm /etc/apt/sources.list.d/wazuh.list"
fi

if [[ -n "${wazuhinstalled}" && ( -n "${wazuh}" || -n "${AIO}" || -n "${uninstall}" ) ]];then
logger -w "Removing the Wazuh manager."
if [ "${sys_type}" == "yum" ]; then
eval "yum remove wazuh-manager -y ${debug}"
elif [ "${sys_type}" == "zypper" ]; then
eval "zypper -n remove wazuh-manager ${debug}"
eval "rm -f /etc/init.d/wazuh-manager ${debug}"
elif [ "${sys_type}" == "apt-get" ]; then
eval "apt remove --purge wazuh-manager -y ${debug}"
fi
fi

if [[ ( -n "${wazuh_remaining_files}" || -n "${wazuhinstalled}" ) && ( -n "${wazuh}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
eval "rm -rf /var/ossec/ ${debug}"
fi

if [[ -n "${elasticsearchinstalled}" && ( -n "${elasticsearch}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
logger -w "Removing Elasticsearch."
if [ "${sys_type}" == "yum" ]; then
eval "yum remove opendistroforelasticsearch -y ${debug}"
eval "yum remove elasticsearch* -y ${debug}"
eval "yum remove opendistro-* -y ${debug}"
elif [ "${sys_type}" == "zypper" ]; then
eval "zypper -n remove opendistroforelasticsearch elasticsearch* opendistro-* ${debug}"
elif [ "${sys_type}" == "apt-get" ]; then
eval "apt remove --purge ^elasticsearch* ^opendistro-* ^opendistroforelasticsearch -y ${debug}"
fi
fi

if [[ ( -n "${elastic_remaining_files}" || -n "${elasticsearchinstalled}" ) && ( -n "${elasticsearch}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
eval "rm -rf /var/lib/elasticsearch/ ${debug}"
eval "rm -rf /usr/share/elasticsearch/ ${debug}"
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

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

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

if [[ ( -n "${kibana_remaining_files}" || -n "${kibanainstalled}" ) && ( -n "${kibana}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
eval "rm -rf /var/lib/kibana/ ${debug}"
eval "rm -rf /usr/share/kibana/ ${debug}"
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"
"/etc/systemd/system/kibana.service"
"/lib/firewalld/services/kibana.xml"
"/lib/firewalld/services/elasticsearch.xml" )

eval "rm -rf ${elements_to_remove[*]}"
logger "Cleaning the installation. Repositories were removed."

if [ -z "${uninstall}" ]; then
if [ -n "${rollback_conf}" ] || [ -n "${overwrite}" ]; then
Expand Down Expand Up @@ -409,7 +337,7 @@ function startService() {
exit 1
else
logger "${1^} service started."
fi
fi
elif [ -x "/etc/rc.d/init.d/${1}" ] ; then
eval "/etc/rc.d/init.d/${1} start ${debug}"
if [ "$?" != 0 ]; then
Expand Down
42 changes: 39 additions & 3 deletions unattended_installer/install_functions/opendistro/elasticsearch.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wazuh installer - elasticsearch.sh functions.
# Wazuh installer - elasticsearch.sh functions.
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
Expand Down Expand Up @@ -38,7 +38,7 @@ function configureElasticsearch() {
eval "getConfig elasticsearch/roles/roles_mapping.yml /usr/share/elasticsearch/plugins/opendistro_security/securityconfig/roles_mapping.yml ${debug}"
eval "getConfig elasticsearch/roles/internal_users.yml /usr/share/elasticsearch/plugins/opendistro_security/securityconfig/internal_users.yml ${debug}"
eval "rm -f /etc/elasticsearch/{esnode-key.pem,esnode.pem,kirk-key.pem,kirk.pem,root-ca.pem} ${debug}"

copyCertificatesElasticsearch

# Configure JVM options for Elasticsearch
Expand Down Expand Up @@ -106,7 +106,7 @@ function configureElasticsearch() {
}

function copyCertificatesElasticsearch() {

eval "mkdir -p ${e_certs_path} ${debug}"
name=${elasticsearch_node_names[pos]}

Expand Down Expand Up @@ -148,6 +148,7 @@ function initializeElasticsearch() {

function installElasticsearch() {

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

if [ "${sys_type}" == "yum" ]; then
Expand All @@ -169,6 +170,41 @@ function installElasticsearch() {

}

function uninstallElasticsearch() {
logger "Cleaning the installation. Elasticsearch will be uninstalled."

if [[ -n "${elasticsearchinstalled}" && ( -n "${elasticsearch}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
logger -w "Removing Elasticsearch."
if [ "${sys_type}" == "yum" ]; then
eval "yum remove opendistroforelasticsearch -y ${debug}"
eval "yum remove elasticsearch* -y ${debug}"
eval "yum remove opendistro-* -y ${debug}"
elif [ "${sys_type}" == "zypper" ]; then
eval "zypper -n remove opendistroforelasticsearch elasticsearch* opendistro-* ${debug}"
elif [ "${sys_type}" == "apt-get" ]; then
eval "apt remove --purge ^elasticsearch* ^opendistro-* ^opendistroforelasticsearch -y ${debug}"
fi
fi

if [[ ( -n "${elastic_remaining_files}" || -n "${elasticsearchinstalled}" ) && ( -n "${elasticsearch}" || -n "${AIO}" || -n "${uninstall}" ) ]]; then
eval "rm -rf /var/lib/elasticsearch/ ${debug}"
eval "rm -rf /usr/share/elasticsearch/ ${debug}"
eval "rm -rf /etc/elasticsearch/ ${debug}"
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" )

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


function startElasticsearchCluster() {

eval "elasticsearch_cluster_ip=( $(cat /etc/elasticsearch/elasticsearch.yml | grep network.host | sed 's/network.host:\s//') )"
Expand Down
5 changes: 3 additions & 2 deletions unattended_installer/install_functions/opendistro/filebeat.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wazuh installer - filebeat.sh functions.
# Wazuh installer - filebeat.sh functions.
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
Expand Down Expand Up @@ -54,8 +54,9 @@ function copyCertificatesFilebeat() {

function installFilebeat() {

uninstall_component_name="manager"
logger "Starting filebeat installation."

if [ "${sys_type}" == "zypper" ]; then
eval "zypper -n install filebeat-${elasticsearch_oss_version} ${debug}"
else
Expand Down
Loading