From 43c2efefe86db6cca31b41a253050d02abdc24b7 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 17 Oct 2022 16:19:24 +0200 Subject: [PATCH] refactor(nginx): apply necessary changes for moonraker PR 491 Signed-off-by: Dominik Willner --- scripts/nginx.sh | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/scripts/nginx.sh b/scripts/nginx.sh index dfff521..3a9215f 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -74,23 +74,29 @@ function set_upstream_nginx_cfg() { } function symlink_webui_nginx_log() { - local interface=${1} path="${KLIPPER_LOGS}" - local access_log="/var/log/nginx/${interface}-access.log" - local error_log="/var/log/nginx/${interface}-error.log" + local interface path access_log error_log regex logpaths - [[ ! -d ${path} ]] && mkdir -p "${path}" + interface=${1} + access_log="/var/log/nginx/${interface}-access.log" + error_log="/var/log/nginx/${interface}-error.log" + regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/logs" + logpaths=$(find "${HOME}" -maxdepth 2 -type d -regextype posix-extended -regex "${regex}" | sort) - if [[ -f ${access_log} && ! -L "${path}/${interface}-access.log" ]]; then - status_msg "Creating symlink for ${access_log} ..." - ln -s "${access_log}" "${path}" - ok_msg "Done!" - fi + for path in ${logpaths}; do + [[ ! -d ${path} ]] && mkdir -p "${path}" - if [[ -f ${error_log} && ! -L "${path}/${interface}-error.log" ]]; then - status_msg "Creating symlink for ${error_log} ..." - ln -s "${error_log}" "${path}" - ok_msg "Done!" - fi + if [[ -f ${access_log} && ! -L "${path}/${interface}-access.log" ]]; then + status_msg "Creating symlink for ${access_log} ..." + ln -s "${access_log}" "${path}" + ok_msg "Symlink created: ${path}/${interface}-access.log" + fi + + if [[ -f ${error_log} && ! -L "${path}/${interface}-error.log" ]]; then + status_msg "Creating symlink for ${error_log} ..." + ln -s "${error_log}" "${path}" + ok_msg "Symlink created: ${path}/${interface}-error.log" + fi + done } function match_nginx_configs() {