fix: FreeBSD compat for 2 cron scripts (#550)

pull/562/head
Stéphane Lesimple 10 months ago committed by Stéphane Lesimple
parent ad23386b84
commit cdbd6c701e

@ -20,16 +20,23 @@ script_init osh-remove-empty-folders config_optional check_secure_lax
# first, we list all the directories to get a count
_log "Counting the number of directories before the cleanup..."
nbdirs_before=$(find /home/ -mindepth 3 -maxdepth 3 -type d -regextype egrep -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print | wc -l)
# shellcheck disable=SC2086
nbdirs_before=$(find $FIND_EGREP_POSITIONAL_BEFORE /home/ -mindepth 3 -maxdepth 3 -type d \
$FIND_EGREP_POSITIONAL_AFTER '^/home/[^/]+/ttyrec/[0-9.]+$' -print | wc -l)
_log "We have $nbdirs_before directories, removing empty ones..."
# then we pass them all through rmdir, it'll just fail on non-empty ones.
# this is (way) faster than trying to be smart and listing each and every directory's contents first.
find /home/ -mindepth 3 -maxdepth 3 -type d -mtime +$MTIME_DAYS -regextype egrep -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print0 | xargs -r0 rmdir -- 2>/dev/null
# shellcheck disable=SC2086
find $FIND_EGREP_POSITIONAL_BEFORE /home/ -mindepth 3 -maxdepth 3 -type d \
-mtime +$MTIME_DAYS $FIND_EGREP_POSITIONAL_AFTER -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print0 | \
xargs -r0 rmdir -- 2>/dev/null
# finally, see how many directories remain
_log "Counting the number of directories after the cleanup..."
nbdirs_after=$(find /home/ -mindepth 3 -maxdepth 3 -type d -regextype egrep -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print | wc -l)
# shellcheck disable=SC2086
nbdirs_after=$(find $FIND_EGREP_POSITIONAL_BEFORE /home/ -mindepth 3 -maxdepth 3 -type d \
$FIND_EGREP_POSITIONAL_AFTER -regex '^/home/[^/]+/ttyrec/[0-9.]+$' -print | wc -l)
_log "Finally deleted $((nbdirs_before - nbdirs_after)) directories in this run"

@ -32,7 +32,7 @@ if [ "$1" = "--big-only" ]; then
fi
else
_log "Rotating all ttyrec files..."
if pkill --signal USR1 ttyrec; then
if pkill -USR1 ttyrec; then
_log "Rotation done"
else
_log "No ttyrec files to rotate"

@ -30,11 +30,6 @@ if [ -z "$LINUX_DISTRO" ] || [ -z "$DISTRO_VERSION" ]; then
fi
fi
# special case while bookworm is not yet released
if [ "$DISTRO_VERSION" = "bookworm/sid" ]; then
DISTRO_VERSION=12
fi
LINUX_DISTRO=$(echo "$LINUX_DISTRO" | tr '[:upper:]' '[:lower:]' | tr -d ' ')
# shellcheck disable=SC2034
DISTRO_VERSION_MAJOR=$(echo "$DISTRO_VERSION" | grep -Eo '^[0-9]+' || true)
@ -92,6 +87,16 @@ if [ ! -e "$CRON_DIR" ]; then
CRON_DIR=/etc/cron.d
fi
# set proper `find' options for egrep-style regex matching
# shellcheck disable=SC2034
if [ "$OS_FAMILY" = FreeBSD ]; then
FIND_EGREP_POSITIONAL_BEFORE='-E'
FIND_EGREP_POSITIONAL_AFTER=''
else
FIND_EGREP_POSITIONAL_BEFORE=''
FIND_EGREP_POSITIONAL_AFTER='-regextype egrep'
fi
action_doing()
{
printf '\r*** %b\n' "$*"

Loading…
Cancel
Save