diff --git a/bin/cron/osh-remove-empty-folders.sh b/bin/cron/osh-remove-empty-folders.sh index b6007a0..61aa12b 100755 --- a/bin/cron/osh-remove-empty-folders.sh +++ b/bin/cron/osh-remove-empty-folders.sh @@ -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" diff --git a/bin/cron/osh-rotate-ttyrec.sh b/bin/cron/osh-rotate-ttyrec.sh index 9e9c3d8..00d02cf 100755 --- a/bin/cron/osh-rotate-ttyrec.sh +++ b/bin/cron/osh-rotate-ttyrec.sh @@ -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" diff --git a/lib/shell/functions.inc b/lib/shell/functions.inc index 03630e0..e92bff1 100644 --- a/lib/shell/functions.inc +++ b/lib/shell/functions.inc @@ -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' "$*"