1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-04-01 23:57:05 +00:00

Checking file existence using 'if' replaced with shell option 'nullglob' to prevent the following 'for' loop from being entered even when no matching files are present.

This commit is contained in:
Tomasz Stanczak 2025-02-08 10:46:27 +01:00
parent 8bac222ea5
commit c214e98535

View File

@ -3,17 +3,16 @@
source /etc/mailinabox.conf source /etc/mailinabox.conf
shopt -s extglob shopt -s extglob
shopt -s nullglob
if ls "$STORAGE_ROOT/ssl/"*-+([0-9])-+([0-9a-f]).pem &>/dev/null; then retain_after="$(date --date="7 days ago" +%Y%m%d)"
retain_after="$(date --date="7 days ago" +%Y%m%d)"
mkdir -p $STORAGE_ROOT/ssl.expired mkdir -p $STORAGE_ROOT/ssl.expired
for file in $STORAGE_ROOT/ssl/*-+([0-9])-+([0-9a-f]).pem; do for file in $STORAGE_ROOT/ssl/*-+([0-9])-+([0-9a-f]).pem; do
pem="$(basename "$file")" pem="$(basename "$file")"
not_valid_after="$(cut -d- -f1 <<< "${pem: -21}")" not_valid_after="$(cut -d- -f1 <<< "${pem: -21}")"
if [ "$not_valid_after" -lt "$retain_after" ]; then if [ "$not_valid_after" -lt "$retain_after" ]; then
mv "$file" "$STORAGE_ROOT/ssl.expired/${pem}" mv "$file" "$STORAGE_ROOT/ssl.expired/${pem}"
fi fi
done done
fi