spiegel-keyman/mac/bashHelperFunctions.sh
Marc Durdin 767927bf16 chore(common): use /usr/bin/env bash
Fixes up scripts (except under /linux) to use `#!/usr/bin/env bash`
instead of `#!/bin/bash` or `#!/bin/sh` so that we don't end up with
the ancient version of bash supplied with macOS.

This became urgent with this PR, because of bash-4.xisms in
build-utils.sh, for example on line 572:

```
if [[ -v _builder_params[$e] ]]; then
```
2022-07-25 14:59:37 +10:00

44 lines
No EOL
1 KiB
Bash
Executable file

#!/usr/bin/env bash
# TODO: deprecate and replace with shellHelperFunctions.sh.
# The following allows coloring of warning and error lines, but only works if there's a
# terminal attached, so not on the build machine.
if ! [[ "$TERM" == "" || "$TERM" == "dumb" ]]; then
ERROR_RED=$(tput setaf 1)
WARNING_YELLOW=$(tput setaf 3)
NORMAL=$(tput sgr0)
fi
fail() {
FAILURE_MSG="$1"
if [[ "$FAILURE_MSG" == "" ]]; then
FAILURE_MSG="Unknown failure"
fi
echo "${ERROR_RED}$FAILURE_MSG${NORMAL}"
exit 1
}
warn() { echo "${WARNING_YELLOW}$*${NORMAL}"; }
displayInfo() {
if [ "$QUIET" != true ]; then
while [[ $# -gt 0 ]] ; do
echo $1
shift # past argument
done
fi
}
assertFileExists() {
if ! [ -f $1 ]; then
fail "Build failed: missing $1"
fi
}
assertValidVersionNbr()
{
if [[ "$1" == "" || ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
fail "Specified version not valid: '$1'. Version should be in the form Major.Minor.BuildCounter"
fi
}