From 8a856ca5efbf6867d76d0aae0a8ab5d4265dcf3f Mon Sep 17 00:00:00 2001 From: c-bordon Date: Mon, 18 Apr 2022 14:02:21 -0300 Subject: [PATCH 1/7] Fix Offline argument --- unattended_installer/install_functions/installMain.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/unattended_installer/install_functions/installMain.sh b/unattended_installer/install_functions/installMain.sh index 84f6bbcd72..dd7c7fced4 100755 --- a/unattended_installer/install_functions/installMain.sh +++ b/unattended_installer/install_functions/installMain.sh @@ -182,6 +182,10 @@ function main() { common_logger -e "Error on arguments. Probably missing after -dw|--download-wazuh" getHelp exit 1 + elif [ "${2}" != "deb" ] && [ "${2}" != "rpm" ]; then + common_logger -e "Error on arguments. Probably missing after -dw|--download-wazuh" + getHelp + exit 1 fi download=1 package_type="${2}" From e59ca52abdf3e48f042ef8af042896e5e7e60398 Mon Sep 17 00:00:00 2001 From: c-bordon Date: Mon, 18 Apr 2022 14:13:06 -0300 Subject: [PATCH 2/7] Removed unnecessary validation --- unattended_installer/install_functions/installMain.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/unattended_installer/install_functions/installMain.sh b/unattended_installer/install_functions/installMain.sh index dd7c7fced4..10b07550a0 100755 --- a/unattended_installer/install_functions/installMain.sh +++ b/unattended_installer/install_functions/installMain.sh @@ -178,11 +178,7 @@ function main() { shift 2 ;; "-dw"|"--download-wazuh") - if [ -z "${2}" ]; then - common_logger -e "Error on arguments. Probably missing after -dw|--download-wazuh" - getHelp - exit 1 - elif [ "${2}" != "deb" ] && [ "${2}" != "rpm" ]; then + if [ "${2}" != "deb" ] && [ "${2}" != "rpm" ]; then common_logger -e "Error on arguments. Probably missing after -dw|--download-wazuh" getHelp exit 1 From 10cb4e021c4a5bcf024e0c5d42c817aeb826800f Mon Sep 17 00:00:00 2001 From: c-bordon Date: Tue, 19 Apr 2022 11:49:54 -0300 Subject: [PATCH 3/7] Changes in offline installator --- .../common_functions/common.sh | 10 +++- .../install_functions/installMain.sh | 14 +++++- .../install_functions/installVariables.sh | 16 +++---- .../wazuh-offline-download.sh | 46 ++++++++++++------- 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/unattended_installer/common_functions/common.sh b/unattended_installer/common_functions/common.sh index fd3eeb9929..fa3ffb57a7 100644 --- a/unattended_installer/common_functions/common.sh +++ b/unattended_installer/common_functions/common.sh @@ -36,8 +36,14 @@ function common_logger() { done fi - if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then - printf "${now} ${mtype} ${message}\n" | tee -a ${logfile} + if [ "$EUID" -eq 0 ]; then + if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then + printf "${now} ${mtype} ${message}\n" | tee -a ${logfile} + fi + else + if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then + printf "${now} ${mtype} ${message}\n" + fi fi } diff --git a/unattended_installer/install_functions/installMain.sh b/unattended_installer/install_functions/installMain.sh index 10b07550a0..ea9f757eb7 100755 --- a/unattended_installer/install_functions/installMain.sh +++ b/unattended_installer/install_functions/installMain.sh @@ -74,8 +74,6 @@ function getHelp() { function main() { umask 177 - common_checkRoot - if [ -z "${1}" ]; then getHelp fi @@ -85,6 +83,7 @@ function main() { case "${1}" in "-a"|"--all-in-one") AIO=1 + common_checkRoot shift 1 ;; "-ds"|"--disable-spinner") @@ -92,6 +91,7 @@ function main() { shift 1 ;; "-c"|"--configfile") + common_checkRoot if [ -z "${2}" ]; then common_logger -e "Error on arguments. Probably missing after -c|--configfile" getHelp @@ -102,10 +102,12 @@ function main() { shift 2 ;; "-F"|"--force-dashboard") + common_checkRoot force=1 shift 1 ;; "-g"|"--generate-configurations") + common_checkRoot configurations=1 shift 1 ;; @@ -113,18 +115,22 @@ function main() { getHelp ;; "-i"|"--ignore-check") + common_checkRoot ignore=1 shift 1 ;; "-o"|"--overwrite") + common_checkRoot overwrite=1 shift 1 ;; "-s"|"--start-cluster") + common_checkRoot start_indexer_cluster=1 shift 1 ;; "-t"|"--tar") + common_checkRoot if [ -z "${2}" ]; then common_logger -e "Error on arguments. Probably missing after -t|--tar" getHelp @@ -135,6 +141,7 @@ function main() { shift 2 ;; "-u"|"--uninstall") + common_checkRoot uninstall=1 shift 1 ;; @@ -148,6 +155,7 @@ function main() { shift 1 ;; "-wd"|"--wazuh-dashboard") + common_checkRoot if [ -z "${2}" ]; then common_logger -e "Error on arguments. Probably missing after -wd|---wazuh-dashboard" getHelp @@ -158,6 +166,7 @@ function main() { shift 2 ;; "-wi"|"--wazuh-indexer") + common_checkRoot if [ -z "${2}" ]; then common_logger -e "Arguments contain errors. Probably missing after -wi|--wazuh-indexer." getHelp @@ -168,6 +177,7 @@ function main() { shift 2 ;; "-ws"|"--wazuh-server") + common_checkRoot if [ -z "${2}" ]; then common_logger -e "Error on arguments. Probably missing after -ws|--wazuh-server" getHelp diff --git a/unattended_installer/install_functions/installVariables.sh b/unattended_installer/install_functions/installVariables.sh index 01404837ba..37090af98c 100644 --- a/unattended_installer/install_functions/installVariables.sh +++ b/unattended_installer/install_functions/installVariables.sh @@ -35,18 +35,18 @@ debug=">> ${logfile} 2>&1" ## Offline Installation vars readonly BASE_DEST_FOLDER="wazuh-offline" readonly WAZUH_DEB_BASE_URL="${BASE_URL}/apt/pool/main/w/wazuh-manager" -readonly WAZUH_DEB_PACKAGES=( "wazuh-manager_${wazuh_version}-${wazuh_revision}_amd64.deb" ) +readonly WAZUH_DEB_PACKAGES="wazuh-manager_${wazuh_version}-${wazuh_revision}_amd64.deb" readonly FILEBEAT_DEB_BASE_URL="${BASE_URL}/apt/pool/main/f/filebeat" -readonly FILEBEAT_DEB_PACKAGES=( "filebeat-oss-${filebeat_version}-amd64.deb" ) +readonly FILEBEAT_DEB_PACKAGES="filebeat-oss-${filebeat_version}-amd64.deb" readonly INDEXER_DEB_BASE_URL="${BASE_URL}/apt/pool/main/w/wazuh-indexer" -readonly INDEXER_DEB_PACKAGES=( "wazuh-indexer_${wazuh_version}-${wazuh_revision}_amd64.deb" ) +readonly INDEXER_DEB_PACKAGES="wazuh-indexer_${wazuh_version}-${wazuh_revision}_amd64.deb" readonly DASHBOARD_DEB_BASE_URL="${BASE_URL}/apt/pool/main/w/wazuh-dashboard" -readonly DASHBOARD_DEB_PACKAGES=( "wazuh-dashboard_${wazuh_version}-${wazuh_revision}_amd64.deb" ) +readonly DASHBOARD_DEB_PACKAGES="wazuh-dashboard_${wazuh_version}-${wazuh_revision}_amd64.deb" readonly WAZUH_RPM_BASE_URL="${BASE_URL}/yum" -readonly WAZUH_RPM_PACKAGES=( "wazuh-manager-${wazuh_version}-${wazuh_revision}.x86_64.rpm" ) +readonly WAZUH_RPM_PACKAGES="wazuh-manager-${wazuh_version}-${wazuh_revision}.x86_64.rpm" readonly FILEBEAT_RPM_BASE_URL="${BASE_URL}/yum" -readonly FILEBEAT_RPM_PACKAGES=( "filebeat-oss-${filebeat_version}-x86_64.rpm" ) +readonly FILEBEAT_RPM_PACKAGES="filebeat-oss-${filebeat_version}-x86_64.rpm" readonly INDEXER_RPM_BASE_URL="${BASE_URL}/yum" -readonly INDEXER_RPM_PACKAGES=( "wazuh-indexer-${wazuh_version}-${wazuh_revision}.x86_64.rpm" ) +readonly INDEXER_RPM_PACKAGES="wazuh-indexer-${wazuh_version}-${wazuh_revision}.x86_64.rpm" readonly DASHBOARD_RPM_BASE_URL="${BASE_URL}/yum" -readonly DASHBOARD_RPM_PACKAGES=( "wazuh-dashboard-${wazuh_version}-${wazuh_revision}.x86_64.rpm" ) +readonly DASHBOARD_RPM_PACKAGES="wazuh-dashboard-${wazuh_version}-${wazuh_revision}.x86_64.rpm" \ No newline at end of file diff --git a/unattended_installer/install_functions/wazuh-offline-download.sh b/unattended_installer/install_functions/wazuh-offline-download.sh index 97046ed901..ccc9b5bb50 100755 --- a/unattended_installer/install_functions/wazuh-offline-download.sh +++ b/unattended_installer/install_functions/wazuh-offline-download.sh @@ -16,53 +16,56 @@ function offline_download() { DEST_PATH="${BASE_DEST_FOLDER}/wazuh-packages" - mkdir -p ${DEST_PATH} # Create folder if it does not exist - - rm -f ${VERBOSE} ${DEST_PATH}/* # Clean folder before downloading specific versions + if [ -d ${DEST_PATH} ]; then + eval "rm -f ${VERBOSE} ${DEST_PATH}/*" # Clean folder before downloading specific versions + eval "chmod 700 ${DEST_PATH}" + else + eval "mkdir -m700 -p ${DEST_PATH}" # Create folder if it does not exist + fi case "${package_type}" in "deb") for p in ${WAZUH_DEB_PACKAGES[@]}; do # Download packages for Wazuh - curl -so ${DEST_PATH}/$p ${WAZUH_DEB_BASE_URL}/$p + eval "curl -so ${DEST_PATH}/$p ${WAZUH_DEB_BASE_URL}/$p" common_logger "Wazuh deb package downloaded" done for p in ${FILEBEAT_DEB_PACKAGES[@]}; do # Download packages for Filebeat - curl -so ${DEST_PATH}/$p ${FILEBEAT_DEB_BASE_URL}/$p + eval "curl -so ${DEST_PATH}/$p ${FILEBEAT_DEB_BASE_URL}/$p" common_logger "Filebeat deb package downloaded" done for p in ${INDEXER_DEB_PACKAGES[@]}; do # Download packages for Wazuh Indexer - curl -so ${DEST_PATH}/$p ${INDEXER_DEB_BASE_URL}/$p + eval "curl -so ${DEST_PATH}/$p ${INDEXER_DEB_BASE_URL}/$p" common_logger "Wazuh Indexer deb package downloaded" done for p in ${DASHBOARD_DEB_PACKAGES[@]}; do # Download packages for Wazuh Dashboard - curl -so ${DEST_PATH}/$p ${DASHBOARD_DEB_BASE_URL}/$p + eval "curl -so ${DEST_PATH}/$p ${DASHBOARD_DEB_BASE_URL}/$p" common_logger "Wazuh Dashboard deb package downloaded" done ;; "rpm") for p in ${WAZUH_RPM_PACKAGES[@]}; do # Download packages for Wazuh - curl -so ${DEST_PATH}/$p ${WAZUH_RPM_BASE_URL}/$p + eval "curl -so ${DEST_PATH}/$p ${WAZUH_RPM_BASE_URL}/$p" common_logger "Wazuh rpm package downloaded" done for p in ${FILEBEAT_RPM_PACKAGES[@]}; do # Download packages for Filebeat - curl -so ${DEST_PATH}/$p ${FILEBEAT_RPM_BASE_URL}/$p + eval "curl -so ${DEST_PATH}/$p ${FILEBEAT_RPM_BASE_URL}/$p" common_logger "Filebeat rpm package downloaded" done for p in ${INDEXER_RPM_PACKAGES[@]}; do # Download packages for Wazuh Indexer - curl -so ${DEST_PATH}/$p ${INDEXER_RPM_BASE_URL}/$p + eval "curl -so ${DEST_PATH}/$p ${INDEXER_RPM_BASE_URL}/$p" common_logger "Wazuh Indexer rpm package downloaded" done for p in ${DASHBOARD_RPM_PACKAGES[@]}; do # Download packages for Wazuh Dashboard - curl -so ${DEST_PATH}/$p ${DASHBOARD_RPM_BASE_URL}/$p + eval "curl -so ${DEST_PATH}/$p ${DASHBOARD_RPM_BASE_URL}/$p" common_logger "Wazuh Dashboard rpm package downloaded" done ;; @@ -78,20 +81,29 @@ function offline_download() { DEST_PATH="${BASE_DEST_FOLDER}/wazuh-files" - mkdir -p ${DEST_PATH} # Create folder if it does not exist + if [ -d ${DEST_PATH} ]; then + eval "rm -f ${VERBOSE} ${DEST_PATH}/*" # Clean folder before downloading specific versions + eval "chmod 700 ${DEST_PATH}" + else + eval "mkdir -m700 -p ${DEST_PATH}" # Create folder if it does not exist + fi - rm -f ${VERBOSE} ${DEST_PATH}/* # Clean folder before downloading specific versions + eval "curl -so ${DEST_PATH}/GPG-KEY-WAZUH https://packages.wazuh.com/key/GPG-KEY-WAZUH" - curl -so ${DEST_PATH}/GPG-KEY-WAZUH https://packages.wazuh.com/key/GPG-KEY-WAZUH + eval "curl -so ${DEST_PATH}/filebeat.yml ${resources}/tpl/wazuh/filebeat/filebeat.yml" - curl -so ${DEST_PATH}/filebeat.yml ${resources}/tpl/wazuh/filebeat/filebeat.yml + eval "curl -so ${DEST_PATH}/wazuh-template.json https://raw.githubusercontent.com/wazuh/wazuh/${wazuh_major}/extensions/elasticsearch/7.x/wazuh-template.json" - curl -so ${DEST_PATH}/wazuh-template.json https://raw.githubusercontent.com/wazuh/wazuh/${wazuh_major}/extensions/elasticsearch/7.x/wazuh-template.json + eval "curl -so ${DEST_PATH}/wazuh-filebeat-module.tar.gz ${BASE_URL}/filebeat/wazuh-filebeat-0.1.tar.gz" - curl -so ${DEST_PATH}/wazuh-filebeat-module.tar.gz ${BASE_URL}/filebeat/wazuh-filebeat-0.1.tar.gz + eval "chmod 500 ${BASE_DEST_FOLDER}" common_logger "The Configuration Files are in ${DEST_PATH}" + eval "tar -czf ${BASE_DEST_FOLDER}.tar.gz ${BASE_DEST_FOLDER}" + + eval "chmod -R 700 ${BASE_DEST_FOLDER} && rm -rf ${BASE_DEST_FOLDER}" + common_logger "You can follow the installation guide here https://documentation.wazuh.com/current/installation-guide/more-installation-alternatives/offline-installation.html" } \ No newline at end of file From c77ab55116808ccdcf6cf654fabe4a17aeed1664 Mon Sep 17 00:00:00 2001 From: c-bordon Date: Tue, 19 Apr 2022 16:20:35 -0300 Subject: [PATCH 4/7] PR changes --- .../common_functions/common.sh | 12 ++-- .../install_functions/installMain.sh | 21 +++--- .../install_functions/installVariables.sh | 36 +++++----- .../wazuh-offline-download.sh | 71 +++++++------------ 4 files changed, 59 insertions(+), 81 deletions(-) diff --git a/unattended_installer/common_functions/common.sh b/unattended_installer/common_functions/common.sh index fa3ffb57a7..c1b8b21af2 100644 --- a/unattended_installer/common_functions/common.sh +++ b/unattended_installer/common_functions/common.sh @@ -36,13 +36,11 @@ function common_logger() { done fi - if [ "$EUID" -eq 0 ]; then - if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then - printf "${now} ${mtype} ${message}\n" | tee -a ${logfile} - fi - else - if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then - printf "${now} ${mtype} ${message}\n" + if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then + if [ "$EUID" -eq 0 ]; then + printf "${now} ${mtype} ${message}\n" | tee -a ${logfile} + else + printf "${now} ${mtype} ${message}\n" fi fi diff --git a/unattended_installer/install_functions/installMain.sh b/unattended_installer/install_functions/installMain.sh index ea9f757eb7..2d8e48085d 100755 --- a/unattended_installer/install_functions/installMain.sh +++ b/unattended_installer/install_functions/installMain.sh @@ -78,12 +78,20 @@ function main() { getHelp fi + arguments=( $@ ) + for a in ${arguments[@]}; do + if [ "${a}" != "-dw" ] && [ "${a}" != "--download-wazuh" ] && [ "${a}" != "-V" ] && [ "${a}" != "-h" ]; then + if [[ "${a}" == -* ]]; then + common_checkRoot + fi + fi + done + while [ -n "${1}" ] do case "${1}" in "-a"|"--all-in-one") AIO=1 - common_checkRoot shift 1 ;; "-ds"|"--disable-spinner") @@ -91,7 +99,6 @@ function main() { shift 1 ;; "-c"|"--configfile") - common_checkRoot if [ -z "${2}" ]; then common_logger -e "Error on arguments. Probably missing after -c|--configfile" getHelp @@ -102,12 +109,10 @@ function main() { shift 2 ;; "-F"|"--force-dashboard") - common_checkRoot force=1 shift 1 ;; "-g"|"--generate-configurations") - common_checkRoot configurations=1 shift 1 ;; @@ -115,22 +120,18 @@ function main() { getHelp ;; "-i"|"--ignore-check") - common_checkRoot ignore=1 shift 1 ;; "-o"|"--overwrite") - common_checkRoot overwrite=1 shift 1 ;; "-s"|"--start-cluster") - common_checkRoot start_indexer_cluster=1 shift 1 ;; "-t"|"--tar") - common_checkRoot if [ -z "${2}" ]; then common_logger -e "Error on arguments. Probably missing after -t|--tar" getHelp @@ -141,7 +142,6 @@ function main() { shift 2 ;; "-u"|"--uninstall") - common_checkRoot uninstall=1 shift 1 ;; @@ -155,7 +155,6 @@ function main() { shift 1 ;; "-wd"|"--wazuh-dashboard") - common_checkRoot if [ -z "${2}" ]; then common_logger -e "Error on arguments. Probably missing after -wd|---wazuh-dashboard" getHelp @@ -166,7 +165,6 @@ function main() { shift 2 ;; "-wi"|"--wazuh-indexer") - common_checkRoot if [ -z "${2}" ]; then common_logger -e "Arguments contain errors. Probably missing after -wi|--wazuh-indexer." getHelp @@ -177,7 +175,6 @@ function main() { shift 2 ;; "-ws"|"--wazuh-server") - common_checkRoot if [ -z "${2}" ]; then common_logger -e "Error on arguments. Probably missing after -ws|--wazuh-server" getHelp diff --git a/unattended_installer/install_functions/installVariables.sh b/unattended_installer/install_functions/installVariables.sh index 37090af98c..7ee88479ae 100644 --- a/unattended_installer/install_functions/installVariables.sh +++ b/unattended_installer/install_functions/installVariables.sh @@ -17,7 +17,7 @@ readonly repository="pre-release" #use 4.x for production ## Links and paths to resources readonly resources="https://${bucket}/${wazuh_major}" -readonly BASE_URL="https://${bucket}/${repository}" +readonly base_url="https://${bucket}/${repository}" readonly base_path="$(dirname $(readlink -f "$0"))" config_file="${base_path}/config.yml" readonly tar_file_name="wazuh-install-files.tar" @@ -33,20 +33,20 @@ readonly logfile="/var/log/wazuh-install.log" debug=">> ${logfile} 2>&1" ## Offline Installation vars -readonly BASE_DEST_FOLDER="wazuh-offline" -readonly WAZUH_DEB_BASE_URL="${BASE_URL}/apt/pool/main/w/wazuh-manager" -readonly WAZUH_DEB_PACKAGES="wazuh-manager_${wazuh_version}-${wazuh_revision}_amd64.deb" -readonly FILEBEAT_DEB_BASE_URL="${BASE_URL}/apt/pool/main/f/filebeat" -readonly FILEBEAT_DEB_PACKAGES="filebeat-oss-${filebeat_version}-amd64.deb" -readonly INDEXER_DEB_BASE_URL="${BASE_URL}/apt/pool/main/w/wazuh-indexer" -readonly INDEXER_DEB_PACKAGES="wazuh-indexer_${wazuh_version}-${wazuh_revision}_amd64.deb" -readonly DASHBOARD_DEB_BASE_URL="${BASE_URL}/apt/pool/main/w/wazuh-dashboard" -readonly DASHBOARD_DEB_PACKAGES="wazuh-dashboard_${wazuh_version}-${wazuh_revision}_amd64.deb" -readonly WAZUH_RPM_BASE_URL="${BASE_URL}/yum" -readonly WAZUH_RPM_PACKAGES="wazuh-manager-${wazuh_version}-${wazuh_revision}.x86_64.rpm" -readonly FILEBEAT_RPM_BASE_URL="${BASE_URL}/yum" -readonly FILEBEAT_RPM_PACKAGES="filebeat-oss-${filebeat_version}-x86_64.rpm" -readonly INDEXER_RPM_BASE_URL="${BASE_URL}/yum" -readonly INDEXER_RPM_PACKAGES="wazuh-indexer-${wazuh_version}-${wazuh_revision}.x86_64.rpm" -readonly DASHBOARD_RPM_BASE_URL="${BASE_URL}/yum" -readonly DASHBOARD_RPM_PACKAGES="wazuh-dashboard-${wazuh_version}-${wazuh_revision}.x86_64.rpm" \ No newline at end of file +readonly base_dest_folder="wazuh-offline" +readonly manager_deb_base_url="${base_url}/apt/pool/main/w/wazuh-manager" +readonly manager_deb_package="wazuh-manager_${wazuh_version}-${wazuh_revision}_amd64.deb" +readonly filebeat_deb_base_url="${base_url}/apt/pool/main/f/filebeat" +readonly filebeat_deb_package="filebeat-oss-${filebeat_version}-amd64.deb" +readonly indexer_deb_base_url="${base_url}/apt/pool/main/w/wazuh-indexer" +readonly indexer_deb_package="wazuh-indexer_${wazuh_version}-${wazuh_revision}_amd64.deb" +readonly dashboard_deb_base_url="${base_url}/apt/pool/main/w/wazuh-dashboard" +readonly dashboard_deb_package="wazuh-dashboard_${wazuh_version}-${wazuh_revision}_amd64.deb" +readonly manager_rpm_base_url="${base_url}/yum" +readonly manager_rpm_package="wazuh-manager-${wazuh_version}-${wazuh_revision}.x86_64.rpm" +readonly filebeat_rpm_base_url="${base_url}/yum" +readonly filebeat_rpm_package="filebeat-oss-${filebeat_version}-x86_64.rpm" +readonly indexer_rpm_base_url="${base_url}/yum" +readonly indexer_rpm_package="wazuh-indexer-${wazuh_version}-${wazuh_revision}.x86_64.rpm" +readonly dashboard_rpm_base_url="${base_url}/yum" +readonly dashboard_rpm_package="wazuh-dashboard-${wazuh_version}-${wazuh_revision}.x86_64.rpm" \ No newline at end of file diff --git a/unattended_installer/install_functions/wazuh-offline-download.sh b/unattended_installer/install_functions/wazuh-offline-download.sh index ccc9b5bb50..7bfd824740 100755 --- a/unattended_installer/install_functions/wazuh-offline-download.sh +++ b/unattended_installer/install_functions/wazuh-offline-download.sh @@ -14,60 +14,43 @@ function offline_download() { common_logger "Downloading Wazuh ${package_type} packages for ${arch}..." - DEST_PATH="${BASE_DEST_FOLDER}/wazuh-packages" + dest_path="${base_dest_folder}/wazuh-packages" - if [ -d ${DEST_PATH} ]; then - eval "rm -f ${VERBOSE} ${DEST_PATH}/*" # Clean folder before downloading specific versions - eval "chmod 700 ${DEST_PATH}" + if [ -d ${dest_path} ]; then + eval "rm -f ${dest_path}/*" # Clean folder before downloading specific versions + eval "chmod 700 ${dest_path}" else - eval "mkdir -m700 -p ${DEST_PATH}" # Create folder if it does not exist + eval "mkdir -m700 -p ${dest_path}" # Create folder if it does not exist fi case "${package_type}" in "deb") - for p in ${WAZUH_DEB_PACKAGES[@]}; do # Download packages for Wazuh - eval "curl -so ${DEST_PATH}/$p ${WAZUH_DEB_BASE_URL}/$p" + eval "curl -so ${dest_path}/${manager_deb_package} ${wazuh_deb_base_url}/${manager_deb_package}" common_logger "Wazuh deb package downloaded" - done - - for p in ${FILEBEAT_DEB_PACKAGES[@]}; do # Download packages for Filebeat - eval "curl -so ${DEST_PATH}/$p ${FILEBEAT_DEB_BASE_URL}/$p" + eval "curl -so ${dest_path}/${filebeat_deb_package} ${filebeat_deb_base_url}/${filebeat_deb_package}" common_logger "Filebeat deb package downloaded" - done - for p in ${INDEXER_DEB_PACKAGES[@]}; do # Download packages for Wazuh Indexer - eval "curl -so ${DEST_PATH}/$p ${INDEXER_DEB_BASE_URL}/$p" + eval "curl -so ${dest_path}/${indexer_deb_package} ${indexer_deb_base_url}/${indexer_deb_package}" common_logger "Wazuh Indexer deb package downloaded" - done - for p in ${DASHBOARD_DEB_PACKAGES[@]}; do # Download packages for Wazuh Dashboard - eval "curl -so ${DEST_PATH}/$p ${DASHBOARD_DEB_BASE_URL}/$p" + eval "curl -so ${dest_path}/${dashboard_deb_package} ${dashboard_deb_base_url}/${dashboard_deb_package}" common_logger "Wazuh Dashboard deb package downloaded" - done ;; "rpm") - for p in ${WAZUH_RPM_PACKAGES[@]}; do # Download packages for Wazuh - eval "curl -so ${DEST_PATH}/$p ${WAZUH_RPM_BASE_URL}/$p" + eval "curl -so ${dest_path}/${manager_rpm_package} ${wazuh_rpm_base_url}/${manager_rpm_package}" common_logger "Wazuh rpm package downloaded" - done - for p in ${FILEBEAT_RPM_PACKAGES[@]}; do # Download packages for Filebeat - eval "curl -so ${DEST_PATH}/$p ${FILEBEAT_RPM_BASE_URL}/$p" + eval "curl -so ${dest_path}/${filebeat_rpm_package} ${filebeat_rpm_base_url}/${filebeat_rpm_package}" common_logger "Filebeat rpm package downloaded" - done - for p in ${INDEXER_RPM_PACKAGES[@]}; do # Download packages for Wazuh Indexer - eval "curl -so ${DEST_PATH}/$p ${INDEXER_RPM_BASE_URL}/$p" + eval "curl -so ${dest_path}/${indexer_rpm_package} ${indexer_rpm_base_url}/${indexer_rpm_package}" common_logger "Wazuh Indexer rpm package downloaded" - done - for p in ${DASHBOARD_RPM_PACKAGES[@]}; do # Download packages for Wazuh Dashboard - eval "curl -so ${DEST_PATH}/$p ${DASHBOARD_RPM_BASE_URL}/$p" + eval "curl -so ${dest_path}/${dashboard_rpm_package} ${dashboard_rpm_base_url}/${dashboard_rpm_package}" common_logger "Wazuh Dashboard rpm package downloaded" - done ;; *) print_unknown_args @@ -75,34 +58,34 @@ function offline_download() { ;; esac - common_logger "The packages are in ${DEST_PATH}" + common_logger "The packages are in ${dest_path}" common_logger "Downloading Configuration Files" - DEST_PATH="${BASE_DEST_FOLDER}/wazuh-files" + dest_path="${base_dest_folder}/wazuh-files" - if [ -d ${DEST_PATH} ]; then - eval "rm -f ${VERBOSE} ${DEST_PATH}/*" # Clean folder before downloading specific versions - eval "chmod 700 ${DEST_PATH}" + if [ -d ${dest_path} ]; then + eval "rm -f ${dest_path}/*" # Clean folder before downloading specific versions + eval "chmod 700 ${dest_path}" else - eval "mkdir -m700 -p ${DEST_PATH}" # Create folder if it does not exist + eval "mkdir -m700 -p ${dest_path}" # Create folder if it does not exist fi - eval "curl -so ${DEST_PATH}/GPG-KEY-WAZUH https://packages.wazuh.com/key/GPG-KEY-WAZUH" + eval "curl -so ${dest_path}/GPG-KEY-WAZUH https://packages.wazuh.com/key/GPG-KEY-WAZUH" - eval "curl -so ${DEST_PATH}/filebeat.yml ${resources}/tpl/wazuh/filebeat/filebeat.yml" + eval "curl -so ${dest_path}/filebeat.yml ${resources}/tpl/wazuh/filebeat/filebeat.yml" - eval "curl -so ${DEST_PATH}/wazuh-template.json https://raw.githubusercontent.com/wazuh/wazuh/${wazuh_major}/extensions/elasticsearch/7.x/wazuh-template.json" + eval "curl -so ${dest_path}/wazuh-template.json https://raw.githubusercontent.com/wazuh/wazuh/${wazuh_major}/extensions/elasticsearch/7.x/wazuh-template.json" - eval "curl -so ${DEST_PATH}/wazuh-filebeat-module.tar.gz ${BASE_URL}/filebeat/wazuh-filebeat-0.1.tar.gz" + eval "curl -so ${dest_path}/wazuh-filebeat-module.tar.gz ${base_url}/filebeat/wazuh-filebeat-0.1.tar.gz" - eval "chmod 500 ${BASE_DEST_FOLDER}" + eval "chmod 500 ${base_dest_folder}" - common_logger "The Configuration Files are in ${DEST_PATH}" + common_logger "The Configuration Files are in ${dest_path}" - eval "tar -czf ${BASE_DEST_FOLDER}.tar.gz ${BASE_DEST_FOLDER}" + eval "tar -czf ${base_dest_folder}.tar.gz ${base_dest_folder}" - eval "chmod -R 700 ${BASE_DEST_FOLDER} && rm -rf ${BASE_DEST_FOLDER}" + eval "chmod -R 700 ${base_dest_folder} && rm -rf ${base_dest_folder}" common_logger "You can follow the installation guide here https://documentation.wazuh.com/current/installation-guide/more-installation-alternatives/offline-installation.html" From 838c250b05ae81dcc2080c7fe063070c4e34bbf7 Mon Sep 17 00:00:00 2001 From: c-bordon Date: Tue, 19 Apr 2022 17:08:14 -0300 Subject: [PATCH 5/7] Replace a variable with args --- unattended_installer/install_functions/installMain.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unattended_installer/install_functions/installMain.sh b/unattended_installer/install_functions/installMain.sh index 2d8e48085d..0e4944b3dc 100755 --- a/unattended_installer/install_functions/installMain.sh +++ b/unattended_installer/install_functions/installMain.sh @@ -79,9 +79,9 @@ function main() { fi arguments=( $@ ) - for a in ${arguments[@]}; do - if [ "${a}" != "-dw" ] && [ "${a}" != "--download-wazuh" ] && [ "${a}" != "-V" ] && [ "${a}" != "-h" ]; then - if [[ "${a}" == -* ]]; then + for args in ${arguments[@]}; do + if [ "${args}" != "-dw" ] && [ "${args}" != "--download-wazuh" ] && [ "${args}" != "-V" ] && [ "${args}" != "-h" ]; then + if [[ "${args}" == -* ]]; then common_checkRoot fi fi From 1bd4fa38c6f5f86c9fefbb278fc1273d6b09bdab Mon Sep 17 00:00:00 2001 From: Alberto R Date: Wed, 20 Apr 2022 12:18:14 +0200 Subject: [PATCH 6/7] Improved how to download offline assets --- .../wazuh-offline-download.sh | 83 +++++++++---------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/unattended_installer/install_functions/wazuh-offline-download.sh b/unattended_installer/install_functions/wazuh-offline-download.sh index 7bfd824740..36ec35bb92 100755 --- a/unattended_installer/install_functions/wazuh-offline-download.sh +++ b/unattended_installer/install_functions/wazuh-offline-download.sh @@ -1,7 +1,7 @@ #!/bin/bash # Wazuh installer: offline download -# Copyright (C) 2015-2021, Wazuh Inc. +# Copyright (C) 2021, Wazuh Inc. # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public @@ -11,9 +11,7 @@ function offline_download() { common_logger "Starting Wazuh packages download." - - common_logger "Downloading Wazuh ${package_type} packages for ${arch}..." - + common_logger "Downloading Wazuh ${package_type} packages for ${arch}." dest_path="${base_dest_folder}/wazuh-packages" if [ -d ${dest_path} ]; then @@ -23,45 +21,29 @@ function offline_download() { eval "mkdir -m700 -p ${dest_path}" # Create folder if it does not exist fi - case "${package_type}" in - "deb") - # Download packages for Wazuh - eval "curl -so ${dest_path}/${manager_deb_package} ${wazuh_deb_base_url}/${manager_deb_package}" - common_logger "Wazuh deb package downloaded" - # Download packages for Filebeat - eval "curl -so ${dest_path}/${filebeat_deb_package} ${filebeat_deb_base_url}/${filebeat_deb_package}" - common_logger "Filebeat deb package downloaded" - # Download packages for Wazuh Indexer - eval "curl -so ${dest_path}/${indexer_deb_package} ${indexer_deb_base_url}/${indexer_deb_package}" - common_logger "Wazuh Indexer deb package downloaded" - # Download packages for Wazuh Dashboard - eval "curl -so ${dest_path}/${dashboard_deb_package} ${dashboard_deb_base_url}/${dashboard_deb_package}" - common_logger "Wazuh Dashboard deb package downloaded" - ;; - "rpm") - # Download packages for Wazuh - eval "curl -so ${dest_path}/${manager_rpm_package} ${wazuh_rpm_base_url}/${manager_rpm_package}" - common_logger "Wazuh rpm package downloaded" - # Download packages for Filebeat - eval "curl -so ${dest_path}/${filebeat_rpm_package} ${filebeat_rpm_base_url}/${filebeat_rpm_package}" - common_logger "Filebeat rpm package downloaded" - # Download packages for Wazuh Indexer - eval "curl -so ${dest_path}/${indexer_rpm_package} ${indexer_rpm_base_url}/${indexer_rpm_package}" - common_logger "Wazuh Indexer rpm package downloaded" - # Download packages for Wazuh Dashboard - eval "curl -so ${dest_path}/${dashboard_rpm_package} ${dashboard_rpm_base_url}/${dashboard_rpm_package}" - common_logger "Wazuh Dashboard rpm package downloaded" - ;; - *) - print_unknown_args - exit 0 - ;; - esac + packages_to_download=( "manager" "filebeat" "indexer" "dashboard" ) + + for package in "${packages_to_download[@]}" + do + + package_name="${package}_${package_type}_package" + eval "package_base_url="${package}_${package_type}_base_url"" + + eval "curl -so ${dest_path}/${package_name} ${package_base_url}/${package_name}" + if [ "$?" != 0 ]; then + common_logger -e "The ${package} package could not be downloaded. Exiting." + exit 1 + else + common_logger "The ${package} package was downloaded." + fi + + done common_logger "The packages are in ${dest_path}" - common_logger "Downloading Configuration Files" +# -------------------------------------------------- + common_logger "Downloading configuration files and assets." dest_path="${base_dest_folder}/wazuh-files" if [ -d ${dest_path} ]; then @@ -71,20 +53,31 @@ function offline_download() { eval "mkdir -m700 -p ${dest_path}" # Create folder if it does not exist fi - eval "curl -so ${dest_path}/GPG-KEY-WAZUH https://packages.wazuh.com/key/GPG-KEY-WAZUH" + files_to_download=( "https://packages.wazuh.com/key/GPG-KEY-WAZUH" + "${resources}/tpl/wazuh/filebeat/filebeat.yml" + "https://raw.githubusercontent.com/wazuh/wazuh/${wazuh_major}/extensions/elasticsearch/7.x/wazuh-template.json" + "${base_url}/filebeat/wazuh-filebeat-0.1.tar.gz" ) - eval "curl -so ${dest_path}/filebeat.yml ${resources}/tpl/wazuh/filebeat/filebeat.yml" + cd ${dest_path} + for file in "${files_to_download[@]}" + do - eval "curl -so ${dest_path}/wazuh-template.json https://raw.githubusercontent.com/wazuh/wazuh/${wazuh_major}/extensions/elasticsearch/7.x/wazuh-template.json" + eval "curl -sO ${files_to_download}" + if [ "$?" != 0 ]; then + common_logger -e "The resource ${files_to_download} could not be downloaded. Exiting." + exit 1 + else + common_logger "The resource ${files_to_download} was downloaded." + fi - eval "curl -so ${dest_path}/wazuh-filebeat-module.tar.gz ${base_url}/filebeat/wazuh-filebeat-0.1.tar.gz" + done + cd - eval "chmod 500 ${base_dest_folder}" - common_logger "The Configuration Files are in ${dest_path}" + common_logger "The configuration files and assets are in ${dest_path}" eval "tar -czf ${base_dest_folder}.tar.gz ${base_dest_folder}" - eval "chmod -R 700 ${base_dest_folder} && rm -rf ${base_dest_folder}" common_logger "You can follow the installation guide here https://documentation.wazuh.com/current/installation-guide/more-installation-alternatives/offline-installation.html" From 4786602daeea2c5f6d04769f24f6e16fc4a28740 Mon Sep 17 00:00:00 2001 From: c-bordon Date: Wed, 20 Apr 2022 09:02:28 -0300 Subject: [PATCH 7/7] Fix some Downloads errors and changed variables --- .../install_functions/installVariables.sh | 4 +++- .../wazuh-offline-download.sh | 19 ++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/unattended_installer/install_functions/installVariables.sh b/unattended_installer/install_functions/installVariables.sh index 7ee88479ae..2eaa510d33 100644 --- a/unattended_installer/install_functions/installVariables.sh +++ b/unattended_installer/install_functions/installVariables.sh @@ -49,4 +49,6 @@ readonly filebeat_rpm_package="filebeat-oss-${filebeat_version}-x86_64.rpm" readonly indexer_rpm_base_url="${base_url}/yum" readonly indexer_rpm_package="wazuh-indexer-${wazuh_version}-${wazuh_revision}.x86_64.rpm" readonly dashboard_rpm_base_url="${base_url}/yum" -readonly dashboard_rpm_package="wazuh-dashboard-${wazuh_version}-${wazuh_revision}.x86_64.rpm" \ No newline at end of file +readonly dashboard_rpm_package="wazuh-dashboard-${wazuh_version}-${wazuh_revision}.x86_64.rpm" +readonly wazuh_gpg_key="https://${bucket}/key/GPG-KEY-WAZUH" +readonly filebeat_config_file="${resources}/tpl/wazuh/filebeat/filebeat.yml" \ No newline at end of file diff --git a/unattended_installer/install_functions/wazuh-offline-download.sh b/unattended_installer/install_functions/wazuh-offline-download.sh index 36ec35bb92..389382dfcc 100755 --- a/unattended_installer/install_functions/wazuh-offline-download.sh +++ b/unattended_installer/install_functions/wazuh-offline-download.sh @@ -27,9 +27,9 @@ function offline_download() { do package_name="${package}_${package_type}_package" - eval "package_base_url="${package}_${package_type}_base_url"" + eval "package_base_url=${package}_${package_type}_base_url" - eval "curl -so ${dest_path}/${package_name} ${package_base_url}/${package_name}" + eval "curl -so ${dest_path}/${!package_name} ${!package_base_url}/${!package_name}" if [ "$?" != 0 ]; then common_logger -e "The ${package} package could not be downloaded. Exiting." exit 1 @@ -53,25 +53,22 @@ function offline_download() { eval "mkdir -m700 -p ${dest_path}" # Create folder if it does not exist fi - files_to_download=( "https://packages.wazuh.com/key/GPG-KEY-WAZUH" - "${resources}/tpl/wazuh/filebeat/filebeat.yml" - "https://raw.githubusercontent.com/wazuh/wazuh/${wazuh_major}/extensions/elasticsearch/7.x/wazuh-template.json" - "${base_url}/filebeat/wazuh-filebeat-0.1.tar.gz" ) + files_to_download=( ${wazuh_gpg_key} ${filebeat_config_file} ${filebeat_wazuh_template} ${filebeat_wazuh_module} ) - cd ${dest_path} + eval "cd ${dest_path}" for file in "${files_to_download[@]}" do - eval "curl -sO ${files_to_download}" + eval "curl -sO ${file}" if [ "$?" != 0 ]; then - common_logger -e "The resource ${files_to_download} could not be downloaded. Exiting." + common_logger -e "The resource ${file} could not be downloaded. Exiting." exit 1 else - common_logger "The resource ${files_to_download} was downloaded." + common_logger "The resource ${file} was downloaded." fi done - cd - + eval "cd - > /dev/null" eval "chmod 500 ${base_dest_folder}"