mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-02-28 17:38:32 +00:00
Merge pull request #87 from kvz/fixup-after-230
fixup example.sh like 2.3.0 main.sh
This commit is contained in:
commit
9b86dcced8
@ -25,6 +25,8 @@ install:
|
|||||||
before_install:
|
before_install:
|
||||||
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
|
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
|
||||||
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then which gsed || brew install gnu-sed; fi
|
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then which gsed || brew install gnu-sed; fi
|
||||||
|
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then which gtimeout || brew install coreutils; fi
|
||||||
|
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then which bundle || gem install bundler; fi
|
||||||
- bash --version
|
- bash --version
|
||||||
- awk --version
|
- awk --version
|
||||||
before_cache:
|
before_cache:
|
||||||
|
3
FAQ.md
3
FAQ.md
@ -96,9 +96,10 @@ Somewhat inconsistent – but true to Unix ancestry – the abbreviation for our
|
|||||||
|
|
||||||
## How can I locally develop and preview the b3bp website?
|
## How can I locally develop and preview the b3bp website?
|
||||||
|
|
||||||
You should have a working Node.js >=10 and Ruby >=2 install on your workstation. When that is the case, you can run:
|
You should have a working Node.js >=10, Ruby >=2 and [YARN](https://yarnpkg.com) install on your workstation. When that is the case, you can run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
yarn install
|
||||||
npm run start
|
npm run start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
29
example.sh
29
example.sh
@ -7,7 +7,7 @@
|
|||||||
#
|
#
|
||||||
# LOG_LEVEL=7 ./example.sh -f /tmp/x -d (change this for your script)
|
# LOG_LEVEL=7 ./example.sh -f /tmp/x -d (change this for your script)
|
||||||
#
|
#
|
||||||
# Based on a template by BASH3 Boilerplate v2.2.0
|
# Based on a template by BASH3 Boilerplate v2.3.0
|
||||||
# http://bash3boilerplate.sh/#authors
|
# http://bash3boilerplate.sh/#authors
|
||||||
#
|
#
|
||||||
# The MIT License (MIT)
|
# The MIT License (MIT)
|
||||||
@ -47,6 +47,25 @@ EOF
|
|||||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/main.sh"
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/main.sh"
|
||||||
|
|
||||||
|
|
||||||
|
### Signal trapping and backtracing
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
function __b3bp_cleanup_before_exit () {
|
||||||
|
info "Cleaning up. Done"
|
||||||
|
}
|
||||||
|
trap __b3bp_cleanup_before_exit EXIT
|
||||||
|
|
||||||
|
# requires `set -o errtrace`
|
||||||
|
__b3bp_err_report() {
|
||||||
|
local error_code
|
||||||
|
error_code=${?}
|
||||||
|
error "Error in ${__file} in function ${1} on line ${2}"
|
||||||
|
exit ${error_code}
|
||||||
|
}
|
||||||
|
# Uncomment the following line for always providing an error backtrace
|
||||||
|
# trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
|
||||||
|
|
||||||
|
|
||||||
### Command-line argument switches (like -d for debugmode, -h for showing helppage)
|
### Command-line argument switches (like -d for debugmode, -h for showing helppage)
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
@ -54,6 +73,8 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/main.sh"
|
|||||||
if [[ "${arg_d:?}" = "1" ]]; then
|
if [[ "${arg_d:?}" = "1" ]]; then
|
||||||
set -o xtrace
|
set -o xtrace
|
||||||
LOG_LEVEL="7"
|
LOG_LEVEL="7"
|
||||||
|
# Enable error backtracing
|
||||||
|
trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# verbose mode
|
# verbose mode
|
||||||
@ -83,11 +104,7 @@ fi
|
|||||||
### Runtime
|
### Runtime
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
function cleanup_before_exit () {
|
info "__i_am_main_script: ${__i_am_main_script}"
|
||||||
info "Cleaning up. Done"
|
|
||||||
}
|
|
||||||
trap cleanup_before_exit EXIT
|
|
||||||
|
|
||||||
info "__file: ${__file}"
|
info "__file: ${__file}"
|
||||||
info "__dir: ${__dir}"
|
info "__dir: ${__dir}"
|
||||||
info "__base: ${__base}"
|
info "__base: ${__base}"
|
||||||
|
16
main.sh
16
main.sh
@ -27,11 +27,18 @@ set -o pipefail
|
|||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
|
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
|
||||||
|
__i_am_main_script="0" # false
|
||||||
|
|
||||||
if [[ "${__usage+x}" ]]; then
|
if [[ "${__usage+x}" ]]; then
|
||||||
|
if [[ "${BASH_SOURCE[1]}" = "${0}" ]]; then
|
||||||
|
__i_am_main_script="1" # true
|
||||||
|
fi
|
||||||
|
|
||||||
__b3bp_external_usage="true"
|
__b3bp_external_usage="true"
|
||||||
__b3bp_tmp_source_idx=1
|
__b3bp_tmp_source_idx=1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
__i_am_main_script="1" # true
|
||||||
[[ "${__usage+x}" ]] && unset -v __usage
|
[[ "${__usage+x}" ]] && unset -v __usage
|
||||||
[[ "${__helptext+x}" ]] && unset -v __helptext
|
[[ "${__helptext+x}" ]] && unset -v __helptext
|
||||||
fi
|
fi
|
||||||
@ -40,11 +47,7 @@ fi
|
|||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")"
|
__file="${__dir}/$(basename "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")"
|
||||||
__base="$(basename "${__file}" .sh)"
|
__base="$(basename "${__file}" .sh)"
|
||||||
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
|
|
||||||
__i_am_main_script="0" # false
|
|
||||||
else
|
|
||||||
__i_am_main_script="1" # true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Define the environment variables (and their defaults) that this script depends on
|
# Define the environment variables (and their defaults) that this script depends on
|
||||||
LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency
|
LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency
|
||||||
@ -308,6 +311,7 @@ if [[ "${__b3bp_external_usage:-}" = "true" ]]; then
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
### Signal trapping and backtracing
|
### Signal trapping and backtracing
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
@ -326,6 +330,7 @@ __b3bp_err_report() {
|
|||||||
# Uncomment the following line for always providing an error backtrace
|
# Uncomment the following line for always providing an error backtrace
|
||||||
# trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
|
# trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
|
||||||
|
|
||||||
|
|
||||||
### Command-line argument switches (like -d for debugmode, -h for showing helppage)
|
### Command-line argument switches (like -d for debugmode, -h for showing helppage)
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
@ -364,6 +369,7 @@ fi
|
|||||||
### Runtime
|
### Runtime
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
info "__i_am_main_script: ${__i_am_main_script}"
|
||||||
info "__file: ${__file}"
|
info "__file: ${__file}"
|
||||||
info "__dir: ${__dir}"
|
info "__dir: ${__dir}"
|
||||||
info "__base: ${__base}"
|
info "__base: ${__base}"
|
||||||
|
@ -193,7 +193,41 @@ done <<< "$(find "${__dir}/scenario" -type f -iname 'run.sh')"
|
|||||||
|
|
||||||
[[ "${1:-}" ]] && exit 0
|
[[ "${1:-}" ]] && exit 0
|
||||||
|
|
||||||
# finally do some shellcheck linting
|
# Ensure correct syntax with all available bashes
|
||||||
|
|
||||||
|
if bashes=($(which -a bash 2> /dev/null )); then
|
||||||
|
for bash in "${bashes[@]}"; do
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
echo "==> ${bash} -n $(${bash} -c 'echo "(${BASH_VERSION})"')"
|
||||||
|
pushd "${__root}" > /dev/null
|
||||||
|
|
||||||
|
failed="false"
|
||||||
|
|
||||||
|
while IFS=$'\n' read -r file; do
|
||||||
|
[[ "${file}" =~ ^\./node_modules/ ]] && continue
|
||||||
|
[[ "${file}" =~ ^\./website/\.lanyon/ ]] && continue
|
||||||
|
|
||||||
|
echo -n " ${file}.. "
|
||||||
|
|
||||||
|
if ! "${bash}" -n "${file}" 2>> "${__accptstTmpDir}/${bash//\//.}.err"; then
|
||||||
|
echo "✗"
|
||||||
|
failed="true"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✓"
|
||||||
|
done <<< "$(find . -type f -iname '*.sh')"
|
||||||
|
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
|
if [[ "${failed}" = "true" ]]; then
|
||||||
|
cat "${__accptstTmpDir}/${bash//\//.}.err"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# do some shellcheck linting
|
||||||
if [[ "$(command -v shellcheck)" ]]; then
|
if [[ "$(command -v shellcheck)" ]]; then
|
||||||
echo "==> Shellcheck"
|
echo "==> Shellcheck"
|
||||||
pushd "${__root}" > /dev/null
|
pushd "${__root}" > /dev/null
|
||||||
|
1
test/fixture/double-source.exitcode
Normal file
1
test/fixture/double-source.exitcode
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
23
test/fixture/double-source.stdio
Normal file
23
test/fixture/double-source.stdio
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
ACCPTST:STDIO_REPLACE_DATETIMES
|
||||||
|
{datetime} UTC [35m[ debug][0m cli arg arg_f = () -> {tmpdir}/x
|
||||||
|
{datetime} UTC [32m[ info][0m __i_am_main_script: 0
|
||||||
|
{datetime} UTC [32m[ info][0m __file: {root}/example.sh
|
||||||
|
{datetime} UTC [32m[ info][0m __dir: {root}
|
||||||
|
{datetime} UTC [32m[ info][0m __base: example
|
||||||
|
{datetime} UTC [32m[ info][0m OSTYPE: {OSTYPE}
|
||||||
|
{datetime} UTC [32m[ info][0m arg_f: {tmpdir}/x
|
||||||
|
{datetime} UTC [32m[ info][0m arg_d: 0
|
||||||
|
{datetime} UTC [32m[ info][0m arg_v: 0
|
||||||
|
{datetime} UTC [32m[ info][0m arg_h: 0
|
||||||
|
{datetime} UTC [32m[ info][0m multiple lines example - line #1
|
||||||
|
{datetime} UTC [32m[ info][0m multiple lines example - line #2
|
||||||
|
{datetime} UTC [32m[ info][0m imagine logging the output of 'ls -al /path/'
|
||||||
|
{datetime} UTC [35m[ debug][0m Info useful to developers for debugging the application, not useful during operations.
|
||||||
|
{datetime} UTC [32m[ info][0m Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required.
|
||||||
|
{datetime} UTC [34m[ notice][0m Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required.
|
||||||
|
{datetime} UTC [33m[ warning][0m Warning messages, not an error, but indication that an error will occur if action is not taken, e.g. file system 85% full - each item must be resolved within a given time. This is a debug message
|
||||||
|
{datetime} UTC [31m[ error][0m Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time.
|
||||||
|
{datetime} UTC [1;31m[ critical][0m Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection.
|
||||||
|
{datetime} UTC [1;33;41m[ alert][0m Should be corrected immediately, therefore notify staff who can fix the problem. An example would be the loss of a primary ISP connection.
|
||||||
|
{datetime} UTC [1;4;5;33;41m[emergency][0m A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
|
||||||
|
{datetime} UTC [32m[ info][0m Cleaning up. Done
|
@ -1,5 +1,6 @@
|
|||||||
ACCPTST:STDIO_REPLACE_DATETIMES
|
ACCPTST:STDIO_REPLACE_DATETIMES
|
||||||
{datetime} UTC [35m[ debug][0m cli arg arg_f = () -> {tmpdir}/x
|
{datetime} UTC [35m[ debug][0m cli arg arg_f = () -> {tmpdir}/x
|
||||||
|
{datetime} UTC [32m[ info][0m __i_am_main_script: 1
|
||||||
{datetime} UTC [32m[ info][0m __file: {root}/main.sh
|
{datetime} UTC [32m[ info][0m __file: {root}/main.sh
|
||||||
{datetime} UTC [32m[ info][0m __dir: {root}
|
{datetime} UTC [32m[ info][0m __dir: {root}
|
||||||
{datetime} UTC [32m[ info][0m __base: main
|
{datetime} UTC [32m[ info][0m __base: main
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
ACCPTST:STDIO_REPLACE_DATETIMES
|
ACCPTST:STDIO_REPLACE_DATETIMES
|
||||||
{datetime} UTC [ debug] cli arg arg_f = () -> {tmpdir}/x
|
{datetime} UTC [ debug] cli arg arg_f = () -> {tmpdir}/x
|
||||||
|
{datetime} UTC [ info] __i_am_main_script: 1
|
||||||
{datetime} UTC [ info] __file: {root}/main.sh
|
{datetime} UTC [ info] __file: {root}/main.sh
|
||||||
{datetime} UTC [ info] __dir: {root}
|
{datetime} UTC [ info] __dir: {root}
|
||||||
{datetime} UTC [ info] __base: main
|
{datetime} UTC [ info] __base: main
|
||||||
|
15
test/scenario/double-source/run.sh
Normal file
15
test/scenario/double-source/run.sh
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -o pipefail
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
|
|
||||||
|
export LOG_LEVEL=7
|
||||||
|
|
||||||
|
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||||
|
|
||||||
|
# shellcheck source=example.sh
|
||||||
|
source "${__root}/example.sh" -f /tmp/x
|
@ -9,4 +9,4 @@ __root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
|||||||
|
|
||||||
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||||
|
|
||||||
env LOG_LEVEL=8 bash "${__root}/main.sh" -f /tmp/x
|
env LOG_LEVEL=7 bash "${__root}/main.sh" -f /tmp/x
|
||||||
|
@ -9,4 +9,4 @@ __root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
|||||||
|
|
||||||
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||||
|
|
||||||
env LOG_LEVEL=8 NO_COLOR=true bash "${__root}/main.sh" -f /tmp/x
|
env LOG_LEVEL=7 NO_COLOR=true bash "${__root}/main.sh" -f /tmp/x
|
||||||
|
Loading…
x
Reference in New Issue
Block a user