lib.cli-std: fix two shell errors when AUTOMAKE is false

If `AUTOMAKE` is set to `no` in the config file, it is normalized to the
empty string.

This leads to two errors if `find` is provided by Busybox.

There is a conditional where `$AUTOMAKE` is not quoted when compared to
`recursive` leading to the following error:

  /usr/share/shorewall/lib.cli-std: line 398: [: =: unary operator expected

In contrast to the non-Busybox case, we don't check for an empty
`$AUTOMAKE` before passing it as an argument to `-maxdepth`, leading to:

  /usr/bin/find: Expected a positive decimal integer argument to -maxdepth, but got -type

Refactor the conditionals to eliminate code duplication and fix these two
bugs.

Link: https://gitlab.com/shorewall/code/-/issues/10
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
This commit is contained in:
Jeremy Sowden 2023-09-04 20:26:04 +01:00
parent aae5baedfd
commit 5e8ce7d073

View File

@ -381,36 +381,33 @@ uptodate() {
[ -x $1 ] || return 1 [ -x $1 ] || return 1
local dir local dir
local busybox
local find local find
local quit
local maxdepth
find=$(mywhich find) find=$(mywhich find)
[ -n "${find}" ] || return 1 [ -n "${find}" ] || return 1
[ -h "${find}" ] && busybox=Yes
find="${find} -L" if [ -h "${find}" ]; then
#
# 'Find' is provided by Busybox and doesn't support -quit.
#
quit=
else
quit=-quit
fi
if [ "$AUTOMAKE" = recursive ]; then
maxdepth=
elif [ -z "$AUTOMAKE" ]; then
maxdepth="-maxdepth 1"
else
maxdepth="-maxdepth $AUTOMAKE"
fi
for dir in $g_shorewalldir $(split $CONFIG_PATH); do for dir in $g_shorewalldir $(split $CONFIG_PATH); do
if [ -n "${busybox}" ]; then if [ -n "$(${find} -L ${dir} ${maxdepth} -newer $1 -print ${quit})" ]; then
#
# Busybox 'find' doesn't support -quit.
#
if [ $AUTOMAKE = recursive ]; then
if [ -n "$(${find} ${dir} -newer $1 -print)" ]; then
return 1;
fi
elif [ -n "$(${find} ${dir} -maxdepth $AUTOMAKE -type f -newer $1 -print)" ]; then
return 1;
fi
elif [ "$AUTOMAKE" = recursive ]; then
if [ -n "$(${find} ${dir} -newer $1 -print -quit)" ]; then
return 1;
fi
elif [ -z "$AUTOMAKE" ]; then
if [ -n "$(${find} ${dir} -maxdepth 1 -type f -newer $1 -print -quit)" ]; then
return 1;
fi
elif [ -n "$(${find} ${dir} -maxdepth $AUTOMAKE -type f -newer $1 -print -quit)" ]; then
return 1; return 1;
fi fi
done done