Skip to content

Commit

Permalink
chore: config
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-segning committed Sep 29, 2024
1 parent f806e41 commit d0b077f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
8 changes: 4 additions & 4 deletions scripts/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ case "$OS_NAME" in
if command_exists apt-get; then
info_message "Detected Debian/Ubuntu-based system"
maybe_sudo apt-get update
maybe_sudo apt-get install -y curl jq
maybe_sudo apt-get install -y curl jq gnu-sed
elif command_exists yum; then
info_message "Detected Red Hat/CentOS-based system"
maybe_sudo yum install -y curl jq
maybe_sudo yum install -y curl jq gnu-sed
elif command_exists apk; then
info_message "Detected Alpine Linux system"
maybe_sudo apk add --no-cache curl jq
maybe_sudo apk add --no-cache curl jq gnu-sed
else
error_message "Unsupported Linux distribution"
exit 1
Expand All @@ -85,7 +85,7 @@ case "$OS_NAME" in
"Darwin")
info_message "Detected macOS"
if command_exists brew; then
brew install curl jq
brew install curl jq gnu-sed
else
error_message "Homebrew is not installed. Please install Homebrew first."
exit 1
Expand Down
78 changes: 43 additions & 35 deletions scripts/setup-agent.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/sh
#!/bin/bash

# Check if we're running in bash; if not, adjust behavior
if [ -n "$BASH_VERSION" ]; then
set -euo pipefail
else
set -eu
fi

# Default log level and application details
LOG_LEVEL=${LOG_LEVEL:-"INFO"}
Expand All @@ -17,8 +24,11 @@ USER=${USER:-"root"}
GROUP=${GROUP:-"wazuh"}

WAZUH_MANAGER=${WAZUH_MANAGER:-'master.wazuh.adorsys.team'}
WAZUH_AGENT_VERSION=${WAZUH_AGENT_VERSION:-'4.8.2-1'}
WAZUH_AGENT_VERSION=${WAZUH_AGENT_VERSION:-'4.8.1-1'}
WAZUH_AGENT_NAME=${WAZUH_AGENT_NAME:-}

TMP_FOLDER="$(mktemp -d)"

# Define text formatting
RED='\033[0;31m'
GREEN='\033[0;32m'
Expand Down Expand Up @@ -46,58 +56,56 @@ error_message() {
log "${RED}${BOLD}[ERROR]${NORMAL}" "$*"
}

# Step 0: Ensure Curl and JQ are installed
info_message "Ensuring dependencies are installed"
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-agent/main/scripts/deps.sh | sudo bash) 2>&1; then
error_message "Failed to ensure deps"
cleanup() {
# Remove temporary folder
if [ -d "$TMP_FOLDER" ]; then
rm -rf "$TMP_FOLDER"
fi
}

trap cleanup EXIT

info_message "Starting setup. Using temporary directory: \"$TMP_FOLDER\""

# Step -1: Download all scripts
info_message "Download all scripts..."
curl -SL -s https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-agent/main/scripts/deps.sh > "$TMP_FOLDER/deps.sh"
curl -SL -s https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-agent/main/scripts/install.sh > "$TMP_FOLDER/install-wazuh-agent.sh"
curl -SL -s https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-cert-oauth2/main/scripts/install.sh > "$TMP_FOLDER/install-wazuh-cert-oauth2.sh"
curl -SL -s https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-yara/main/scripts/install.sh > "$TMP_FOLDER/install-yara.sh"
curl -SL -s https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-snort/main/scripts/install.sh > "$TMP_FOLDER/install-snort.sh"

# Step 0: Install dependencies
info_message "Install dependencies"
if ! (sudo env bash "$TMP_FOLDER/deps.sh") 2>&1; then
error_message "Failed to install dependencies"
exit 1
fi

# Step 1: Download and install Wazuh agent
info_message "Installing Wazuh agent"
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-agent/main/scripts/install.sh | LOG_LEVEL=$LOG_LEVEL OSSEC_CONF_PATH=$OSSEC_CONF_PATH WAZUH_MANAGER=$WAZUH_MANAGER WAZUH_AGENT_VERSION=$WAZUH_AGENT_VERSION sudo bash) 2>&1; then
if ! (sudo LOG_LEVEL="$LOG_LEVEL" OSSEC_CONF_PATH=$OSSEC_CONF_PATH WAZUH_MANAGER="$WAZUH_MANAGER" WAZUH_AGENT_VERSION="$WAZUH_AGENT_VERSION" bash "$TMP_FOLDER/install-wazuh-agent.sh") 2>&1; then
error_message "Failed to install wazuh-agent"
exit 1
fi

# Step 2: Download and install wazuh-cert-oauth2-client
info_message "Installing wazuh-cert-oauth2-client"
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-cert-oauth2/main/scripts/install.sh | LOG_LEVEL=$LOG_LEVEL OSSEC_CONF_PATH=$OSSEC_CONF_PATH APP_NAME=$APP_NAME WOPS_VERSION=$WOPS_VERSION sudo sh) 2>&1; then
if ! (sudo LOG_LEVEL="$LOG_LEVEL" OSSEC_CONF_PATH=$OSSEC_CONF_PATH APP_NAME="$APP_NAME" WOPS_VERSION="$WOPS_VERSION" bash "$TMP_FOLDER/install-wazuh-cert-oauth2.sh") 2>&1; then
error_message "Failed to install 'wazuh-cert-oauth2-client'"
exit 1
fi

# Detect the operating system
OS=$(uname)

# Step 3: Download and install yara
info_message "Installing yara"
if [ "$OS" = "Darwin" ]; then
# Run without sudo for macOS
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-yara/main/scripts/install.sh | bash) 2>&1; then
error_message "Failed to install 'yara'"
exit 1
fi
else
# Run with sudo for Linux
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-yara/main/scripts/install.sh | sudo bash) 2>&1; then
error_message "Failed to install 'yara'"
exit 1
fi
if ! (sudo LOG_LEVEL="$LOG_LEVEL" OSSEC_CONF_PATH=$OSSEC_CONF_PATH bash "$TMP_FOLDER/install-yara.sh") 2>&1; then
error_message "Failed to install 'yara'"
exit 1
fi

# Step 4: Download and install snort
info_message "Installing snort"
if [ "$OS" = "Darwin" ]; then
# Run without sudo for macOS
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-snort/main/scripts/install.sh | bash) 2>&1; then
error_message "Failed to install 'snort'"
exit 1
fi
else
# Run with sudo for Linux
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-snort/main/scripts/install.sh | sudo bash) 2>&1; then
error_message "Failed to install 'snort'"
exit 1
fi
if ! (sudo LOG_LEVEL="$LOG_LEVEL" OSSEC_CONF_PATH=$OSSEC_CONF_PATH bash "$TMP_FOLDER/install-snort.sh") 2>&1; then
error_message "Failed to install 'snort'"
exit 1
fi

0 comments on commit d0b077f

Please sign in to comment.