Skip to content

Commit

Permalink
Merge pull request #2691 from wazuh/enhancement/1422-improve-offline-…
Browse files Browse the repository at this point in the history
…installation-experience

Added offline installation feature to Installation Assistant
  • Loading branch information
teddytpc1 authored Jan 3, 2024
2 parents 5c53afc + aae2491 commit 9766d74
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 30 deletions.
9 changes: 9 additions & 0 deletions unattended_installer/install_functions/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ function checks_arguments() {
fi
fi

# -------------- 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."
exit 1
fi
fi

# -------------- Configurations ---------------------------------

if [ -f "${tar_file}" ]; then
Expand Down
3 changes: 1 addition & 2 deletions unattended_installer/install_functions/dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ function dashboard_install() {

common_logger "Starting Wazuh dashboard installation."
if [ "${sys_type}" == "yum" ]; then
eval "yum install wazuh-dashboard${sep}${wazuh_version} -y ${debug}"
install_result="${PIPESTATUS[0]}"
installCommon_yumInstall "wazuh-dashboard" "${wazuh_version}-*"
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_aptInstall "wazuh-dashboard" "${wazuh_version}-*"
fi
Expand Down
37 changes: 21 additions & 16 deletions unattended_installer/install_functions/filebeat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@
function filebeat_configure(){

common_logger -d "Configuring Filebeat."
eval "common_curl -sSo /etc/filebeat/wazuh-template.json ${filebeat_wazuh_template} --max-time 300 --retry 5 --retry-delay 5 --fail"
if [ ! -f "/etc/filebeat/wazuh-template.json" ]; then
common_logger -e "Error downloading wazuh-template.json file."
installCommon_rollBack
exit 1
fi
common_logger -d "Filebeat template was download successfully."

eval "chmod go+r /etc/filebeat/wazuh-template.json ${debug}"
eval "(common_curl -sS ${filebeat_wazuh_module} --max-time 300 --retry 5 --retry-delay 5 --fail | tar -xvz -C /usr/share/filebeat/module) ${debug}"
if [ ! -d "/usr/share/filebeat/module" ]; then
common_logger -e "Error downloading wazuh filebeat module."
installCommon_rollBack
exit 1
if [ -z "${offline_install}" ]; then
eval "common_curl -sSo /etc/filebeat/wazuh-template.json ${filebeat_wazuh_template} --max-time 300 --retry 5 --retry-delay 5 --fail"
if [ ! -f "/etc/filebeat/wazuh-template.json" ]; then
common_logger -e "Error downloading wazuh-template.json file."
installCommon_rollBack
exit 1
fi
common_logger -d "Filebeat template was download successfully."

eval "(common_curl -sS ${filebeat_wazuh_module} --max-time 300 --retry 5 --retry-delay 5 --fail | tar -xvz -C /usr/share/filebeat/module) ${debug}"
if [ ! -d "/usr/share/filebeat/module" ]; then
common_logger -e "Error downloading wazuh filebeat module."
installCommon_rollBack
exit 1
fi
common_logger -d "Filebeat module was downloaded successfully."
else
eval "cp ${offline_files_path}/wazuh-template.json /etc/filebeat/wazuh-template.json ${debug}"
eval "tar -xvzf ${offline_files_path}/wazuh-filebeat-*.tar.gz -C /usr/share/filebeat/module ${debug}"
fi
common_logger -d "Filebeat module was downloaded successfully."

eval "chmod go+r /etc/filebeat/wazuh-template.json ${debug}"
if [ -n "${AIO}" ]; then
eval "installCommon_getConfig filebeat/filebeat_unattended.yml /etc/filebeat/filebeat.yml ${debug}"
else
Expand Down Expand Up @@ -94,8 +100,7 @@ function filebeat_install() {

common_logger "Starting Filebeat installation."
if [ "${sys_type}" == "yum" ]; then
eval "yum install filebeat${sep}${filebeat_version} -y -q ${debug}"
install_result="${PIPESTATUS[0]}"
installCommon_yumInstall "filebeat" "${filebeat_version}"
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_aptInstall "filebeat" "${filebeat_version}"
fi
Expand Down
3 changes: 1 addition & 2 deletions unattended_installer/install_functions/indexer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ function indexer_install() {
common_logger "Starting Wazuh indexer installation."

if [ "${sys_type}" == "yum" ]; then
eval "yum install wazuh-indexer-${wazuh_version} -y ${debug}"
install_result="${PIPESTATUS[0]}"
installCommon_yumInstall "wazuh-indexer" "${wazuh_version}-*"
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_aptInstall "wazuh-indexer" "${wazuh_version}-*"
fi
Expand Down
17 changes: 16 additions & 1 deletion unattended_installer/install_functions/installCommon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ function installCommon_aptInstall() {
else
installer=${package}
fi

# Offline installation case: get package name and install it
if [ -n "${offline_install}" ]; then
package_name=$(ls ${offline_packages_path} | grep ${package})
installer="${offline_packages_path}/${package_name}"
fi

command="DEBIAN_FRONTEND=noninteractive apt-get install ${installer} -y -q"
common_checkAptLock

Expand Down Expand Up @@ -848,7 +855,15 @@ function installCommon_yumInstall() {
installer="${package}"
fi

command="yum install ${installer} -y"
# Offline installation case: get package name and install it
if [ -n "${offline_install}" ]; then
package_name=$(ls ${offline_packages_path} | grep ${package})
installer="${offline_packages_path}/${package_name}"
command="rpm -ivh ${installer}"
common_logger -d "Installing local package: ${installer}"
else
command="yum install ${installer} -y"
fi
common_checkYumLock

if [ "${attempt}" -ne "${max_attempts}" ]; then
Expand Down
33 changes: 26 additions & 7 deletions unattended_installer/install_functions/installMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ function getHelp() {
echo -e " -o, --overwrite"
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 ""
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."
echo -e ""
Expand Down Expand Up @@ -114,6 +117,10 @@ function main() {
overwrite=1
shift 1
;;
"-of"|"--offline-installation")
offline_install=1
shift 1
;;
"-p"|"--port")
if [ -z "${2}" ]; then
common_logger -e "Error on arguments. Probably missing <port> after -p|--port"
Expand Down Expand Up @@ -217,6 +224,12 @@ function main() {

common_checkSystem

if [ -z "${uninstall}" ] && [ -z "${offline_install}" ]; then
installCommon_installCheckDependencies
elif [ -n "${offline_install}" ]; then
offline_checkDependencies
fi

if [ -z "${download}" ]; then
check_dist
fi
Expand All @@ -230,10 +243,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 Expand Up @@ -275,10 +284,20 @@ function main() {

# -------------- Wazuh repo ----------------------

# Offline installation case: extract the compressed files
if [ -n "${offline_install}" ]; then
offline_checkPreinstallation
offline_extractFiles
fi

if [ -n "${AIO}" ] || [ -n "${indexer}" ] || [ -n "${dashboard}" ] || [ -n "${wazuh}" ]; then
installCommon_installPrerequisites
if [ -z "${offline_install}" ]; then
installCommon_installPrerequisites
fi
check_curlVersion
installCommon_addWazuhRepo
if [ -z "${offline_install}" ]; then
installCommon_addWazuhRepo
fi
fi

# -------------- Configuration creation case -----------------------
Expand Down Expand Up @@ -387,7 +406,7 @@ function main() {

# -------------------------------------------------------------------

if [ -z "${configurations}" ] && [ -z "${download}" ]; then
if [ -z "${configurations}" ] && [ -z "${download}" ] && [ -z "${offline_install}" ]; then
installCommon_restoreWazuhrepo
fi

Expand Down
3 changes: 1 addition & 2 deletions unattended_installer/install_functions/manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ function manager_install() {

common_logger "Starting the Wazuh manager installation."
if [ "${sys_type}" == "yum" ]; then
eval "${sys_type} install wazuh-manager${sep}${wazuh_version} -y ${debug}"
install_result="${PIPESTATUS[0]}"
installCommon_yumInstall "wazuh-manager" "${wazuh_version}-*"
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_aptInstall "wazuh-manager" "${wazuh_version}-*"
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

# Wazuh installer: offline download
# Copyright (C) 2023, Wazuh Inc.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.

# Checks the necessary dependencies for the installation
function offline_checkDependencies() {

dependencies=( curl tar gnupg openssl )

common_logger "Checking installed dependencies 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 dependencies are installed."

}

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

offline_tarfile="${base_dest_folder}.tar.gz"
common_logger "Checking ${offline_tarfile} file."
if [ ! -f "${base_path}/${offline_tarfile}" ]; then
common_logger -e "The ${offline_tarfile} file was not found in ${base_path}."
exit 1
fi
common_logger -d "${offline_tarfile} was found correctly."

}

# Extracts the files for the offline installation and check its content
function offline_extractFiles() {

common_logger -d "Extracting files from ${offline_tarfile}"
if [ ! -d "${base_path}/wazuh-offline/" ]; then
eval "tar -xzf ${offline_tarfile} ${debug}"

if [ ! -d "${base_path}/wazuh-offline/" ]; then
common_logger -e "The ${offline_tarfile} file could not be decompressed."
exit 1
fi
fi

offline_files_path="${base_path}/wazuh-offline/wazuh-files"
offline_packages_path="${base_path}/wazuh-offline/wazuh-packages"

required_files=(
"${offline_files_path}/filebeat.yml"
"${offline_files_path}/GPG-KEY-WAZUH"
"${offline_files_path}/wazuh-filebeat-*.tar.gz"
"${offline_files_path}/wazuh-template.json"
)

if [ "${sys_type}" == "apt-get" ]; then
required_files+=("${offline_packages_path}/filebeat-oss-*.deb" "${offline_packages_path}/wazuh-dashboard_*.deb" "${offline_packages_path}/wazuh-indexer_*.deb" "${offline_packages_path}/wazuh-manager_*.deb")
elif [ "${sys_type}" == "rpm" ]; then
required_files+=("${offline_packages_path}/filebeat-oss-*.rpm" "${offline_packages_path}/wazuh-dashboard_*.rpm" "${offline_packages_path}/wazuh-indexer_*.rpm" "${offline_packages_path}/wazuh-manager_*.rpm")
fi

for file in "${required_files[@]}"; do
if ! compgen -G "${file}" > /dev/null; then
common_logger -e "Missing necessary offline file: ${file}"
exit 1
fi
done

common_logger -d "Offline files extracted successfully."
}

0 comments on commit 9766d74

Please sign in to comment.