Skip to content

Commit

Permalink
When downgrading the postrm deb script is run as an upgrade.
Browse files Browse the repository at this point in the history
This works fine with newer versions of Wazuh that follow the same paths structure.

Older versions (ones with ossec group and user) require that we restore that expected
paths and ownership.
  • Loading branch information
jr0me committed Mar 19, 2024
1 parent 24efdee commit 11176d1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions debs/SPECS/wazuh-agent/debian/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ case "$1" in
;;

upgrade)
# If the upgrade downgrades to earlier versions, restore ownership
if command -v ${DIR}/bin/ossec-control > /dev/null 2>&1; then

OSMYSHELL="/sbin/nologin"

if [ -f ${DIR}/queue/sockets/.agent_info ]; then
mv ${DIR}/queue/sockets/.agent_info ${DIR}/queue/ossec/
fi

if ! getent group ossec > /dev/null 2>&1; then
addgroup --system ossec > /dev/null 2>&1
fi

if ! getent passwd ossec > /dev/null 2>&1; then
adduser --system --home /var/ossec --shell ${OSMYSHELL} --ingroup ossec ossec > /dev/null 2>&1
fi

find ${DIR} ! -group root -exec chgrp ossec {} \; > /dev/null 2>&1
find ${DIR} ! -user root -exec chown ossec {} \; > /dev/null 2>&1

# delete wazuh user and group
if getent passwd wazuh > /dev/null 2>&1; then
deluser wazuh
fi

if getent group wazuh > /dev/null 2>&1; then
delgroup wazuh
fi
fi

exit 0

;;

Expand Down

0 comments on commit 11176d1

Please sign in to comment.