Skip to content

Commit 18b2f39

Browse files
Merge pull request #581 from ExtremeFiretop/ExtremeFiretop-patch-1
Fix log cleanup function to create directory and restore logs
2 parents c97d27e + 7a3be17 commit 18b2f39

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎MerlinAU.sh‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
set -u
1010

1111
## Set version for each Production Release ##
12-
readonly SCRIPT_VERSION=1.6.4
13-
readonly SCRIPT_VERSTAG="26061118"
12+
readonly SCRIPT_VERSION=1.6.5
13+
readonly SCRIPT_VERSTAG="26062210"
1414
readonly SCRIPT_NAME="MerlinAU"
1515
## Set to "master" for Production Releases ##
16-
SCRIPT_BRANCH="master"
16+
SCRIPT_BRANCH="dev"
1717

1818
##----------------------------------------##
1919
## Modified by Martinski W. [2024-Jul-03] ##
@@ -2250,7 +2250,11 @@ readonly POST_UPDATE_EMAIL_SCRIPT_HOOK="[ -x $ScriptFilePath ] && $POST_UPDATE_E
22502250
##------------------------------------------##
22512251
_CleanUpOldLogFiles_()
22522252
{
2253-
[ ! -d "$FW_LOG_DIR" ] && return 1
2253+
# Create the log directory on a fresh installation.
2254+
if [ ! -d "$FW_LOG_DIR" ]
2255+
then
2256+
mkdir -p -m 755 "$FW_LOG_DIR" 2>/dev/null || return 1
2257+
fi
22542258
local numLogFiles topLogFile savedTopLogFile=""
22552259

22562260
numLogFiles="$(ls -1lt "$FW_LOG_DIR"/*.log 2>/dev/null | wc -l)"
@@ -2270,7 +2274,18 @@ _CleanUpOldLogFiles_()
22702274
fi
22712275

22722276
# Delete logs older than 30 days #
2273-
/usr/bin/find -L "$FW_LOG_DIR" -name '*.log' -mtime +30 -exec rm {} \;
2277+
if ! /usr/bin/find -L "$FW_LOG_DIR" \
2278+
-name '*.log' \
2279+
-mtime +30 \
2280+
-exec rm -f {} \;
2281+
then
2282+
# Attempt restoration before returning failure.
2283+
[ -n "$savedTopLogFile" ] &&
2284+
[ -e "$savedTopLogFile" ] &&
2285+
mv -f "$savedTopLogFile" "$topLogFile" 2>/dev/null
2286+
2287+
return 1
2288+
fi
22742289

22752290
# Restore the most recent log file #
22762291
if [ -n "$topLogFile" ] && \

0 commit comments

Comments
 (0)