1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

build system: modernise shell compatibility checks

All changed files:
- Put the shell in POSIX mode if it has an '-o posix' option.
- Remove nonsense disabling 'set -x' on bash. It's not broken.

bin/package, src/cmd/INIT/package.sh:
- Add check blocking native zsh mode (e.g., "$path" conflicts).
  Using a 'sh -> zsh' symlink works, so recommend that.
- Remove old ksh93 version check for a supposed conflict with
  libcmd. It was broken; it would revert to /bin/sh, but on illumos
  distributions, /bin/sh is a ksh93 of a version that is supposedly
  affected. It builds fine anyway.
- Rewrite checksh() to incorporate the shell compatibility checks
  that were previously in two different places in 'package'.

bin/ignore, src/cmd/INIT/ignore.sh,
bin/silent, src/cmd/INIT/silent.sh:
- Change bad check for a full POSIX 'export' command (no, $RANDOM
  has nothing to do with that) with a proper feature test.
This commit is contained in:
Martijn Dekker 2020-08-23 23:41:31 +01:00
parent 42d1651108
commit 9b45f2ccbe
20 changed files with 113 additions and 128 deletions

View file

@ -20,18 +20,17 @@
# non-ksh script for the nmake ignore prefix
# @(#)ignore (AT&T Research) 1992-08-11
case $-:$BASH_VERSION in
*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
esac
(set -o posix) 2>/dev/null && set -o posix
modern_export=`v=; export v=ok 2>/dev/null; echo "$v"`
while :
do case $# in
0) exit 0 ;;
esac
case $1 in
*=*) case $RANDOM in
$RANDOM)`echo $1 | sed "s/\\([^=]*\\)=\\(.*\\)/eval \\1='\\2'; export \\1/"` ;;
*) export "$1" ;;
*=*) case $modern_export in
ok) export "$1" ;;
*) `echo $1 | sed "s/\\([^=]*\\)=\\(.*\\)/eval \\1='\\2'; export \\1/"` ;;
esac
shift
;;

View file

@ -21,9 +21,7 @@
# mamprobe - generate MAM cc probe info
# Glenn Fowler <gsf@research.att.com>
case $-:$BASH_VERSION in
*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
esac
(set -o posix) 2>/dev/null && set -o posix
command=mamprobe

View file

@ -24,38 +24,34 @@ USAGE_LICENSE="[-author?Glenn Fowler <gsf@research.att.com>][-copyright?Copyrigh
command=package
case $-:$BASH_VERSION in
*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
(set -o posix) 2>/dev/null && set -o posix
path=Bad
case $PATH in
Bad*) echo "Cannot be run by zsh in native mode; use a sh symlink to zsh" >&2
exit 1 ;;
esac
# ksh checks -- ksh between 2007-11-05 and 2011-11-11 conflict with new -lcmd -- wea culpa
# shell checks
checksh()
{
egrep 'Version.*(88|1993)' $1 >/dev/null 2>&1 ||
PATH=/dev/null $1 -c '(( 2 + 2 ))' >/dev/null 2>&1 &&
$1 -c '(( .sh.version >= 20111111 ))' >/dev/null 2>&1
"$1" -ec '
# reject csh
case 1 in
1) ;;
esac
# reject special use of $path (to use zsh, use a "sh -> zsh" symlink, which disables this)
path=Bad
case $PATH in
Bad*) exit 1 ;;
esac
# catch (our own) pipe/socket configuration mismatches
date | "$1" -c "read x" || exit 1
# check Bourne/POSIX compatible trap exit status (should exit with status 0)
trap "exit 0" 0
exit 1
' x "$1" 2>/dev/null || return 1
}
case $_AST_BIN_PACKAGE_:$SHELL:$0 in
1:*:*|*:/bin/sh:*)
;;
*:*/*:*/*)
_AST_BIN_PACKAGE_=1 # prevent non-interactive sh .rc referencing bin/package recursion #
export _AST_BIN_PACKAGE_
if checksh $SHELL
then : no -lcmd conflict :
else case " $* " in
*" debug "*|*" DEBUG "*|*" show "*)
echo $command: $SHELL: warning: possible -lcmd conflict -- falling back to /bin/sh >&2
;;
esac
SHELL=/bin/sh
export SHELL
exec $SHELL "$0" "$@"
fi
;;
esac
LC_ALL=C
export LC_ALL
@ -3103,26 +3099,7 @@ cat $INITROOT/$i.sh
;;
esac
;;
esac
# $SHELL must be /bin/sh compatible
case $SHELL in
/bin/sh);;
'') SHELL=/bin/sh
;;
*) $SHELL -c 'trap "exit 0" 0; exit 1' 2>/dev/null
case $? in
1) SHELL=/bin/sh
;;
*) # catch (our own) pipe/socket configuration mismatches
$SHELL -c "date | $SHELL -c 'read x'"
case $? in
0) ;;
*) SHELL=/bin/sh ;;
esac
;;
esac
*) checksh $SHELL || SHELL=/bin/sh
;;
esac
export SHELL

View file

@ -20,18 +20,17 @@
# non-ksh stub for the nmake silent prefix
# @(#)silent (AT&T Research) 1992-08-11
case $-:$BASH_VERSION in
*x*:[01234567899]*) : bash set -x is broken :; set +ex ;;
esac
(set -o posix) 2>/dev/null && set -o posix
modern_export=`v=; export v=ok 2>/dev/null; echo "$v"`
while :
do case $# in
0) exit 0 ;;
esac
case $1 in
*=*) case $RANDOM in
$RANDOM)`echo $1 | sed "s/\\([^=]*\\)=\\(.*\\)/eval \\1='\\2'; export \\1/"` ;;
*) export "$1" ;;
*=*) case $modern_export in
ok) export "$1" ;;
*) `echo $1 | sed "s/\\([^=]*\\)=\\(.*\\)/eval \\1='\\2'; export \\1/"` ;;
esac
shift
;;

View file

@ -19,6 +19,8 @@
########################################################################
: cross compiler a.out execution
(set -o posix) 2>/dev/null && set -o posix
command=crossexec
tmp=/tmp/cross$$

View file

@ -19,6 +19,8 @@
########################################################################
: wrapper for .exe challenged win32 systems/commands
(set -o posix) 2>/dev/null && set -o posix
command=execrate
bins=`

View file

@ -19,6 +19,8 @@
########################################################################
: convert command that operates on file args to pipeline filter
(set -o posix) 2>/dev/null && set -o posix
command=filter
TMPDIR=${TMPDIR:-/tmp}

View file

@ -19,6 +19,8 @@
########################################################################
: copy http url data
(set -o posix) 2>/dev/null && set -o posix
command=hurl
agent="$command/2009-01-20 (AT&T Research)"
authorize=

View file

@ -25,9 +25,7 @@
#
# NOTE: .exe a.out suffix and [\\/] in path patterns for dos/nt
case $-:$BASH_VERSION in
*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
esac
(set -o posix) 2>/dev/null && set -o posix
command=iffe
version=2012-07-17 # update in USAGE too #

View file

@ -20,18 +20,17 @@
# non-ksh script for the nmake ignore prefix
# @(#)ignore (AT&T Research) 1992-08-11
case $-:$BASH_VERSION in
*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
esac
(set -o posix) 2>/dev/null && set -o posix
modern_export=`v=; export v=ok 2>/dev/null; echo "$v"`
while :
do case $# in
0) exit 0 ;;
esac
case $1 in
*=*) case $RANDOM in
$RANDOM)`echo $1 | sed "s/\\([^=]*\\)=\\(.*\\)/eval \\1='\\2'; export \\1/"` ;;
*) export "$1" ;;
*=*) case $modern_export in
ok) export "$1" ;;
*) `echo $1 | sed "s/\\([^=]*\\)=\\(.*\\)/eval \\1='\\2'; export \\1/"` ;;
esac
shift
;;

View file

@ -21,9 +21,7 @@
# mamprobe - generate MAM cc probe info
# Glenn Fowler <gsf@research.att.com>
case $-:$BASH_VERSION in
*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
esac
(set -o posix) 2>/dev/null && set -o posix
command=mamprobe

View file

@ -19,7 +19,10 @@
# #
########################################################################
: mkdir for systems that do not support -p : 2002-09-01 :
MKDIR=/bin/mkdir
(set -o posix) 2>/dev/null && set -o posix
MKDIR=mkdir
CHMOD=chmod
mode=
parents=

View file

@ -23,38 +23,34 @@
command=package
case $-:$BASH_VERSION in
*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
(set -o posix) 2>/dev/null && set -o posix
path=Bad
case $PATH in
Bad*) echo "Cannot be run by zsh in native mode; use a sh symlink to zsh" >&2
exit 1 ;;
esac
# ksh checks -- ksh between 2007-11-05 and 2011-11-11 conflict with new -lcmd -- wea culpa
# shell checks
checksh()
{
egrep 'Version.*(88|1993)' $1 >/dev/null 2>&1 ||
PATH=/dev/null $1 -c '(( 2 + 2 ))' >/dev/null 2>&1 &&
$1 -c '(( .sh.version >= 20111111 ))' >/dev/null 2>&1
"$1" -ec '
# reject csh
case 1 in
1) ;;
esac
# reject special use of $path (to use zsh, use a "sh -> zsh" symlink, which disables this)
path=Bad
case $PATH in
Bad*) exit 1 ;;
esac
# catch (our own) pipe/socket configuration mismatches
date | "$1" -c "read x" || exit 1
# check Bourne/POSIX compatible trap exit status (should exit with status 0)
trap "exit 0" 0
exit 1
' x "$1" 2>/dev/null || return 1
}
case $_AST_BIN_PACKAGE_:$SHELL:$0 in
1:*:*|*:/bin/sh:*)
;;
*:*/*:*/*)
_AST_BIN_PACKAGE_=1 # prevent non-interactive sh .rc referencing bin/package recursion #
export _AST_BIN_PACKAGE_
if checksh $SHELL
then : no -lcmd conflict :
else case " $* " in
*" debug "*|*" DEBUG "*|*" show "*)
echo $command: $SHELL: warning: possible -lcmd conflict -- falling back to /bin/sh >&2
;;
esac
SHELL=/bin/sh
export SHELL
exec $SHELL "$0" "$@"
fi
;;
esac
LC_ALL=C
export LC_ALL
@ -3102,26 +3098,7 @@ cat $INITROOT/$i.sh
;;
esac
;;
esac
# $SHELL must be /bin/sh compatible
case $SHELL in
/bin/sh);;
'') SHELL=/bin/sh
;;
*) $SHELL -c 'trap "exit 0" 0; exit 1' 2>/dev/null
case $? in
1) SHELL=/bin/sh
;;
*) # catch (our own) pipe/socket configuration mismatches
$SHELL -c "date | $SHELL -c 'read x'"
case $? in
0) ;;
*) SHELL=/bin/sh ;;
esac
;;
esac
*) checksh $SHELL || SHELL=/bin/sh
;;
esac
export SHELL

View file

@ -20,18 +20,17 @@
# non-ksh stub for the nmake silent prefix
# @(#)silent (AT&T Research) 1992-08-11
case $-:$BASH_VERSION in
*x*:[01234567899]*) : bash set -x is broken :; set +ex ;;
esac
(set -o posix) 2>/dev/null && set -o posix
modern_export=`v=; export v=ok 2>/dev/null; echo "$v"`
while :
do case $# in
0) exit 0 ;;
esac
case $1 in
*=*) case $RANDOM in
$RANDOM)`echo $1 | sed "s/\\([^=]*\\)=\\(.*\\)/eval \\1='\\2'; export \\1/"` ;;
*) export "$1" ;;
*=*) case $modern_export in
ok) export "$1" ;;
*) `echo $1 | sed "s/\\([^=]*\\)=\\(.*\\)/eval \\1='\\2'; export \\1/"` ;;
esac
shift
;;

View file

@ -22,6 +22,11 @@
# @(#)math.sh (AT&T Research) 2012-06-13
case $ZSH_VERSION in
?*) emulate ksh ;;
*) (set -o posix) 2>/dev/null && set -o posix ;;
esac
command=$0
iffeflags="-n -v"
iffehdrs="math.h"

View file

@ -34,8 +34,9 @@
# but you shall be confused anyway
#
case $-:$BASH_VERSION in
*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
case $ZSH_VERSION in
?*) emulate ksh ;;
*) (set -o posix) 2>/dev/null && set -o posix ;;
esac
LC_ALL=C

View file

@ -19,6 +19,12 @@
# Phong Vo <kpv@research.att.com> #
# #
########################################################################
case $ZSH_VERSION in
?*) emulate ksh ;;
*) (set -o posix) 2>/dev/null && set -o posix ;;
esac
ok=0
for i in \
-x /lib/ld.so /lib/ld-*.so /usr/lib/ld.so /lib/rld \

View file

@ -20,6 +20,12 @@
# #
########################################################################
: generate "<sys/param.h> + <sys/types.h> + <sys/stat.h>" include sequence
case $ZSH_VERSION in
?*) emulate ksh ;;
*) (set -o posix) 2>/dev/null && set -o posix ;;
esac
case $# in
0) ;;
*) eval $1

View file

@ -20,6 +20,12 @@
# #
########################################################################
: generate preroot features
case $ZSH_VERSION in
?*) emulate ksh ;;
*) (set -o posix) 2>/dev/null && set -o posix ;;
esac
case $# in
0) ;;
*) eval $1

View file

@ -20,6 +20,12 @@
# #
########################################################################
: generate sig features
case $ZSH_VERSION in
?*) emulate ksh ;;
*) (set -o posix) 2>/dev/null && set -o posix ;;
esac
case $# in
0) ;;
*) eval $1