Skip to content
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

Removing root requirement for download option from Wazuh installation assistant and other improvements #1465

Merged
merged 7 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions unattended_installer/common_functions/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ function common_logger() {
fi

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

}
Expand Down
13 changes: 10 additions & 3 deletions unattended_installer/install_functions/installMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@ function getHelp() {
function main() {
umask 177

common_checkRoot

if [ -z "${1}" ]; then
getHelp
fi

arguments=( $@ )
for args in ${arguments[@]}; do
if [ "${args}" != "-dw" ] && [ "${args}" != "--download-wazuh" ] && [ "${args}" != "-V" ] && [ "${args}" != "-h" ]; then
if [[ "${args}" == -* ]]; then
common_checkRoot
fi
fi
done

while [ -n "${1}" ]
do
case "${1}" in
Expand Down Expand Up @@ -178,7 +185,7 @@ function main() {
shift 2
;;
"-dw"|"--download-wazuh")
if [ -z "${2}" ]; then
if [ "${2}" != "deb" ] && [ "${2}" != "rpm" ]; then
common_logger -e "Error on arguments. Probably missing <deb|rpm> after -dw|--download-wazuh"
getHelp
exit 1
Expand Down
38 changes: 20 additions & 18 deletions unattended_installer/install_functions/installVariables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -33,20 +33,22 @@ 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" )
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"
readonly wazuh_gpg_key="https://${bucket}/key/GPG-KEY-WAZUH"
readonly filebeat_config_file="${resources}/tpl/wazuh/filebeat/filebeat.yml"
145 changes: 65 additions & 80 deletions unattended_installer/install_functions/wazuh-offline-download.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,86 +11,71 @@
function offline_download() {

common_logger "Starting Wazuh packages download."
common_logger "Downloading Wazuh ${package_type} packages for ${arch}."
dest_path="${base_dest_folder}/wazuh-packages"

common_logger "Downloading Wazuh ${package_type} packages for ${arch}..."

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

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
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
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
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
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
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
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
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
common_logger "Wazuh Dashboard rpm package downloaded"
done
;;
*)
print_unknown_args
exit 0
;;
esac

common_logger "The packages are in ${DEST_PATH}"

common_logger "Downloading Configuration Files"

DEST_PATH="${BASE_DEST_FOLDER}/wazuh-files"

mkdir -p ${DEST_PATH} # Create folder if it does not exist

rm -f ${VERBOSE} ${DEST_PATH}/* # Clean folder before downloading specific versions

curl -so ${DEST_PATH}/GPG-KEY-WAZUH https://packages.wazuh.com/key/GPG-KEY-WAZUH

curl -so ${DEST_PATH}/filebeat.yml ${resources}/tpl/wazuh/filebeat/filebeat.yml

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-filebeat-module.tar.gz ${BASE_URL}/filebeat/wazuh-filebeat-0.1.tar.gz

common_logger "The Configuration Files are in ${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
fi

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 and assets."
dest_path="${base_dest_folder}/wazuh-files"

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
fi

files_to_download=( ${wazuh_gpg_key} ${filebeat_config_file} ${filebeat_wazuh_template} ${filebeat_wazuh_module} )

eval "cd ${dest_path}"
for file in "${files_to_download[@]}"
do

eval "curl -sO ${file}"
if [ "$?" != 0 ]; then
common_logger -e "The resource ${file} could not be downloaded. Exiting."
exit 1
else
common_logger "The resource ${file} was downloaded."
fi

done
eval "cd - > /dev/null"

eval "chmod 500 ${base_dest_folder}"

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"

Expand Down