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

Replace launchctl variables from macOS installation scripts #2218

Merged
merged 2 commits into from May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 16 additions & 9 deletions macos/package_files/postinstall.sh
Expand Up @@ -14,7 +14,19 @@ DIR="/Library/Ossec"
INSTALLATION_SCRIPTS_DIR="${DIR}/packages_files/agent_installation_scripts"
SCA_BASE_DIR="${INSTALLATION_SCRIPTS_DIR}/sca"

if [ $(launchctl getenv WAZUH_PKG_UPGRADE) = true ]; then
if [ -f "${DIR}/WAZUH_PKG_UPGRADE" ]; then
upgrade="true"
fi

rm -f ${DIR}/WAZUH_PKG_UPGRADE
rauldpm marked this conversation as resolved.
Show resolved Hide resolved

if [ -f "${DIR}/WAZUH_RESTART" ]; then
restart="true"
fi

rm -f ${DIR}/WAZUH_RESTART
rauldpm marked this conversation as resolved.
Show resolved Hide resolved

if [ -n "${upgrade}" ]; then
rm -rf ${DIR}/etc/{ossec.conf,client.keys,local_internal_options.conf,shared}
cp -rf ${DIR}/config_files/{ossec.conf,client.keys,local_internal_options.conf,shared} ${DIR}/etc/
rm -rf ${DIR}/config_files/
Expand Down Expand Up @@ -68,13 +80,8 @@ chown -R root:${GROUP} ${DIR}/var

. ${INSTALLATION_SCRIPTS_DIR}/src/init/dist-detect.sh

upgrade=$(launchctl getenv WAZUH_PKG_UPGRADE)
restart=$(launchctl getenv WAZUH_RESTART)

launchctl unsetenv WAZUH_PKG_UPGRADE
launchctl unsetenv WAZUH_RESTART

if [ "${upgrade}" = "false" ]; then
if [ -z "${upgrade}" ]; then
${INSTALLATION_SCRIPTS_DIR}/gen_ossec.sh conf agent ${DIST_NAME} ${DIST_VER}.${DIST_SUBVER} ${DIR} > ${DIR}/etc/ossec.conf
chown root:wazuh ${DIR}/etc/ossec.conf
chmod 0640 ${DIR}/etc/ossec.conf
Expand Down Expand Up @@ -108,7 +115,7 @@ if [ -r ${SCA_TMP_FILE} ]; then
fi

# Register and configure agent if Wazuh environment variables are defined
if [ "${upgrade}" = "false" ]; then
if [ -z "${upgrade}" ]; then
${INSTALLATION_SCRIPTS_DIR}/src/init/register_configure_agent.sh ${DIR} > /dev/null || :
fi
# Install the service
Expand Down Expand Up @@ -141,6 +148,6 @@ if [ -f ${DIR}/queue/alerts/sockets ]; then
rm ${DIR}/queue/alerts/sockets
fi

if ${upgrade} && ${restart}; then
if [ -n "${upgrade}" ] && [ -n "${restart}" ]; then
${DIR}/bin/wazuh-control restart
fi
21 changes: 11 additions & 10 deletions macos/package_files/preinstall.sh
Expand Up @@ -11,16 +11,17 @@

DIR="/Library/Ossec"

if [ ! -d ${DIR} ]; then
launchctl setenv WAZUH_PKG_UPGRADE false
else
launchctl setenv WAZUH_PKG_UPGRADE true
if [ -d ${DIR} ]; then
rm -f ${DIR}/WAZUH_PKG_UPGRADE
rm -f ${DIR}/WAZUH_RESTART
touch ${DIR}/WAZUH_PKG_UPGRADE
rauldpm marked this conversation as resolved.
Show resolved Hide resolved
upgrade="true"
if ${DIR}/bin/wazuh-control status | grep "is running" > /dev/null 2>&1; then
launchctl setenv WAZUH_RESTART true
touch ${DIR}/WAZUH_RESTART
restart="true"
elif ${DIR}/bin/ossec-control status | grep "is running" > /dev/null 2>&1; then
launchctl setenv WAZUH_RESTART true
else
launchctl setenv WAZUH_RESTART false
touch ${DIR}/WAZUH_RESTART
restart="true"
fi
fi

Expand All @@ -31,7 +32,7 @@ elif [ -f ${DIR}/bin/ossec-control ]; then
${DIR}/bin/ossec-control stop
fi

if [ $(launchctl getenv WAZUH_PKG_UPGRADE) = true ]; then
if [ -n "${upgrade}" ]; then
mkdir -p ${DIR}/config_files/
cp -r ${DIR}/etc/{ossec.conf,client.keys,local_internal_options.conf,shared} ${DIR}/config_files/

Expand All @@ -44,7 +45,7 @@ if [ $(launchctl getenv WAZUH_PKG_UPGRADE) = true ]; then
fi
fi

if [ $(launchctl getenv WAZUH_PKG_UPGRADE) = true ]; then
if [ -n "${upgrade}" ]; then
if pkgutil --pkgs | grep -i wazuh-agent-etc > /dev/null 2>&1 ; then
pkgutil --forget com.wazuh.pkg.wazuh-agent-etc
fi
Expand Down