Merge branch 'master' of github.com:kvz/bash3boilerplate

This commit is contained in:
Kevin van Zonneveld 2019-11-05 09:32:59 +01:00
commit 8146667ea1
13 changed files with 5086 additions and 3224 deletions

39
.gitignore vendored
View File

@ -1,23 +1,20 @@
npm-debug.log
node_modules
website/index.md
website/_site/
website/_vendor/
website/changelog.md
website/faq.md
website/.jekyll-metadata
env.sh
website/main.sh
website/assets/build
website/.lanyon
website/.lanyon/vendor/bin
website/.lanyon/bin
assets/build
.jekyll-cache/
.jekyll-metadata
.lanyon
.lanyon/bin
assets/build
env.sh
node_modules
npm-debug.log
website/_site/
website/_vendor/
website/.jekyll-metadata
website/.lanyon
website/.lanyon/bin
website/.lanyon/vendor/bin
website/assets/build
website/changelog.md
website/faq.md
website/index.md
website/main.shwebsite/.lanyon
website/main.sh

59
.lanyonrc.js Normal file
View File

@ -0,0 +1,59 @@
const path = require('path')
const _ = require('lodash')
module.exports.overrideRuntime = function ({ runtime, toolkit }) {
let preBuilds = []
let postBuilds = []
if (!runtime.isDev) {
preBuilds = preBuilds.concat([
'npm run inject',
])
postBuilds = postBuilds.concat([
// 'npm run redirects',
])
}
// "lanyon": {
// "projectDir": "website",
// "contentScandir": "../",
// "contentIgnore": [
// "website/*.md",
// "website/main.sh"
// ]
// },
// runtime['npmRoot'] = `${__dirname}`
runtime.projectDir = `${__dirname}/website`
runtime.cacheDir = path.join(runtime.projectDir, '.lanyon')
runtime.recordsPath = path.join(runtime.cacheDir, 'records.json')
runtime.assetsSourceDir = path.join(runtime.projectDir, 'assets')
runtime.assetsBuildDir = path.join(runtime.assetsSourceDir, 'build')
runtime.contentScandir = path.join(runtime.projectDir, runtime.contentScandir || '.')
runtime.contentBuildDir = path.join(runtime.projectDir, '_site')
runtime['prebuild:content'] = preBuilds.join(' && ')
runtime['postbuild:content'] = postBuilds.join(' && ')
return runtime
}
module.exports.overrideConfig = function ({ config, toolkit }) {
if (config.runtime.isDev) {
config.jekyll.url = 'http://localhost:3000'
}
config.jekyll.profile = true
config.jekyll.trace = true
if (config.runtime.isDev) {
config.jekyll.unpublished = true
config.jekyll.future = true
config.jekyll.incremental = true // <-- for clarify; incremental is the default also
} else {
config.jekyll.incremental = false
}
return config
}

View File

@ -3,10 +3,10 @@ matrix:
- os: linux
sudo: false
language: node_js
node_js: 6
node_js: 10
- os: osx
language: node_js
node_js: 6
node_js: 10
env:
global:
- SCROLEX_MODE=passthru
@ -18,13 +18,10 @@ addons:
apt:
sources:
- debian-sid
install:
- npm install
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then npm run install:lanyon; fi
before_install:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get install --allow-unauthenticated -y cabal-install; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cabal update; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cabal install shellcheck; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cabal v1-install ShellCheck; 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 gtimeout || brew install coreutils; fi
@ -33,10 +30,10 @@ before_install:
- awk --version
before_cache:
- rm -f ./node_modules/.bin/which
cache:
apt: true
directories:
- .lanyon
# cache:
# apt: true
# directories:
# - .lanyon
script: test/acceptance.sh
deploy:
skip_cleanup: true

View File

@ -124,18 +124,16 @@ info "arg_f: ${arg_f}"
info "arg_d: ${arg_d}"
info "arg_v: ${arg_v}"
info "arg_h: ${arg_h}"
if [[ -v arg_i ]]
then
if [[ -n "${arg_i:-}" ]]; then
info "arg_i: ${#arg_i[@]}"
for input_file in "${arg_i[@]}"
do
for input_file in "${arg_i[@]}"; do
info " - ${input_file}"
done
else
info "arg_i: 0"
fi
# shellcheck disable=SC2015
[[ -v arg_x ]] && info "arg_x: ${#arg_x[@]}" || info "arg_x: 0"
[[ -n "${arg_x:-}" ]] && info "arg_x: ${#arg_x[@]}" || info "arg_x: 0"
info "$(echo -e "multiple lines example - line #1\\nmultiple lines example - line #2\\nimagine logging the output of 'ls -al /path/'")"

45
main.sh
View File

@ -203,13 +203,15 @@ while read -r __b3bp_tmp_line; do
if [[ "${__b3bp_tmp_line}" =~ ^Default= ]] || [[ "${__b3bp_tmp_line}" =~ \.\ *Default= ]]; then
# ignore default value if option does not have an argument
__b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}"
if [[ "${!__b3bp_tmp_varname}" != "0" ]]; then
# take default
__b3bp_tmp_init="${__b3bp_tmp_line##*Default=}"
# strip double quotes from default argument
__b3bp_tmp_re='^"(.*)"$'
if [[ "${__b3bp_tmp_init}" =~ ${__b3bp_tmp_re} ]]; then
__b3bp_tmp_init="${BASH_REMATCH[1]}"
else
# strip single quotes from default argument
__b3bp_tmp_re="^'(.*)'$"
if [[ "${__b3bp_tmp_init}" =~ ${__b3bp_tmp_re} ]]; then
__b3bp_tmp_init="${BASH_REMATCH[1]}"
@ -223,6 +225,7 @@ while read -r __b3bp_tmp_line; do
printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2"
fi
# Init var with value unless it is an array / a repeatable
__b3bp_tmp_varname="__b3bp_tmp_is_array_${__b3bp_tmp_opt:0:1}"
[[ "${!__b3bp_tmp_varname}" = "0" ]] && printf -v "arg_${__b3bp_tmp_opt:0:1}" '%s' "${__b3bp_tmp_init}"
done <<< "${__usage:-}"
@ -271,12 +274,22 @@ if [[ "${__b3bp_tmp_opts:-}" ]]; then
__b3bp_tmp_varname="__b3bp_tmp_is_array_${__b3bp_tmp_opt:0:1}"
if [[ "${!__b3bp_tmp_varname}" != "0" ]]; then
__b3bp_tmp_varname="arg_${__b3bp_tmp_opt:0:1}[@]"
# repeatables
# shellcheck disable=SC2016
declare -a "${__b3bp_tmp_varname}"='("${!__b3bp_tmp_varname}" "${__b3bp_tmp_value}")'
debug "cli arg ${__b3bp_tmp_varname} append ${__b3bp_tmp_value}"
if [[ -z "${OPTARG}" ]]; then
# repeatable flags, they increcemnt
__b3bp_tmp_varname="arg_${__b3bp_tmp_opt:0:1}"
debug "cli arg ${__b3bp_tmp_varname} = (${__b3bp_tmp_default}) -> ${!__b3bp_tmp_varname}"
__b3bp_tmp_value=$((${!__b3bp_tmp_varname} + 1))
printf -v "${__b3bp_tmp_varname}" '%s' "${__b3bp_tmp_value}"
else
# repeatable args, they get appended to an array
__b3bp_tmp_varname="arg_${__b3bp_tmp_opt:0:1}[@]"
debug "cli arg ${__b3bp_tmp_varname} append ${__b3bp_tmp_value}"
declare -a "${__b3bp_tmp_varname}"='("${!__b3bp_tmp_varname}" "${__b3bp_tmp_value}")'
fi
else
# non-repeatables
__b3bp_tmp_varname="arg_${__b3bp_tmp_opt:0:1}"
__b3bp_tmp_default="${!__b3bp_tmp_varname}"
@ -285,6 +298,7 @@ if [[ "${__b3bp_tmp_opts:-}" ]]; then
fi
printf -v "${__b3bp_tmp_varname}" '%s' "${__b3bp_tmp_value}"
debug "cli arg ${__b3bp_tmp_varname} = (${__b3bp_tmp_default}) -> ${!__b3bp_tmp_varname}"
fi
done
@ -404,18 +418,27 @@ info "arg_f: ${arg_f}"
info "arg_d: ${arg_d}"
info "arg_v: ${arg_v}"
info "arg_h: ${arg_h}"
if [[ -v arg_i ]]
then
info "arg_i: ${#arg_i[@]}"
for input_file in "${arg_i[@]}"
do
# shellcheck disable=SC2015
if [[ -n "${arg_i:-}" ]] && declare -p arg_i 2> /dev/null | grep -q '^declare \-a'; then
info "arg_i:"
for input_file in "${arg_i[@]}"; do
info " - ${input_file}"
done
elif [[ -n "${arg_i:-}" ]]; then
info "arg_i: ${arg_i}"
else
info "arg_i: 0"
fi
# shellcheck disable=SC2015
[[ -v arg_x ]] && info "arg_x: ${#arg_x[@]}" || info "arg_x: 0"
if [[ -n "${arg_x:-}" ]] && declare -p arg_x 2> /dev/null | grep -q '^declare \-a'; then
info "arg_x: ${#arg_x[@]}"
elif [[ -n "${arg_x:-}" ]]; then
info "arg_x: ${arg_x}"
else
info "arg_x: 0"
fi
info "$(echo -e "multiple lines example - line #1\\nmultiple lines example - line #2\\nimagine logging the output of 'ls -al /path/'")"

View File

@ -7,41 +7,33 @@
"build": "lanyon build",
"deploy": "lanyon deploy",
"encrypt": "lanyon encrypt",
"inject": "./_scripts/inject.sh",
"install:lanyon": "lanyon install",
"lint": "shellcheck --shell=bash $(find . -name '*.sh' -maxdepth 2)",
"release:major": "env SEMANTIC=major npm run release",
"release:minor": "env SEMANTIC=minor npm run release",
"release:patch": "env SEMANTIC=patch npm run release",
"release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && npm run version:replace && git commit main.sh src/*.sh -m 'Update version' && git push && git push --tags && npm publish",
"save:fixtures": "cross-env SAVE_FIXTURES=true npm run test",
"serve:production": "LANYON_ENV=production lanyon serve",
"start:production": "npm-run-all build:production serve:production",
"start": "lanyon start",
"test:debug:main:repeated": "cross-env LOG_LEVEL=7 test/acceptance.sh main-repeated",
"test:update": "cross-env SAVE_FIXTURES=true npm run test",
"test": "test/acceptance.sh",
"upgrade:modules": "next-update --keep true --tldr",
"version:current": "node -e 'console.log(require(\"./package.json\").version)'",
"version:replace": "replace 'v\\d+\\.\\d+\\.\\d+' \"v$(npm run --silent version:current)\" main.sh src/*.sh"
},
"lanyon": {
"projectDir": "website",
"prebuild": "./_scripts/inject.sh",
"contentScandir": "../",
"contentIgnore": [
"website/*.md",
"website/main.sh"
]
},
"optionalDependencies": {
"fsevents": "*"
},
"dependencies": {},
"devDependencies": {
"browser-sync": "2.18.5",
"cross-env": "3.1.3",
"fakefile": "0.0.8",
"lanyon": "0.0.92",
"lanyon": "0.1.7",
"next-update": "1.5.1",
"npm-run-all": "3.1.2",
"replace": "^0.3.0"
"replace": "0.3.0"
}
}

View File

@ -98,7 +98,7 @@ while IFS=$'\n' read -r scenario; do
-e "s@${USER:-travis}@{user}@g" "${curFile}" \
-e "s@travis@{user}@g" "${curFile}" \
-e "s@kvz@{user}@g" "${curFile}" \
-e "s@{root}/node_modules/\.bin/node@{node}@g" "${curFile}" \
-e "s@{root}/node_modules/\\.bin/node@{node}@g" "${curFile}" \
-e "s@{home}/build/{user}/fre{node}@{node}@g" "${curFile}" \
-e "s@${HOSTNAME}@{hostname}@g" "${curFile}" \
-e "s@${__arch}@{arch}@g" "${curFile}" \
@ -198,6 +198,9 @@ done <<< "$(find "${__dir}/scenario" -type f -iname 'run.sh')"
# shellcheck disable=SC2230
# "command -v" is not a substitute for "which -a"
while IFS=$'\n' read -r bash; do
if [[ "${bash:-}" = "" ]]; then
continue
fi
# shellcheck disable=SC2016
echo "==> ${bash} -n $(${bash} -c 'echo "(${BASH_VERSION})"')"
pushd "${__root}" > /dev/null
@ -229,14 +232,14 @@ done <<< "$(which -a bash 2>/dev/null)"
# do some shellcheck linting
if [[ "$(command -v shellcheck)" ]]; then
echo "==> Shellcheck"
echo "==> ShellCheck"
pushd "${__root}" > /dev/null
failed="false"
while IFS=$'\n' read -r file; do
[[ "${file}" =~ ^\./node_modules/ ]] && continue
[[ "${file}" =~ ^\./website/\.lanyon/ ]] && continue
[[ "${file}" =~ ^\./website/ ]] && continue
echo -n " ${file}.. "

View File

@ -20,6 +20,6 @@ ACCPTST:STDIO_REPLACE_DATETIMES
{datetime} UTC [ warning] 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 [ error] Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time.
{datetime} UTC [ critical] Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection.
{datetime} UTC [ alert] 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 [emergency] A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
{datetime} UTC [ alert] 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 [emergency] A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
{datetime} UTC [ info] Cleaning up. Done

View File

@ -20,6 +20,6 @@ ACCPTST:STDIO_REPLACE_DATETIMES
{datetime} UTC [ warning] 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 [ error] Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time.
{datetime} UTC [ critical] Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection.
{datetime} UTC [ alert] 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 [emergency] A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
{datetime} UTC [ alert] 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 [emergency] A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
{datetime} UTC [ info] Cleaning up. Done

View File

@ -1,5 +1,5 @@
ACCPTST:STDIO_REPLACE_DATETIMES
{datetime} UTC [ info] arg_i: 5
{datetime} UTC [ info] arg_i:
{datetime} UTC [ info] - simple_input
{datetime} UTC [ info] - input_in_quotes
{datetime} UTC [ info] - input with spaces

View File

@ -10,10 +10,10 @@ __root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
(
env LOG_LEVEL=6 bash "${__root}/main.sh" -f dummy -i simple_input -i "input_in_quotes" -i "input with spaces" -i "input with \"quotes\"" -i last_input
env LOG_LEVEL="${LOG_LEVEL:-6}" bash "${__root}/main.sh" -f dummy -i simple_input -i "input_in_quotes" -i "input with spaces" -i "input with \"quotes\"" -i last_input
) 2>&1 |grep arg_i -A 5
(
env LOG_LEVEL=6 bash "${__root}/main.sh" -x -f dummy -x -x
env LOG_LEVEL=6 bash "${__root}/main.sh" -f dummy -xxxx
env LOG_LEVEL="${LOG_LEVEL:-6}" bash "${__root}/main.sh" -x -f dummy -x -x
env LOG_LEVEL="${LOG_LEVEL:-6}" bash "${__root}/main.sh" -f dummy -xxxx
) 2>&1 |grep arg_x

View File

@ -1,4 +1,4 @@
title: BASH3 Boilerplate
gems:
plugins:
- jekyll-redirect-from

8097
yarn.lock

File diff suppressed because it is too large Load Diff