Skip to content

Commit

Permalink
Merge pull request #1 from ADORSYS-GIS/fix
Browse files Browse the repository at this point in the history
Fix  Issue with Repeated File Creation and Permission Management Based on Operating System
  • Loading branch information
bengo237 committed Sep 19, 2024
2 parents ef8c03c + aea0ae0 commit 8a83e04
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 18 deletions.
45 changes: 35 additions & 10 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,46 @@ installation() {
$PACKAGE_MANAGER update
WAZUH_MANAGER="$WAZUH_MANAGER" $PACKAGE_MANAGER install wazuh-agent
elif [ "$OS" = "macOS" ]; then
# Detect architecture (Intel or Apple Silicon)
ARCH=$(uname -m)
BASE_URL="https://packages.wazuh.com/4.x/macos"
PKG_NAME="wazuh-agent-4.9.0-1.${ARCH}64.pkg"
PKG_URL="$BASE_URL/$PKG_NAME"
TMP_DIR="$(mktemp)"
mkdir -p "$TMP_DIR"
if [ ! -f "$TMP_DIR/$PKG_NAME" ]; then
curl -o "$TMP_DIR/$PKG_NAME" "$PKG_URL"
info_message "Wazuh agent downloaded successfully."

if [ "$ARCH" = "x86_64" ]; then
# Intel architecture
PKG_NAME="wazuh-agent-4.9.0-1.x86_64.pkg"
elif [ "$ARCH" = "arm64" ]; then
# Apple Silicon (M1/M2)
PKG_NAME="wazuh-agent-4.9.0-1.arm64.pkg"
else
error_message "Unsupported architecture: $ARCH"
exit 1
fi

PKG_URL="$BASE_URL/$PKG_NAME"

# Create a unique temporary directory
TMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'wazuh_install')
info_message "Using temporary directory: $TMP_DIR"

# Download the correct Wazuh agent package based on architecture
curl -o "$TMP_DIR/$PKG_NAME" "$PKG_URL"
info_message "Wazuh agent downloaded successfully."

# Set environment variable for Wazuh manager
echo "WAZUH_MANAGER='$WAZUH_MANAGER'" > /tmp/wazuh_envs

# Install Wazuh agent using the package
installer -pkg "$TMP_DIR/$PKG_NAME" -target /

# Clean up the temporary directory after installation
rm -rf "$TMP_DIR"
info_message "Temporary directory cleaned up."
fi
info_message "Wazuh agent installed successfully."
}



disable_repo() {
# Disable Wazuh repository after installation for Linux
if [ "$OS" = "Linux" ]; then
Expand Down Expand Up @@ -174,10 +198,11 @@ start_agent() {
info_message "Wazuh agent started successfully."
}


# Main execution
import_keys
installation
# disable_repo
disable_repo
config
start_agent
start_agent

# End of script
45 changes: 37 additions & 8 deletions scripts/setup-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
LOG_LEVEL=${LOG_LEVEL:-"INFO"}
APP_NAME=${APP_NAME:-"wazuh-cert-oauth2-client"}
WOPS_VERSION=${WOPS_VERSION:-"0.2.1"}
OSSEC_CONF_PATH=${OSSEC_CONF_PATH:-"/var/ossec/etc/ossec.conf"}
# Define the OSSEC configuration path
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
OSSEC_CONF_PATH="/Library/Ossec/etc/ossec.conf"
else
# Linux
OSSEC_CONF_PATH="/var/ossec/etc/ossec.conf"
fi

USER=${USER:-"root"}
GROUP=${GROUP:-"wazuh"}

Expand Down Expand Up @@ -59,16 +67,37 @@ if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazu
exit 1
fi

# Detect the operating system
OS=$(uname)

# Step 3: Download and install yara
info_message "Installing yara"
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
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
fi

# Step 4: Download and install snort
info_message "Installing snort"
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 [ "$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
fi

0 comments on commit 8a83e04

Please sign in to comment.