diff --git a/CHANGELOG.md b/CHANGELOG.md index 177a666..db9b98b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Released: Unreleased. [Commit log](https://github.com/kvz/bash3boilerplate/compare/v2.0.0...master) +- Less verbose header comments - For delete-key-friendliness, don't crash on undeclared help vars - Introduce `errtrace`, which is on by default (BREAKING) - Add a configurable `helptext` that is left alone by the parses and allows you to have a richer help diff --git a/main.sh b/main.sh index 3a772d6..4730e76 100755 --- a/main.sh +++ b/main.sh @@ -1,37 +1,15 @@ #!/usr/bin/env bash -# BASH3 Boilerplate -# # This file: # -# - Is a template to write better bash scripts -# - Is delete-key friendly, in case you don't need e.g. command line option parsing -# -# More info: -# -# - https://github.com/kvz/bash3boilerplate -# - http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/ -# -# Version: 2.0.0 -# -# Authors: -# -# - [Kevin van Zonneveld](http://kvz.io) -# - [Izaak Beekman](https://izaakbeekman.com/) -# - [Alexander Rathai](mailto:) -# - [Dr. Damian Rouson](http://www.sourceryinstitute.org/) (documentation) +# - Demos BASH3 Boilerplate (change this for your script) # # Usage: # -# LOG_LEVEL=7 ./main.sh -f /tmp/x -d +# LOG_LEVEL=7 ./main.sh -f /tmp/x -d (change this for your script) # -# Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io) and contributors -# Licensed under MIT: https://raw.githubusercontent.com/kvz/bash3boilerplate/master/LICENSE -# You are not obligated to ship the license file with your b3bp projects as long -# as you leave the above comments intact. - - -### Configuration -##################################################################### +# Based on a template by BASH3 Boilerplate v2.0.0 +# Copyright (c) 2013 Kevin van Zonneveld and contributors +# http://bash3boilerplate.sh/#authors # Exit on error. Append ||true if you expect an error. # `set` is safer than relying on a shebang like `#!/bin/bash -e` because that is neutralized diff --git a/src/ini_val.sh b/src/ini_val.sh index 7de6b2e..0d02d07 100755 --- a/src/ini_val.sh +++ b/src/ini_val.sh @@ -9,17 +9,6 @@ # # - All keys inside the .ini file must be unique, regardless of the use of sections # -# More info: -# -# - https://github.com/kvz/bash3boilerplate -# - http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/ -# -# Version: 2.0.0 -# -# Authors: -# -# - Kevin van Zonneveld (http://kvz.io) -# # Usage as a function: # # source ini_val.sh @@ -29,10 +18,9 @@ # # ini_val.sh data.ini connection.host 127.0.0.1 # -# Copyright (c) 2013 Kevin van Zonneveld and [contributors](https://github.com/kvz/bash3boilerplate#authors) -# Licensed under [MIT](https://raw.githubusercontent.com/kvz/bash3boilerplate/master/LICENSE) -# You are not obligated to bundle the LICENSE file with your b3bp projects as long -# as you leave these references intact. +# Based on a template by BASH3 Boilerplate v2.0.0 +# Copyright (c) 2013 Kevin van Zonneveld and contributors +# http://bash3boilerplate.sh/#authors function ini_val() { local file="${1:-}" diff --git a/src/megamount.sh b/src/megamount.sh index 994a8bd..0c8dd68 100644 --- a/src/megamount.sh +++ b/src/megamount.sh @@ -11,17 +11,6 @@ # # - ./parse_url.sh # -# More info: -# -# - https://github.com/kvz/bash3boilerplate -# - http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/ -# -# Version: 2.0.0 -# -# Authors: -# -# - Kevin van Zonneveld (http://kvz.io) -# # Usage as a function: # # source megamount.sh @@ -31,10 +20,9 @@ # # megamount.sh smb://janedoe:abc123@192.168.0.1/documents /mnt/documents # -# Copyright (c) 2013 Kevin van Zonneveld and [contributors](https://github.com/kvz/bash3boilerplate#authors) -# Licensed under [MIT](https://raw.githubusercontent.com/kvz/bash3boilerplate/master/LICENSE) -# You are not obligated to bundle the LICENSE file with your b3bp projects as long -# as you leave these references intact. +# Based on a template by BASH3 Boilerplate v2.0.0 +# Copyright (c) 2013 Kevin van Zonneveld and contributors +# http://bash3boilerplate.sh/#authors __dir=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd) source "${__dir}/parse_url.sh" diff --git a/src/parse_url.sh b/src/parse_url.sh index 65d94b8..373a3ad 100644 --- a/src/parse_url.sh +++ b/src/parse_url.sh @@ -5,20 +5,10 @@ # # - Takes a URL and parses protocol, user, pass, host, port, path. # -# More info: -# -# - https://github.com/kvz/bash3boilerplate -# # Based on: # # - http://stackoverflow.com/a/6174447/151666 # -# Version: 2.0.0 -# -# Authors: -# -# - Kevin van Zonneveld (http://kvz.io) -# # Usage as a function: # # source parse_url.sh @@ -28,10 +18,9 @@ # # parse_url.sh 'http://johndoe:abc123@example.com:8080/index.html' # -# Copyright (c) 2013 Kevin van Zonneveld and [contributors](https://github.com/kvz/bash3boilerplate#authors) -# Licensed under [MIT](https://raw.githubusercontent.com/kvz/bash3boilerplate/master/LICENSE) -# You are not obligated to bundle the LICENSE file with your b3bp projects as long -# as you leave these references intact. +# Based on a template by BASH3 Boilerplate v2.0.0 +# Copyright (c) 2013 Kevin van Zonneveld and contributors +# http://bash3boilerplate.sh/#authors function parse_url() { local parse="${1}" diff --git a/src/templater.sh b/src/templater.sh index 77410b6..b90c98b 100755 --- a/src/templater.sh +++ b/src/templater.sh @@ -6,17 +6,6 @@ # - takes a source (template) & destination (config) filepath argument # - then replaces placeholders with variables found in the environment # -# More info: -# -# - https://github.com/kvz/bash3boilerplate -# - http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/ -# -# Version: 2.0.0 -# -# Authors: -# -# - Kevin van Zonneveld (http://kvz.io) -# # Usage as a function: # # source templater.sh @@ -27,10 +16,9 @@ # # ALLOW_REMAINDERS=1 templater.sh input.cfg output.cfg # -# Copyright (c) 2013 Kevin van Zonneveld and [contributors](https://github.com/kvz/bash3boilerplate#authors) -# Licensed under [MIT](https://raw.githubusercontent.com/kvz/bash3boilerplate/master/LICENSE) -# You are not obligated to bundle the LICENSE file with your b3bp projects as long -# as you leave these references intact. +# Based on a template by BASH3 Boilerplate v2.0.0 +# Copyright (c) 2013 Kevin van Zonneveld and contributors +# http://bash3boilerplate.sh/#authors function templater() { ALLOW_REMAINDERS="${ALLOW_REMAINDERS:-0}" diff --git a/website/_bin/deploy.sh b/website/_bin/deploy.sh index 2e875ed..68b7add 100755 --- a/website/_bin/deploy.sh +++ b/website/_bin/deploy.sh @@ -1,13 +1,38 @@ #!/usr/bin/env bash -set -o pipefail +# This file: +# +# - Let's inject.sh inject markdown files into the ./website directory +# - Syncs that to a temporary directory along with a git init +# - (in case of Travis CI) assumes a Git bot identity, and uses an overriden GHPAGES_URL containing its token thanks to `travis encrypt` +# - Force pushes that to the gh-pages branch +# +# Usage: +# +# ./deploy.sh +# +# Based on a template by BASH3 Boilerplate v2.0.0 +# Copyright (c) 2013 Kevin van Zonneveld and contributors +# http://bash3boilerplate.sh/#authors + +# Exit on error. Append || true if you expect an error. set -o errexit +# Exit on error inside any functions or subshells. +set -o errtrace +# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR set -o nounset +# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip` +set -o pipefail +# Turn on traces, useful while debugging but commented out by default # set -o xtrace -# Set magic variables for current file & dir +# Set magic variables for current file, directory, os, etc. __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" __file="${__dir}/$(basename "${BASH_SOURCE[0]}")" __base="$(basename ${__file} .sh)" +__os="Linux" +if [[ "${OSTYPE:-}" == "darwin"* ]]; then + __os="OSX" +fi ghpages_repo=${GHPAGES_REPO:-"kvz/bash3boilerplate"} ghpages_branch=${GHPAGES_BRANCH:-"gh-pages"} diff --git a/website/_bin/inject.sh b/website/_bin/inject.sh index 2293dcf..eb701c1 100755 --- a/website/_bin/inject.sh +++ b/website/_bin/inject.sh @@ -1,14 +1,37 @@ #!/usr/bin/env bash -set -o pipefail +# This file: +# +# - Injects markdown files into the ./website directory +# - Changes them a little to make them more suitable for Jekyll building +# +# Usage: +# +# ./inject.sh +# +# Based on a template by BASH3 Boilerplate v2.0.0 +# Copyright (c) 2013 Kevin van Zonneveld and contributors +# http://bash3boilerplate.sh/#authors + +# Exit on error. Append || true if you expect an error. set -o errexit +# Exit on error inside any functions or subshells. +set -o errtrace +# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR set -o nounset +# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip` +set -o pipefail +# Turn on traces, useful while debugging but commented out by default # set -o xtrace -# Set magic variables for current file & dir +# Set magic variables for current file, directory, os, etc. __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" __file="${__dir}/$(basename "${BASH_SOURCE[0]}")" __base="$(basename ${__file} .sh)" -__webroot="$(cd "$(dirname "${__dir}")" && pwd)" +__os="Linux" +if [[ "${OSTYPE:-}" == "darwin"* ]]; then + __os="OSX" +fi + for doc in "README" "FAQ" "CHANGELOG"; do targetName="$(echo "${doc}" | awk '{print tolower($0)}')"