Skip to content

Commit

Permalink
Merge pull request #3074 from wazuh/bug/3072-offline-install-fix-temp…
Browse files Browse the repository at this point in the history
…late-download

Fixed bugs for offline installation with the installation assistant
  • Loading branch information
c-bordon authored Aug 15, 2024
2 parents add6b47 + 418f13f commit 29ca39e
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 34 deletions.
22 changes: 12 additions & 10 deletions unattended_installer/install_functions/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function checks_arguments() {
# -------------- Offline installation ---------------------

if [ -n "${offline_install}" ]; then
if [ -z "${AIO}" ] && [ -z "${dashboard}" ] && [ -z "${indexer}" ] && [ -z "${wazuh}" ]; then
common_logger -e "The -of|--offline-installation option must be used with -a, -ws, -wi, or -wd."
if [ -z "${AIO}" ] && [ -z "${dashboard}" ] && [ -z "${indexer}" ] && [ -z "${wazuh}" ] && [ -z "${start_indexer_cluster}" ]; then
common_logger -e "The -of|--offline-installation option must be used with -a, -ws, -s, -wi, or -wd."
exit 1
fi
fi
Expand Down Expand Up @@ -378,15 +378,17 @@ function checks_specifications() {

function checks_ports() {

dep="lsof"
if [ "${sys_type}" == "yum" ]; then
installCommon_yumInstallList "${dep}"
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_aptInstallList "${dep}"
fi
if [ -z "${offline_install}" ]; then
dep="lsof"
if [ "${sys_type}" == "yum" ]; then
installCommon_yumInstallList "${dep}"
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_aptInstallList "${dep}"
fi

if [ "${#not_installed[@]}" -gt 0 ]; then
wia_dependencies_installed+=("${dep}")
if [ "${#not_installed[@]}" -gt 0 ]; then
wia_dependencies_installed+=("${dep}")
fi
fi

common_logger -d "Checking ports availability."
Expand Down
23 changes: 21 additions & 2 deletions unattended_installer/install_functions/indexer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,28 @@ function indexer_startCluster() {
common_logger "Wazuh indexer cluster security configuration initialized."
fi

# Validate Wazuh indexer security admin it is initialized
indexer_security_admin_comm="common_curl -XGET https://"${indexer_node_ips[pos]}":9200/ -uadmin:admin -k --max-time 120 --silent -w \"%{http_code}\" --output /dev/null"
http_status=$(eval "${indexer_security_admin_comm}")
retries=0
max_retries=5
while [ "${http_status}" -ne 200 ]; do
common_logger -d "Waiting for Wazuh indexer to be ready. wazuh-indexer status: ${http_status}"
sleep 5
retries=$((retries+1))
if [ "${retries}" -eq "${max_retries}" ]; then
common_logger -e "The Wazuh indexer cluster security configuration could not be initialized."
exit 1
fi
http_status=$(eval "${indexer_security_admin_comm}")
done

# Wazuh alerts template injection
eval "common_curl --silent ${filebeat_wazuh_template} --max-time 300 --retry 5 --retry-delay 5 ${debug}" | eval "common_curl -X PUT 'https://${indexer_node_ips[pos]}:9200/_template/wazuh' -H 'Content-Type: application/json' -d @- -uadmin:admin -k --silent --max-time 300 --retry 5 --retry-delay 5 ${debug}"
if [ "${PIPESTATUS[0]}" != 0 ]; then
if [ -n "${offline_install}" ]; then
filebeat_wazuh_template="file://${offline_files_path}/wazuh-template.json"
fi
http_status=$(eval "common_curl --silent '${filebeat_wazuh_template}' --max-time 300 --retry 5 --retry-delay 5 ${debug}" | eval "common_curl -X PUT 'https://${indexer_node_ips[pos]}:9200/_template/wazuh' -H \'Content-Type: application/json\' -d @- -uadmin:admin -k --max-time 300 --retry 5 --retry-delay 5 -w "%{http_code}" -o /dev/null")
if [ "${http_status}" -ne 200 ]; then
common_logger -e "The wazuh-alerts template could not be inserted into the Wazuh indexer cluster."
exit 1
else
Expand Down
60 changes: 45 additions & 15 deletions unattended_installer/install_functions/installCommon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -390,35 +390,65 @@ function installCommon_installPrerequisites() {
if [ "${sys_type}" == "yum" ]; then
if [ "${1}" == "AIO" ]; then
deps=($(echo "${indexer_yum_dependencies[@]}" "${dashboard_yum_dependencies[@]}" | tr ' ' '\n' | sort -u))
common_logger -d "${message}"
installCommon_yumInstallList "${deps[@]}"
if [ -z "${offline_install}" ]; then
common_logger -d "${message}"
installCommon_yumInstallList "${deps[@]}"
else
offline_checkPrerequisites "${deps[@]}"
fi
fi
if [ "${1}" == "indexer" ]; then
common_logger -d "${message}"
installCommon_yumInstallList "${indexer_yum_dependencies[@]}"
if [ -z "${offline_install}" ]; then
common_logger -d "${message}"
installCommon_yumInstallList "${indexer_yum_dependencies[@]}"
else
offline_checkPrerequisites "${indexer_yum_dependencies[@]}"
fi
fi
if [ "${1}" == "dashboard" ]; then
common_logger -d "${message}"
installCommon_yumInstallList "${dashboard_yum_dependencies[@]}"
if [ -z "${offline_install}" ]; then
common_logger -d "${message}"
installCommon_yumInstallList "${dashboard_yum_dependencies[@]}"
else
offline_checkPrerequisites "${dashboard_yum_dependencies[@]}"
fi
fi
elif [ "${sys_type}" == "apt-get" ]; then
eval "apt-get update -q ${debug}"
if [ -z "${offline_install}" ]; then
eval "apt-get update -q ${debug}"
fi
if [ "${1}" == "AIO" ]; then
deps=($(echo "${wazuh_apt_dependencies[@]}" "${indexer_apt_dependencies[@]}" "${dashboard_apt_dependencies[@]}" | tr ' ' '\n' | sort -u))
common_logger -d "${message}"
installCommon_aptInstallList "${deps[@]}"
if [ -z "${offline_install}" ]; then
common_logger -d "${message}"
installCommon_aptInstallList "${deps[@]}"
else
offline_checkPrerequisites "${deps[@]}"
fi
fi
if [ "${1}" == "indexer" ]; then
common_logger -d "${message}"
installCommon_aptInstallList "${indexer_apt_dependencies[@]}"
if [ -z "${offline_install}" ]; then
common_logger -d "${message}"
installCommon_aptInstallList "${indexer_apt_dependencies[@]}"
else
offline_checkPrerequisites "${indexer_apt_dependencies[@]}"
fi
fi
if [ "${1}" == "dashboard" ]; then
common_logger -d "${message}"
installCommon_aptInstallList "${dashboard_apt_dependencies[@]}"
if [ -z "${offline_install}" ]; then
common_logger -d "${message}"
installCommon_aptInstallList "${dashboard_apt_dependencies[@]}"
else
offline_checkPrerequisites "${dashboard_apt_dependencies[@]}"
fi
fi
if [ "${1}" == "wazuh" ]; then
common_logger -d "${message}"
installCommon_aptInstallList "${wazuh_apt_dependencies[@]}"
if [ -z "${offline_install}" ]; then
common_logger -d "${message}"
installCommon_aptInstallList "${wazuh_apt_dependencies[@]}"
else
offline_checkPrerequisites "${wazuh_apt_dependencies[@]}"
fi
fi
fi

Expand Down
6 changes: 1 addition & 5 deletions unattended_installer/install_functions/installMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getHelp() {
echo -e " Overwrites previously installed components. This will erase all the existing configuration and data."
echo -e ""
echo -e " -of, --offline-installation"
echo -e " Perform an offline installation. This option must be used with -a, -ws, -wi, or -wd."
echo -e " Perform an offline installation. This option must be used with -a, -ws, -s, -wi, or -wd."
echo -e ""
echo -e " -p, --port"
echo -e " Specifies the Wazuh web user interface port. By default is the 443 TCP port. Recommended ports are: 8443, 8444, 8080, 8888, 9000."
Expand Down Expand Up @@ -251,10 +251,6 @@ function main() {

# -------------- Preliminary checks and Prerequisites --------------------------------

if [ -z "${uninstall}" ]; then
installCommon_installCheckDependencies
fi

if [ -z "${configurations}" ] && [ -z "${AIO}" ] && [ -z "${download}" ]; then
checks_previousCertificate
fi
Expand Down
2 changes: 1 addition & 1 deletion unattended_installer/install_functions/installVariables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config_file="${base_path}/config.yml"
readonly tar_file_name="wazuh-install-files.tar"
tar_file="${base_path}/${tar_file_name}"

readonly filebeat_wazuh_template="https://raw.githubusercontent.com/wazuh/wazuh/${source_branch}/extensions/elasticsearch/7.x/wazuh-template.json"
filebeat_wazuh_template="https://raw.githubusercontent.com/wazuh/wazuh/${source_branch}/extensions/elasticsearch/7.x/wazuh-template.json"

readonly dashboard_cert_path="/etc/wazuh-dashboard/certs"
readonly filebeat_cert_path="/etc/filebeat/certs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Checks the necessary dependencies for the installation
function offline_checkDependencies() {

dependencies=( curl tar gnupg openssl )
dependencies=( curl tar gnupg openssl lsof )

common_logger "Checking installed dependencies for Offline installation."
for dep in "${dependencies[@]}"; do
Expand All @@ -30,6 +30,26 @@ function offline_checkDependencies() {

}

# Checks the necessary packages needed for a Wazuh component
function offline_checkPrerequisites(){

dependencies=("$@")
common_logger "Checking prerequisites for Offline installation."
for dep in "${dependencies[@]}"; do
if [ "${sys_type}" == "yum" ]; then
eval "yum list installed 2>/dev/null | grep -q -E ^"${dep}"\\."
elif [ "${sys_type}" == "apt-get" ]; then
eval "apt list --installed 2>/dev/null | grep -q -E ^"${dep}"\/"
fi

if [ "${PIPESTATUS[0]}" != 0 ]; then
common_logger -e "${dep} is necessary for the offline installation."
exit 1
fi
done
common_logger -d "Offline prerequisites are installed."
}

# Checks the necessary files for the installation
function offline_checkPreinstallation() {

Expand Down

0 comments on commit 29ca39e

Please sign in to comment.