Skip to content

Commit a7d83f0

Browse files
authored
Merge pull request #3199 from jimklimov/issue-3196
Fix back/double quoted shell scripting nuances
2 parents 130826c + 844f987 commit a7d83f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+768
-677
lines changed

Makefile.am

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,11 @@ spellcheck spellcheck-interactive:
686686
(cd $(builddir)/docs && $(MAKE) $(AM_MAKEFLAGS) -k -s $(abs_top_builddir)/docs/.prep-src-docs) || RES=$$? ; \
687687
(cd $(builddir)/docs/man && $(MAKE) $(AM_MAKEFLAGS) -k -s $(abs_top_builddir)/docs/man/.prep-src-docs) || RES=$$? ; \
688688
for D in $(SPELLCHECK_DIRS_MOST) ; do \
689-
D="`echo "$$D" | sed 's,^spellcheck/,,'`" ; \
689+
D="`echo \"$$D\" | sed 's,^spellcheck/,,'`" ; \
690690
(cd "$(builddir)/$$D" && $(MAKE) $(AM_MAKEFLAGS) -k -s $@) || RES=$$? ; \
691691
done ; \
692692
for D in $(SPELLCHECK_DIRS_LAST) ; do \
693-
D="`echo "$$D" | sed 's,^spellcheck/,,'`" ; \
693+
D="`echo \"$$D\" | sed 's,^spellcheck/,,'`" ; \
694694
(cd "$(builddir)/$$D" && $(MAKE) $(AM_MAKEFLAGS) SPELLCHECK_REPORT_MAYBE_UPDATED_DICT=yes -k -s $@) || RES=$$? ; \
695695
done ; \
696696
exit $$RES ; \
@@ -703,7 +703,7 @@ spellcheck spellcheck-interactive:
703703
( $(MAKE) $(AM_MAKEFLAGS) SPELLCHECK_TGT='$@' SUBDIR_MAKE_VERBOSE="$${SUBDIR_MAKE_VERBOSE}" -k -s $(SPELLCHECK_DIRS) && exit ; \
704704
echo "WARNING: FAILED fanned-out attempt in $@, retrying with NUT_MAKE_SKIP_FANOUT" >&2 ; \
705705
$(MAKE) $(AM_MAKEFLAGS) NUT_MAKE_SKIP_FANOUT=true SPELLCHECK_TGT='$@' -k -s $(SPELLCHECK_DIRS) ) || exit ; \
706-
if [ x"$@" = xspellcheck-interactive ] ; then \
706+
if [ x'$@' = xspellcheck-interactive ] ; then \
707707
echo "SUCCESS: $@: follow up with spellcheck-quick to revise and update timestamps"; \
708708
$(MAKE) $(AM_MAKEFLAGS) spellcheck-quick ; \
709709
fi
@@ -787,7 +787,7 @@ maintainer-asciidocs:
787787
esac ; \
788788
printf '%s\n' "$${LINE}" >> "$${F}.$${EXT}" || exit ; \
789789
done < "$$F" || { echo "$@: FAILED injection for $${F}" >&2; exit 1; } ; \
790-
if test -s "$${F}.2.tmp" && test -z "`diff "$${F}.2.tmp" docs/asciidoc-vars.conf | tr -d '\n'`" ; then \
790+
if test -s "$${F}.2.tmp" && test -z "`diff \"$${F}.2.tmp\" docs/asciidoc-vars.conf | tr -d '\n'`" ; then \
791791
rm -f "$${F}"*.tmp ; \
792792
echo "$@: SKIP: no changes: $$F"; continue ; \
793793
fi; \
@@ -852,7 +852,7 @@ check-scripts-syntax:
852852
@echo 'NOTE: modern bash complains about scripts using backticks (warning not error), which we ignore in NUT codebase for portability reasons: `...` obsolete, use $$(...)'
853853
@RUNBASH=bash; if [ -x /bin/bash ] && /bin/bash -c 'echo $${BASH_VERSION}' | $(EGREP) '^[456789]\.' ; then RUNBASH=/bin/bash ; else if [ -x /usr/bin/env ] ; then RUNBASH="/usr/bin/env bash"; fi; fi ; \
854854
for F in `git ls-files || find . -type f` ; do \
855-
case "`file "$$F"`" in \
855+
case "`file \"$$F\"`" in \
856856
*"Bourne-Again shell script"*) ( set -x ; $$RUNBASH -n "$$F" ; ) ;; \
857857
*"POSIX shell script"*|*"shell script"*) ( set -x ; /bin/sh -n "$$F" ; ) ;; \
858858
esac || { RES=$$? ; echo "ERROR: Syntax check failed for script file: $$F" >&2 ; exit $$RES ; } ; \
@@ -964,42 +964,42 @@ CHANGELOG_REQUIRE_GROUP_BY_DATE_AUTHOR_ENVVAR = true
964964
$(abs_top_builddir)/ChangeLog: tools/gitlog2changelog.py dummy-stamp
965965
@cd $(abs_top_srcdir) && \
966966
if ( test -e .git ) 2>/dev/null || test -d .git || test -f .git || test -h .git ; then \
967-
NUT_GITDIR=".git" ; if test -r "$${NUT_GITDIR}" -a ! -d "$${NUT_GITDIR}" ; then GD="`$(EGREP) '^gitdir:' "$${NUT_GITDIR}" | sed 's/^gitdir: *//'`" && test -n "$$GD" -a -d "$$GD" && NUT_GITDIR="$$GD" ; fi ; \
968-
if test -s "$@" -a -d "$${NUT_GITDIR}" && test -z "`find "$${NUT_GITDIR}" -newer "$@" 2>/dev/null`" ; then \
967+
NUT_GITDIR=".git" ; if test -r "$${NUT_GITDIR}" -a ! -d "$${NUT_GITDIR}" ; then GD="`$(EGREP) '^gitdir:' \"$${NUT_GITDIR}\" | sed 's/^gitdir: *//'`" && test -n "$$GD" -a -d "$$GD" && NUT_GITDIR="$$GD" ; fi ; \
968+
if test -s '$@' -a -d "$${NUT_GITDIR}" && test -z "`find \"$${NUT_GITDIR}\" -newer '$@' 2>/dev/null`" ; then \
969969
echo " DOC-CHANGELOG-GENERATE $@ : SKIP (keep existing)" ; \
970970
echo "Using still-valid ChangeLog file generated earlier from same revision of Git source metadata in '$${NUT_GITDIR}'" >&2 ; \
971971
else \
972-
if test -s "$@" ; then \
972+
if test -s '$@' ; then \
973973
echo " DOC-CHANGELOG-GENERATE $@ : RE-GENERATE (older than Git workspace metadata) ..." ; \
974974
else \
975975
echo " DOC-CHANGELOG-GENERATE $@ : GENERATE (currently absent) ..." ; \
976976
fi ; \
977-
CHANGELOG_FILE="$@" $(WITH_PDF_NONASCII_TITLES_ENVVAR) \
977+
CHANGELOG_FILE='$@' $(WITH_PDF_NONASCII_TITLES_ENVVAR) \
978978
CHANGELOG_REQUIRE_GROUP_BY_DATE_AUTHOR="$(CHANGELOG_REQUIRE_GROUP_BY_DATE_AUTHOR_ENVVAR)" \
979979
$(abs_top_builddir)/tools/gitlog2changelog.py $(GITLOG_START_POINT) $(GITLOG_END_POINT) \
980980
&& { echo " DOC-CHANGELOG-GENERATE $@ : SUCCESS"; } \
981981
|| { \
982982
echo " DOC-CHANGELOG-GENERATE $@ : FAILED (non-fatal)" >&2 ; \
983-
printf "gitlog2changelog.py failed to generate the ChangeLog.\n\nNOTE: See https://github.com/networkupstools/nut/commits/master for change history.\n\n" > "$@" ; \
983+
printf "gitlog2changelog.py failed to generate the ChangeLog.\n\nNOTE: See https://github.com/networkupstools/nut/commits/master for change history.\n\n" > '$@' ; \
984984
} ; \
985985
fi ; \
986986
else \
987987
if test x"$(abs_top_srcdir)" != x"$(abs_top_builddir)" -a -s ./ChangeLog ; then \
988988
echo " DOC-CHANGELOG-GENERATE $@ : SKIP (keep existing)" ; \
989-
if diff ./ChangeLog "$@" >/dev/null 2>/dev/null ; then \
989+
if diff ./ChangeLog '$@' >/dev/null 2>/dev/null ; then \
990990
echo "Using distributed ChangeLog file from sources (and builddir already has content identical to one in srcdir)" >&2 ; \
991991
else \
992992
echo "Using distributed ChangeLog file from sources (and builddir is not srcdir)" >&2 ; \
993-
rm -f "$@" || true ; \
994-
cp -pf ./ChangeLog "$@" || { cat ./ChangeLog > "$@" ; touch -r ./ChangeLog "$@" || true ; } ; \
993+
rm -f '$@' || true ; \
994+
cp -pf ./ChangeLog '$@' || { cat ./ChangeLog > '$@' ; touch -r ./ChangeLog '$@' || true ; } ; \
995995
fi ; \
996996
else \
997-
if test -s "$@" ; then \
997+
if test -s '$@' ; then \
998998
echo " DOC-CHANGELOG-GENERATE $@ : SKIP (keep existing)" ; \
999999
echo "Using distributed ChangeLog file from sources (and builddir is srcdir)" >&2 ; \
10001000
else \
10011001
echo " DOC-CHANGELOG-GENERATE $@ : FAILED (non-fatal)" >&2 ; \
1002-
printf "Failed to generate the ChangeLog.\n\nNOTE: See https://github.com/networkupstools/nut/commits/master for change history.\n\n" > "$@" ; \
1002+
printf "Failed to generate the ChangeLog.\n\nNOTE: See https://github.com/networkupstools/nut/commits/master for change history.\n\n" > '$@' ; \
10031003
fi ; \
10041004
fi ; \
10051005
fi
@@ -1494,7 +1494,7 @@ install-win-bundle-thirdparty:
14941494
'$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
14951495
| while read D ; do \
14961496
echo " DLL->sbin $$D" 2>&1 ; \
1497-
ln -f '$(DESTDIR)/$(bindir)'/"`basename "$$D"`" ./ ; \
1497+
ln -f '$(DESTDIR)/$(bindir)'/"`basename \"$$D\"`" ./ ; \
14981498
done ; \
14991499
) || exit ; \
15001500
( if test x"$(driverexecdir)" = x"$(bindir)" ; then exit 0 ; fi ; \
@@ -1503,7 +1503,7 @@ install-win-bundle-thirdparty:
15031503
'$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
15041504
| while read D ; do \
15051505
echo " DLL->drv $$D" 2>&1 ; \
1506-
ln -f '$(DESTDIR)/$(bindir)'/"`basename "$$D"`" ./ ; \
1506+
ln -f '$(DESTDIR)/$(bindir)'/"`basename \"$$D\"`" ./ ; \
15071507
done ; \
15081508
) || exit ; \
15091509
( if test -z "$(cgiexecdir)" -o ! -d "$(DESTDIR)/$(cgiexecdir)" ; then exit 0 ; fi ; \
@@ -1514,7 +1514,7 @@ install-win-bundle-thirdparty:
15141514
'$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
15151515
| while read D ; do \
15161516
echo " DLL->cgi $$D" 2>&1 ; \
1517-
ln -f '$(DESTDIR)/$(bindir)'/"`basename "$$D"`" ./ ; \
1517+
ln -f '$(DESTDIR)/$(bindir)'/"`basename \"$$D\"`" ./ ; \
15181518
done ; \
15191519
) || exit ; \
15201520
( if test x"$(libexecdir)" = x"$(bindir)" ; then exit 0 ; fi ; \
@@ -1525,7 +1525,7 @@ install-win-bundle-thirdparty:
15251525
'$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
15261526
| while read D ; do \
15271527
echo " DLL->libexec $$D" 2>&1 ; \
1528-
ln -f '$(DESTDIR)/$(bindir)'/"`basename "$$D"`" ./ ; \
1528+
ln -f '$(DESTDIR)/$(bindir)'/"`basename \"$$D\"`" ./ ; \
15291529
done ; \
15301530
) || exit
15311531
@echo "CHECKING if any executable files were installed to locations other than those covered by this recipe, so might not have needed DLLs bundled near them" >&2 ; \

NEWS.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ https://github.com/networkupstools/nut/milestone/12
4040
to patterns defined in link:docs/nut-names.txt[]
4141

4242
- common code:
43+
* Generally improved shell script portability (including `Makefile.am`
44+
embedded recipes) when mixing back-quotes and double-quotes. Namely,
45+
the classic Solaris `ksh` implementation (also used in current versions
46+
of Solaris and illumos based distributions) was strict about following
47+
(an older revision of) the POSIX standard here, and some use-cases
48+
misbehaved with our older script spelling. [issue #3196]
4349
* Introduced `setproctag()` and `getproctag()` (see examples in `upsmon`)
4450
to help track the log messages from massively-forking NUT daemons. [#3084]
4551
* Extended with plural `checkprocnames()` and `compareprocnames()`,

autogen.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fi
2727
[ -n "${GREP}" ] || { GREP="`command -v grep`" && [ x"${GREP}" != x ] || { echo "$0: FAILED to locate GREP tool" >&2 ; exit 1 ; } ; export GREP ; }
2828
[ -n "${EGREP}" ] || { if ( [ x"`echo a | $GREP -E '(a|b)'`" = xa ] ) 2>/dev/null ; then EGREP="$GREP -E" ; else EGREP="`command -v egrep`" ; fi && [ x"${EGREP}" != x ] || { echo "$0: FAILED to locate EGREP tool" >&2 ; exit 1 ; } ; export EGREP ; }
2929

30-
NUT_VERSION_QUERY=UPDATE_FILE "`dirname $0`"/tools/gitlog2version.sh
30+
NUT_VERSION_QUERY=UPDATE_FILE "`dirname \"$0\"`"/tools/gitlog2version.sh
3131

3232
if [ -n "${PYTHON-}" ] ; then
3333
# May be a name/path of binary, or one with args - check both
@@ -87,7 +87,7 @@ then
8787
echo "Proceeding without Augeas integration, be sure to not require it in configure script" >&2
8888
touch scripts/augeas/nutupsconf.aug.in scripts/augeas/nutupsconf.aug.in.AUTOGEN_WITHOUT
8989
else
90-
echo "Aborting $0! To avoid this, please export WITHOUT_NUT_AUGEAS=true and re-run" >&2
90+
echo "Aborting $0! To avoid this, please export WITHOUT_NUT_AUGEAS=true and re-run" >&2
9191
echo "or better yet, export PYTHON=python-x.y and re-run" >&2
9292
exit 1
9393
fi

0 commit comments

Comments
 (0)