#!/bin/sh

# add something which happens after upgrade

directory_base="/var/ossec"

cp -a ${directory_base}/tmp/etc/* ${directory_base}/etc/
rm -rf ${directory_base}/tmp/etc

# Ensure required internal_options.conf settings exist for 4.14.1+
# These may be missing when upgrading from older versions (e.g., 4.8)
internal_opts="${directory_base}/etc/internal_options.conf"
if [ -f "$internal_opts" ]; then
	# wazuh_modules.rlimit_nofile is required by wazuh-modulesd in 4.14.1+
	if ! grep -q "^wazuh_modules\.rlimit_nofile" "$internal_opts"; then
		echo "wazuh_modules.rlimit_nofile=8192" >> "$internal_opts"
	fi
fi

if [ -f ${directory_base}/tmp/wazuh.restart ]; then
  rm -f ${directory_base}/tmp/wazuh.restart
  ${directory_base}/bin/wazuh-control restart > /dev/null 2>&1
fi

exit 0
