From ecfb96d339ba739b04f2cbe5e6fbb782b6776092 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 10 Jul 2022 09:52:55 +0100 Subject: [PATCH 1/2] If old log paths exist in logrotate file, replace them with new ones Signed-off-by: Adam Warner --- automated install/basic-install.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 078307a6..22fe209a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1955,10 +1955,28 @@ installLogrotate() { printf "\\n %b %s..." "${INFO}" "${str}" if [[ -f ${target} ]]; then - printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" "${INFO}" - # Return value isn't that important, using 2 to indicate that it's not a fatal error but - # the function did not complete. - return 2 + local touched=0 + + if grep -q "/var/log/pihole.log" ${target}; then + sed -i 's/\/var\/log\/pihole.log/\/var\/log\/pihole\/pihole.log/g' ${target} + touched=1 + fi + + if grep -q "/var/log/pihole-FTL.log" ${target}; then + sed -i 's/\/var\/log\/pihole-FTL.log/\/var\/log\/pihole\/FTL.log/g' ${target} + touched=1 + fi + + if [ "${touched}" -eq "0" ]; then + printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" "${INFO}" + # Return value isn't that important, using 2 to indicate that it's not a fatal error but + # the function did not complete. + return 2 + else + printf "\\n\\t%b Old log file paths updated in existing logrotate file. \\n" "${INFO}" + return 3 + fi + fi # Copy the file over from the local repo install -D -m 644 -T "${PI_HOLE_LOCAL_REPO}"/advanced/Templates/logrotate ${target} From 59dab6a568c37ae8331472cf5f94da6531858b64 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 10 Jul 2022 11:50:09 +0100 Subject: [PATCH 2/2] Simplifications per @yubiuser's suggestion Co-authored-by: yubiuser Signed-off-by: Adam Warner --- automated install/basic-install.sh | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 22fe209a..30040a99 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1955,28 +1955,20 @@ installLogrotate() { printf "\\n %b %s..." "${INFO}" "${str}" if [[ -f ${target} ]]; then - local touched=0 - if grep -q "/var/log/pihole.log" ${target}; then + # Account for changed logfile paths from /var/log -> /var/log/pihole/ made in core v5.11. + if grep -q "/var/log/pihole.log" ${target} || grep -q "/var/log/pihole-FTL.log" ${target}; then sed -i 's/\/var\/log\/pihole.log/\/var\/log\/pihole\/pihole.log/g' ${target} - touched=1 - fi - - if grep -q "/var/log/pihole-FTL.log" ${target}; then sed -i 's/\/var\/log\/pihole-FTL.log/\/var\/log\/pihole\/FTL.log/g' ${target} - touched=1 - fi - if [ "${touched}" -eq "0" ]; then - printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" "${INFO}" - # Return value isn't that important, using 2 to indicate that it's not a fatal error but - # the function did not complete. - return 2 - else printf "\\n\\t%b Old log file paths updated in existing logrotate file. \\n" "${INFO}" return 3 fi + printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" "${INFO}" + # Return value isn't that important, using 2 to indicate that it's not a fatal error but + # the function did not complete. + return 2 fi # Copy the file over from the local repo install -D -m 644 -T "${PI_HOLE_LOCAL_REPO}"/advanced/Templates/logrotate ${target}