diff --git a/unattended_installer/install_functions/checks.sh b/unattended_installer/install_functions/checks.sh index c1754d4855..b7c3dcdb4f 100644 --- a/unattended_installer/install_functions/checks.sh +++ b/unattended_installer/install_functions/checks.sh @@ -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 diff --git a/unattended_installer/install_functions/dashboard.sh b/unattended_installer/install_functions/dashboard.sh index d4fe4b8790..b0248015d6 100644 --- a/unattended_installer/install_functions/dashboard.sh +++ b/unattended_installer/install_functions/dashboard.sh @@ -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 diff --git a/unattended_installer/install_functions/filebeat.sh b/unattended_installer/install_functions/filebeat.sh index d4061d640d..6cf2d5e8eb 100644 --- a/unattended_installer/install_functions/filebeat.sh +++ b/unattended_installer/install_functions/filebeat.sh @@ -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 @@ -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 diff --git a/unattended_installer/install_functions/indexer.sh b/unattended_installer/install_functions/indexer.sh index 1eeb485a0b..9e28fc014c 100644 --- a/unattended_installer/install_functions/indexer.sh +++ b/unattended_installer/install_functions/indexer.sh @@ -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 diff --git a/unattended_installer/install_functions/installCommon.sh b/unattended_installer/install_functions/installCommon.sh index 500c76f002..7702b87844 100644 --- a/unattended_installer/install_functions/installCommon.sh +++ b/unattended_installer/install_functions/installCommon.sh @@ -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 @@ -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 diff --git a/unattended_installer/install_functions/installMain.sh b/unattended_installer/install_functions/installMain.sh index 292debd018..cd6f6bf6c6 100755 --- a/unattended_installer/install_functions/installMain.sh +++ b/unattended_installer/install_functions/installMain.sh @@ -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 "" @@ -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 after -p|--port" @@ -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 @@ -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 @@ -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 ----------------------- @@ -387,7 +406,7 @@ function main() { # ------------------------------------------------------------------- - if [ -z "${configurations}" ] && [ -z "${download}" ]; then + if [ -z "${configurations}" ] && [ -z "${download}" ] && [ -z "${offline_install}" ]; then installCommon_restoreWazuhrepo fi diff --git a/unattended_installer/install_functions/manager.sh b/unattended_installer/install_functions/manager.sh index 3f94b3497c..a518609541 100644 --- a/unattended_installer/install_functions/manager.sh +++ b/unattended_installer/install_functions/manager.sh @@ -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 diff --git a/unattended_installer/install_functions/wazuh-offline-installation.sh b/unattended_installer/install_functions/wazuh-offline-installation.sh new file mode 100644 index 0000000000..73a24d1c5b --- /dev/null +++ b/unattended_installer/install_functions/wazuh-offline-installation.sh @@ -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." +}