-
Notifications
You must be signed in to change notification settings - Fork 98
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
base: unify-unatteded-uninstall-chose-component
Are you sure you want to change the base?
Changes from 8 commits
4b8cda9
4530295
dcdd5e3
c79f38e
e845bd4
78c6d9a
9579597
346f192
2decde4
75ae8a8
d7595e0
2761821
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
|
@@ -82,6 +81,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." | ||||||
|
@@ -96,6 +96,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." | ||||||
|
@@ -109,6 +110,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." | ||||||
|
@@ -141,6 +143,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 | ||||||
|
@@ -155,42 +161,83 @@ function checkArguments() { | |||||
|
||||||
} | ||||||
|
||||||
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 tool -----------------------------------" | ||||||
logger "Missing tool report: ${missingtoolsList} are not installed. All this command's are necessary for the correct use of this tool." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
exit 1 | ||||||
|
||||||
fi | ||||||
|
||||||
} | ||||||
|
||||||
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 -w "The script needs to parse the file '${coresFile}' to check the minimum required hardware of CPU cores." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you plan to exit from the script run, this message is not a warning but an error. Only errors should be able to exit from a run. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
logger -w "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check." | ||||||
exit 1 | ||||||
fi | ||||||
if [ -z "${ram_gb}" ]; then | ||||||
logger - w "The command 'free' is required to check the minimum required hardware of RAM." | ||||||
alberpilot marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another point: is there any way to reach this code without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the free command was not installed. /proc/meminfo can be used PS: I add a workarrond for the stage that free is not. |
||||||
logger -w "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 | ||||||
|
||||||
|
@@ -316,7 +363,12 @@ function checkPreviousCertificates() { | |||||
|
||||||
function checkSpecs() { | ||||||
|
||||||
cores=$(cat /proc/cpuinfo | grep -c processor ) | ||||||
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 | ||||||
ram_gb=$(free -m | awk '/^Mem:/{print $2}') | ||||||
|
||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,6 +336,8 @@ function main() { | |
importFunction "wazuh-cert-tool.sh" | ||
importFunction "wazuh-passwords-tool.sh" | ||
|
||
checkTools | ||
|
||
logger "Starting Wazuh unattended installer. Wazuh version: ${wazuh_version}. Wazuh installer version: ${wazuh_install_vesion}" | ||
|
||
# -------------- Preliminary checks -------------------------------- | ||
|
@@ -356,6 +358,7 @@ function main() { | |
# -------------- Uninstall case ------------------------------------ | ||
|
||
if [ -n "${uninstall}" ]; then | ||
|
||
importFunction "wazuh.sh" | ||
importFunction "filebeat.sh" | ||
importFunction "elasticsearch.sh" | ||
|
@@ -404,14 +407,6 @@ function main() { | |
checkNames | ||
fi | ||
|
||
# -------------- Prerequisites and Wazuh repo ---------------------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the Dependencies installation uneccesary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recovered, this was a mistake There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why is moved before the preliminary steps? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done