Skip to content

Commit

Permalink
chore: custom sed
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-segning committed Aug 15, 2024
1 parent 0655cab commit 1fdb6d5
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ print_step() {
log INFO "------ Step $step : $message ------"
}

custom_sed() {
local pattern="$1"
local file="$2"
local tmp_file="$TMP_DIR/$(basename "$file")"

if [ "$(uname)" = "Linux" ]; then
maybe_sudo sed -e -i "$pattern" "$file" > "$tmp_file"
elif [ "$(uname)" = "Darwin" ]; then
maybe_sudo sed -e -i '' "$pattern" "$file" > "$tmp_file"
else
log ERROR "Unsupported OS for sed."
exit 1
fi

mv "$tmp_file" "$file"
}

# Create a temporary directory and ensure it's cleaned up on exit
TMP_DIR=$(mktemp -d)
cleanup() {
Expand Down Expand Up @@ -232,7 +249,7 @@ log INFO "yara.sh script downloaded and installed successfully."

# Step 4: Update Wazuh agent configuration file
print_step 4 "Updating Wazuh agent configuration file..."
maybe_sudo sed -i -e '/<directories>\/etc,\/usr\/bin,\/usr\/sbin<\/directories>/a\
custom_sed '/<directories>\/etc,\/usr\/bin,\/usr\/sbin<\/directories>/a\
<directories realtime="yes">/tmp/yara/malware</directories>' "$OSSEC_CONF_PATH" || {
log ERROR "Error occurred during Wazuh agent configuration file update."
exit 1
Expand All @@ -241,17 +258,10 @@ log INFO "Wazuh agent configuration file updated successfully."

# Step 5: Update frequency in Wazuh agent configuration file
print_step 5 "Updating frequency in Wazuh agent configuration file..."
if [ "$(uname)" = "Linux" ]; then
maybe_sudo sed -i 's/<frequency>43200<\/frequency>/<frequency>300<\/frequency>/g' "$OSSEC_CONF_PATH" || {
log ERROR "Error occurred during frequency update in Wazuh agent configuration file."
exit 1
}
elif [ "$(uname)" = "Darwin" ]; then
maybe_sudo sed -i '' 's/<frequency>43200<\/frequency>/<frequency>300<\/frequency>/g' "$OSSEC_CONF_PATH" || {
log ERROR "Error occurred during frequency update in Wazuh agent configuration file."
exit 1
}
fi
custom_sed 's/<frequency>43200<\/frequency>/<frequency>300<\/frequency>/g' "$OSSEC_CONF_PATH" || {
log ERROR "Error occurred during frequency update in Wazuh agent configuration file."
exit 1
}
log INFO "Frequency in Wazuh agent configuration file updated successfully."

# Step 6: Restart Wazuh agent
Expand Down

0 comments on commit 1fdb6d5

Please sign in to comment.