Skip to content

Commit

Permalink
Merge pull request #2911 from wazuh/change/2536-wazuh-certs-tool-log-…
Browse files Browse the repository at this point in the history
…file-not-defined

Cert-tool logfile added. Modified common_logger function to write on files without root permission.
  • Loading branch information
teddytpc1 authored Apr 24, 2024
2 parents 73e5bdc + 7e20b38 commit a1bca34
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions unattended_installer/cert_tool/certMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function main() {
esac
done

common_logger "Verbose logging redirected to ${logfile}"

if [[ -d "${base_path}"/wazuh-certificates ]]; then
if [ -n "$(ls -A "${base_path}"/wazuh-certificates)" ]; then
common_logger -e "Directory wazuh-certificates already exists in the same path as the script. Please, remove the certs directory to create new certificates."
Expand Down
8 changes: 4 additions & 4 deletions unattended_installer/cert_tool/certVariables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# License (version 2) as published by the FSF - Free Software
# Foundation.

base_path="$(dirname "$(readlink -f "$0")")"
readonly base_path
readonly base_path="$(dirname "$(readlink -f "$0")")"
readonly config_file="${base_path}/config.yml"
readonly logfile=""
readonly logfile="${base_path}/wazuh-certificates-tool.log"
cert_tmp_path="/tmp/wazuh-certificates"
debug=">> /dev/null 2>&1"
debug=">> ${logfile} 2>&1"
readonly cert_tool_script_name=".*certs.*\.sh"
2 changes: 1 addition & 1 deletion unattended_installer/common_functions/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function common_logger() {
fi

if [ -z "${debugLogger}" ] || { [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ]; }; then
if [ "$EUID" -eq 0 ] && [ -z "${nolog}" ]; then
if [ -z "${nolog}" ] && { [ "$EUID" -eq 0 ] || [[ "$(basename "$0")" =~ $cert_tool_script_name ]]; }; then
printf "%s\n" "${now} ${mtype} ${message}" | tee -a ${logfile}
else
printf "%b\n" "${now} ${mtype} ${message}"
Expand Down

0 comments on commit a1bca34

Please sign in to comment.