Compare commits

...

372 Commits
v1.2.0 ... main

Author SHA1 Message Date
dependabot[bot]
2e878ec30f
Bump cross-spawn from 6.0.5 to 6.0.6 (#169)
Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 6.0.5 to 6.0.6.
- [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/v6.0.6/CHANGELOG.md)
- [Commits](https://github.com/moxystudio/node-cross-spawn/compare/v6.0.5...v6.0.6)

---
updated-dependencies:
- dependency-name: cross-spawn
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-25 12:20:37 +01:00
Kevin van Zonneveld
726ce78de7
Update README.md 2024-08-19 13:02:35 +02:00
Kevin van Zonneveld
51e7644bb1
Easier SHELLCHECK_SEVERITY in CI 2023-08-29 12:48:33 +02:00
Kevin van Zonneveld
985b0046c4
Update yarn.lock 2023-08-29 12:46:46 +02:00
Kevin van Zonneveld
38f269c660
Update CHANGELOG.md 2023-08-29 12:45:04 +02:00
Kevin van Zonneveld
f6b61410c0
Update version 2023-08-29 12:44:42 +02:00
Kevin van Zonneveld
42e50f66c8
Release 2.7.2 2023-08-29 12:44:42 +02:00
Kevin van Zonneveld
c5012d0190
Update package.json 2023-08-29 12:44:40 +02:00
Kevin van Zonneveld
14421bd791
Update version 2023-08-29 12:44:13 +02:00
Kevin van Zonneveld
7af1f75c5e
Release 2.7.1 2023-08-29 12:44:12 +02:00
Kevin van Zonneveld
320609fceb
update version 2023-08-29 12:44:10 +02:00
Kevin van Zonneveld
9e70d61133
Fix improper replace 2023-08-29 12:43:49 +02:00
Kevin van Zonneveld
354c304b19
Release 2.7.0 2023-08-29 12:41:51 +02:00
Kevin van Zonneveld
a6a2d961ae
Update CHANGELOG.md 2023-08-29 12:41:50 +02:00
Kevin van Zonneveld
7f9a31f8d8
Release 2.6.0 2023-08-29 12:39:39 +02:00
Kevin van Zonneveld
758fa92f05
Update package.json 2023-08-29 12:39:37 +02:00
Kevin van Zonneveld
555beb1add
Update package.json 2023-08-29 12:38:25 +02:00
Kevin van Zonneveld
2d145e24e9
Update version 2023-08-29 12:37:51 +02:00
Kevin van Zonneveld
b2140d5ec6
Release 2.5.0 2023-08-29 12:37:50 +02:00
Kevin van Zonneveld
7a022bccf3
Upgrade/cleanup deps 2023-08-29 12:37:39 +02:00
Kevin van Zonneveld
55cd329ebd
Upgrade fakefile 2023-08-29 12:35:17 +02:00
Kevin van Zonneveld
879422d09f
Create dependabot.yml 2023-08-29 12:31:27 +02:00
Kevin van Zonneveld
1fb7cc4337
Update ci.yml 2023-08-29 12:29:27 +02:00
Kevin van Zonneveld
f2ccef5b36
Merge branch 'main' of github.com:kvz/bash3boilerplate 2023-08-29 12:25:19 +02:00
Kevin van Zonneveld
2e68b71743
Move linting out to separate actions 2023-08-29 12:25:08 +02:00
Kevin van Zonneveld
28deb39d86
Fix tests 2023-08-29 12:24:49 +02:00
Kevin van Zonneveld
33a3fd706b
Create CNAME 2023-08-29 12:06:32 +02:00
Kevin van Zonneveld
ddc6440177
Rename website->docs 2023-08-29 12:06:14 +02:00
Kevin van Zonneveld
c4585291f3
Update ci.yml 2023-08-29 12:04:33 +02:00
Kevin van Zonneveld
9a27140e7e
Deprecate Lanyon-based website in favor of a simple redirect to github 2023-08-29 12:01:10 +02:00
Kevin van Zonneveld
cb06f0aa70
Update bash3boilerplate.code-workspace 2023-08-29 11:50:15 +02:00
FilipBrinkmann
e45247d4aa
Fix duplicated comment (#166) 2023-07-05 22:21:11 +02:00
dependabot[bot]
a50ad7007e
Bump express from 4.17.1 to 4.18.2 (#165)
Bumps [express](https://github.com/expressjs/express) from 4.17.1 to 4.18.2.
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/master/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.17.1...4.18.2)

---
updated-dependencies:
- dependency-name: express
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-12 10:23:05 +01:00
dependabot[bot]
41172fcc8f
Bump decode-uri-component from 0.2.0 to 0.2.2 (#164)
Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-05 10:59:02 +01:00
dependabot[bot]
9f0c37e2ac
Bump terser from 4.8.0 to 4.8.1 (#163)
Bumps [terser](https://github.com/terser/terser) from 4.8.0 to 4.8.1.
- [Release notes](https://github.com/terser/terser/releases)
- [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/terser/terser/commits)

---
updated-dependencies:
- dependency-name: terser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-21 15:57:12 +02:00
dependabot[bot]
0a6e3925dc
Bump shell-quote from 1.6.1 to 1.7.3 (#162)
Bumps [shell-quote](https://github.com/substack/node-shell-quote) from 1.6.1 to 1.7.3.
- [Release notes](https://github.com/substack/node-shell-quote/releases)
- [Changelog](https://github.com/substack/node-shell-quote/blob/master/CHANGELOG.md)
- [Commits](https://github.com/substack/node-shell-quote/compare/1.6.1...1.7.3)

---
updated-dependencies:
- dependency-name: shell-quote
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-22 10:57:22 +02:00
dependabot[bot]
7d3927b025
Bump eventsource from 1.0.7 to 1.1.1 (#161)
Bumps [eventsource](https://github.com/EventSource/eventsource) from 1.0.7 to 1.1.1.
- [Release notes](https://github.com/EventSource/eventsource/releases)
- [Changelog](https://github.com/EventSource/eventsource/blob/master/HISTORY.md)
- [Commits](https://github.com/EventSource/eventsource/compare/v1.0.7...v1.1.1)

---
updated-dependencies:
- dependency-name: eventsource
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-02 10:43:05 +02:00
dependabot[bot]
49eed4f283
Bump url-parse from 1.5.3 to 1.5.10 (#159)
Bumps [url-parse](https://github.com/unshiftio/url-parse) from 1.5.3 to 1.5.10.
- [Release notes](https://github.com/unshiftio/url-parse/releases)
- [Commits](https://github.com/unshiftio/url-parse/compare/1.5.3...1.5.10)

---
updated-dependencies:
- dependency-name: url-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-28 12:34:33 +01:00
dependabot[bot]
3d47083fcf
Bump ajv from 6.10.2 to 6.12.6 (#157)
Bumps [ajv](https://github.com/ajv-validator/ajv) from 6.10.2 to 6.12.6.
- [Release notes](https://github.com/ajv-validator/ajv/releases)
- [Commits](https://github.com/ajv-validator/ajv/compare/v6.10.2...v6.12.6)

---
updated-dependencies:
- dependency-name: ajv
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-14 10:50:59 +01:00
dependabot[bot]
e516a60169
Bump undefsafe from 2.0.2 to 2.0.5 (#156)
Bumps [undefsafe](https://github.com/remy/undefsafe) from 2.0.2 to 2.0.5.
- [Release notes](https://github.com/remy/undefsafe/releases)
- [Commits](https://github.com/remy/undefsafe/compare/v2.0.2...v2.0.5)

---
updated-dependencies:
- dependency-name: undefsafe
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-10 07:47:25 +01:00
dependabot[bot]
d1c26b9ac1
Bump path-parse from 1.0.6 to 1.0.7 (#155)
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-06 14:37:19 +02:00
dependabot[bot]
85efe41ad9
Bump url-parse from 1.5.1 to 1.5.3 (#154)
Bumps [url-parse](https://github.com/unshiftio/url-parse) from 1.5.1 to 1.5.3.
- [Release notes](https://github.com/unshiftio/url-parse/releases)
- [Commits](https://github.com/unshiftio/url-parse/compare/1.5.1...1.5.3)

---
updated-dependencies:
- dependency-name: url-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-06 13:51:35 +02:00
dependabot[bot]
80ab935cf6
Bump qs from 6.2.1 to 6.2.3 (#153)
Bumps [qs](https://github.com/ljharb/qs) from 6.2.1 to 6.2.3.
- [Release notes](https://github.com/ljharb/qs/releases)
- [Changelog](https://github.com/ljharb/qs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.2.1...v6.2.3)

---
updated-dependencies:
- dependency-name: qs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-04 07:55:33 +02:00
dependabot[bot]
86f20e34b7
Bump color-string from 1.5.3 to 1.6.0 (#152)
Bumps [color-string](https://github.com/Qix-/color-string) from 1.5.3 to 1.6.0.
- [Release notes](https://github.com/Qix-/color-string/releases)
- [Changelog](https://github.com/Qix-/color-string/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Qix-/color-string/commits/1.6.0)

---
updated-dependencies:
- dependency-name: color-string
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-04 07:23:57 +02:00
dependabot[bot]
d113e87c96
Bump tar from 2.2.1 to 2.2.2 (#151)
Bumps [tar](https://github.com/npm/node-tar) from 2.2.1 to 2.2.2.
- [Release notes](https://github.com/npm/node-tar/releases)
- [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md)
- [Commits](https://github.com/npm/node-tar/compare/v2.2.1...v2.2.2)

---
updated-dependencies:
- dependency-name: tar
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-04 07:22:21 +02:00
dependabot[bot]
9f06b1a8c6
Bump dns-packet from 1.1.1 to 1.3.4 (#150)
Bumps [dns-packet](https://github.com/mafintosh/dns-packet) from 1.1.1 to 1.3.4.
- [Release notes](https://github.com/mafintosh/dns-packet/releases)
- [Changelog](https://github.com/mafintosh/dns-packet/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mafintosh/dns-packet/compare/v1.1.1...v1.3.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-27 16:11:20 +02:00
dependabot[bot]
8a14c0e3d5
Bump browserslist from 4.7.2 to 4.16.6 (#149)
Bumps [browserslist](https://github.com/browserslist/browserslist) from 4.7.2 to 4.16.6.
- [Release notes](https://github.com/browserslist/browserslist/releases)
- [Changelog](https://github.com/browserslist/browserslist/blob/main/CHANGELOG.md)
- [Commits](https://github.com/browserslist/browserslist/compare/4.7.2...4.16.6)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-25 11:49:57 +02:00
dependabot[bot]
c086796573
Bump url-parse from 1.4.7 to 1.5.1 (#147)
Bumps [url-parse](https://github.com/unshiftio/url-parse) from 1.4.7 to 1.5.1.
- [Release notes](https://github.com/unshiftio/url-parse/releases)
- [Commits](https://github.com/unshiftio/url-parse/compare/1.4.7...1.5.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-10 08:51:28 +02:00
dependabot[bot]
05cdcdaa12
Bump hosted-git-info from 2.1.5 to 2.8.9 (#148)
Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.1.5 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.1.5...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-10 08:41:35 +02:00
dependabot[bot]
8ceed901d5
Bump ssri from 6.0.1 to 6.0.2 (#146)
Bumps [ssri](https://github.com/npm/ssri) from 6.0.1 to 6.0.2.
- [Release notes](https://github.com/npm/ssri/releases)
- [Changelog](https://github.com/npm/ssri/blob/v6.0.2/CHANGELOG.md)
- [Commits](https://github.com/npm/ssri/compare/v6.0.1...v6.0.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-04-20 07:58:51 +02:00
dependabot[bot]
76fbd2104b
Bump y18n from 3.2.1 to 3.2.2 (#145)
Bumps [y18n](https://github.com/yargs/y18n) from 3.2.1 to 3.2.2.
- [Release notes](https://github.com/yargs/y18n/releases)
- [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md)
- [Commits](https://github.com/yargs/y18n/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-30 17:37:10 +02:00
dependabot[bot]
9cc3bf124c
Bump elliptic from 6.5.3 to 6.5.4 (#144)
Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.3 to 6.5.4.
- [Release notes](https://github.com/indutny/elliptic/releases)
- [Commits](https://github.com/indutny/elliptic/compare/v6.5.3...v6.5.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-09 11:22:17 +01:00
dependabot[bot]
986fec8090
Bump ini from 1.3.4 to 1.3.7 (#142)
Bumps [ini](https://github.com/isaacs/ini) from 1.3.4 to 1.3.7.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](https://github.com/isaacs/ini/compare/v1.3.4...v1.3.7)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-12-14 09:48:44 +01:00
Kevin van Zonneveld
ea15c44c7e Remove Travis 2020-11-23 20:10:45 +01:00
Kevin van Zonneveld
febd9e354b
Switch from using Travis to GitHub Actions (#141)
* First swing at GHA

* Delete .travis.yml

* Update ci.yml

* Update main.sh

* Update ci.yml

* Update ci.yml
2020-11-23 19:56:46 +01:00
dependabot[bot]
13d74bb4f1
Bump is-my-json-valid from 2.15.0 to 2.20.5 (#140)
Bumps [is-my-json-valid](https://github.com/mafintosh/is-my-json-valid) from 2.15.0 to 2.20.5.
- [Release notes](https://github.com/mafintosh/is-my-json-valid/releases)
- [Commits](https://github.com/mafintosh/is-my-json-valid/compare/v2.15.0...v2.20.5)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-11-16 11:01:06 +01:00
dependabot[bot]
ab3857e3bd
Bump elliptic from 6.3.2 to 6.5.3 (#139)
Bumps [elliptic](https://github.com/indutny/elliptic) from 6.3.2 to 6.5.3.
- [Release notes](https://github.com/indutny/elliptic/releases)
- [Commits](https://github.com/indutny/elliptic/compare/v6.3.2...v6.5.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-11-16 11:00:43 +01:00
Kevin van Zonneveld
e5da0aa249 Upgrade to latest Lanyon 2020-11-16 10:46:11 +01:00
Kevin van Zonneveld
bbb8afea4d Update .travis.yml 2020-11-12 15:40:08 +01:00
dependabot[bot]
e078dd2b91
Bump websocket-extensions from 0.1.1 to 0.1.4 (#138)
Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.1 to 0.1.4.
- [Release notes](https://github.com/faye/websocket-extensions-node/releases)
- [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
- [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.1...0.1.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-06-08 10:16:56 +02:00
Kevin van Zonneveld
9fd3f1df64 Update CHANGELOG.md 2020-04-22 10:01:55 +02:00
R. Fuehrer
1005ceeec8
Add feature edit/update comments (#132)
Remove obsolete lines of code
Update reference file
Update test scenario
2020-04-22 09:59:24 +02:00
Kevin van Zonneveld
56eab89caa Fix CHANGELOG links (I think). Should fix #136 2020-04-22 09:57:39 +02:00
Kevin van Zonneveld
186d9ff6a0 Update yarn.lock 2020-04-22 09:51:53 +02:00
Kevin van Zonneveld
23ce0e6b85 Merge branch 'master' of github.com:kvz/bash3boilerplate 2020-04-22 09:51:38 +02:00
Kevin van Zonneveld
6392674f70 Update CHANGELOG.md 2020-04-22 09:48:03 +02:00
dependabot[bot]
222a95793b
Bump constantinople from 3.1.0 to 3.1.2 (#135)
Bumps [constantinople](https://github.com/ForbesLindesay/constantinople) from 3.1.0 to 3.1.2.
- [Release notes](https://github.com/ForbesLindesay/constantinople/releases)
- [Commits](https://github.com/ForbesLindesay/constantinople/compare/3.1.0...3.1.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-16 07:42:22 +02:00
Ross Smith II
269627deec
Simplify example in readme (#133) 2020-02-17 09:51:55 +01:00
R. Fuehrer
1238b67abe Add comment feature and feature checks (#130) 2020-01-07 09:32:57 +01:00
R. Fuehrer
5cc417485a Fix sed regular expression to be non-greedy (#129)
* Fix sed to be non-greedy

* Fix missing double quote to prevent globbing and word splitting
2020-01-04 13:56:01 +01:00
R. Fuehrer
971a83ea3a Enhanced ini file handling (#128)
* Add ini file creation if not exists
Add section creation if not exists
Add default section if section not given
Fix read key value only from given (or default) section

* Fix to support platform specific sed

* Fixed typo in comment

* Fix test scenario to reflect changes to the (introduced) default section

* Fix expectations for scenario test

* Fix style guide compatibility
2019-12-31 15:16:08 +01:00
Ross Smith II
14dc823cca Fix readme to use [[ per readme (#126)
To be consistent with
https://github.com/kvz/bash3boilerplate/edit/master/README.md#Scoping
2019-12-09 09:22:33 +01:00
Gert Goet
599faf3830 Correct error_code in err_report (#124) (#125) 2019-11-18 11:56:18 +01:00
Kevin van Zonneveld
0d096350b0 Update CHANGELOG.md 2019-11-07 14:24:19 +01:00
Kevin van Zonneveld
24e7ceaaf7 Update version 2019-11-07 14:23:58 +01:00
Kevin van Zonneveld
f1ad8a5655 Release 2.4.1 2019-11-07 14:23:57 +01:00
Kevin van Zonneveld
c0f58127bb Update version 2019-11-07 14:23:26 +01:00
Kevin van Zonneveld
6689117e5d Release 2.4.0 2019-11-07 14:23:25 +01:00
Kevin van Zonneveld
a28d594d5f Update CHANGELOG.md 2019-11-07 14:23:19 +01:00
Kevin van Zonneveld
bccefb0061 Update version 2019-11-07 14:21:46 +01:00
Kevin van Zonneveld
9194295c64 Release 2.3.1 2019-11-07 14:21:45 +01:00
Kevin van Zonneveld
8146667ea1 Merge branch 'master' of github.com:kvz/bash3boilerplate 2019-11-05 09:32:59 +01:00
dependabot[bot]
2019caa899 Bump extend from 3.0.0 to 3.0.2 (#121)
Bumps [extend](https://github.com/justmoon/node-extend) from 3.0.0 to 3.0.2.
- [Release notes](https://github.com/justmoon/node-extend/releases)
- [Changelog](https://github.com/justmoon/node-extend/blob/master/CHANGELOG.md)
- [Commits](https://github.com/justmoon/node-extend/compare/v3.0.0...v3.0.2)

Signed-off-by: dependabot[bot] <support@github.com>
2019-11-03 20:31:06 +01:00
dependabot[bot]
357ea3778a Bump mime from 1.3.4 to 1.4.1 (#122)
Bumps [mime](https://github.com/broofa/node-mime) from 1.3.4 to 1.4.1.
- [Release notes](https://github.com/broofa/node-mime/releases)
- [Changelog](https://github.com/broofa/node-mime/blob/master/CHANGELOG.md)
- [Commits](https://github.com/broofa/node-mime/compare/v1.3.4...v1.4.1)

Signed-off-by: dependabot[bot] <support@github.com>
2019-11-03 20:30:58 +01:00
Kevin van Zonneveld
f377dfb16e Update .travis.yml 2019-10-29 13:14:25 +01:00
Kevin van Zonneveld
f77b400dc9 Fix main-repeated tests, flags weren't incremented before 2019-10-29 10:43:47 +01:00
Kevin van Zonneveld
03662dd404 Update main-repeated.stdio 2019-10-29 10:43:30 +01:00
Kevin van Zonneveld
b8a4aba3c2 Allow outputting both flags and arrays for arg_i and arg_x
This should later probably be split so we have dedicated varnames for the different types, as we're now making the template uglier just to accomodate our tests
2019-10-29 09:57:59 +01:00
Kevin van Zonneveld
685442bbcc Fix empty line crashing acceptance test 2019-10-29 09:56:40 +01:00
Kevin van Zonneveld
16b543114b Offer easier way to run a test scenario in debug mode 2019-10-29 09:52:34 +01:00
Kevin van Zonneveld
7791e3ca0f Isolate test: main-repeated 2019-10-29 09:16:13 +01:00
Kevin van Zonneveld
1152cc3cf7 Upgrade to latest Lanyon 2019-10-29 09:14:02 +01:00
Kevin van Zonneveld
b4048f3f12 Update .travis.yml 2019-10-29 08:45:11 +01:00
Kevin van Zonneveld
11cd18e179 Update colors in test fixtures 2019-10-29 08:42:15 +01:00
Kevin van Zonneveld
05f35415a6 Address ShellCheck error
```
In ./test/acceptance.sh line 101:
        -e "s@{root}/node_modules/\.bin/node@{node}@g" "${curFile}" \
                                  ^-- SC1117: Backslash is literal in "\.". Prefer explicit escaping: "\\.".
```
2019-10-29 08:42:04 +01:00
Kevin van Zonneveld
ec9087f0d2 Ignore any shell script in the website directory 2019-10-29 08:41:35 +01:00
Kevin van Zonneveld
5a9a68be2b Fix Typo 2019-10-29 08:41:22 +01:00
Kevin van Zonneveld
97f9676754 Rename save:fixtures to test:update which is more in line with how e.g. Jest does it 2019-10-29 08:41:16 +01:00
Kevin van Zonneveld
83c77f8df3 -v operator was added in bash 4.2 while we target bash 3 -- Part II 2019-10-29 08:41:01 +01:00
Kevin van Zonneveld
04cf154b3e Upgrade to Node 10 on Travis 2019-10-29 08:35:42 +01:00
Kevin van Zonneveld
4085bc461e -v operator was added in bash 4.2 while we target bash 3 2019-10-29 08:34:52 +01:00
Kevin van Zonneveld
8e548e766e Fix Cabal warnings on Travis
Warning: The install command is a part of the legacy v1 style of cabal usage.

Please switch to using either the new project style and the new-install

command or the legacy v1-install alias as new-style projects will become the

default in the next version of cabal-install. Please file a bug if you cannot

replicate a working v1- use case with the new-style commands.

For more information, see: https://wiki.haskell.org/Cabal/NewBuild

cabal: There is no package named 'shellcheck'. However, the following package

name exists: 'ShellCheck'.
2019-10-29 08:34:37 +01:00
Kevin van Zonneveld
d908e8b362 Release 2.4.0 2019-10-08 16:07:32 +02:00
Kevin van Zonneveld
9250d036dc Update CHANGELOG.md 2019-10-08 16:07:27 +02:00
gmeral
ea57d157c7 #111 more contrasted colors for alert and emergency (#112)
* Set alert and emergency colors to more readable values

* Add entry to CHANGELOG.md about #111
2019-09-20 11:43:30 +02:00
Lukas Stockner
95b9cb1469 Add support for repeatable arguments (#118)
* Add support for declaring arguments as repeatable

If the usage of the argument includes the phrase "Can be repeated.",
the corresponding arg_ variable will be an array containing one element
per instance of the argument.

* Add example and test for using repeated parameters

* Add example and test for using repeated flags
2019-09-20 11:40:06 +02:00
Kevin van Zonneveld
ff89a1154b Add --allow-unauthenticated which hopefully fixes #119 2019-09-20 11:35:02 +02:00
Kevin van Zonneveld
9f31a5e969 Create bash3boilerplate.code-workspace 2019-09-20 11:34:43 +02:00
Lukas Stockner
664e55ad1e Fix or silence remaining warnings with shellcheck v0.7.0 (#117)
SC2235: The warning/suggestion about the subshell was letigimate, so
the suggested fix is implemented.

SC2034: The variable __invocation is indeed unused, but it's supposed
to be there in case the script using bash3boilerplate wants to use it,
so this commit silences the warning.

SC1102: The warning about the parsing of $((( is legitimate, so the
suggested fix is implemented.

SC2015: While the warning is correct in general, here 'true' has no
side effects hence it can be silenced.

Fixes #107.
2019-09-20 11:30:59 +02:00
QwertyZW
7b7d31a1bf Improve debug mode (#103)
Add file, line number, function name and function line offset
2019-05-06 10:04:09 +02:00
Manuel Streuhofer
ba0e7150cb close issue #108 (#109)
* added test for issue-108

* Closes #108

* fixed some easy shellcheck complaints

* trying to fix travis/debian-sid/shellcheck problem
2018-09-03 12:00:55 +02:00
Gabriel A. Devenyi
2048e4303e Add || true to fix __invocation with no arguments (#102) 2018-06-26 15:55:16 +02:00
Gabriel A. Devenyi
327cba75c9 Add magic variable that stores the full command line invocation (#99)
Provides variable __invocation which contains the command line
with proper separators maintained.

Adapted from https://stackoverflow.com/a/36625791
2018-06-06 15:28:55 +02:00
Manuel Streuhofer
ee869a9584 templater.sh: use perl if available (#98) 2018-01-25 10:35:53 +01:00
Manuel Streuhofer
f57e37eb68 fix templater.sh and associated test
templater.sh now escapes the delimiter it uses for its sed magic within
the environment variable content.

the associated test uses a properly cleaned up temporary file instead of
explicitly rm-ing its own mess.
2018-01-23 22:02:57 +01:00
A. G. Madi
2463cd6cc9 Allow counting how many times an argument is used. (#96)
An example of use would be the passing in of multiple -v options in some utilities to increase verbosity.
2018-01-22 15:21:48 +01:00
Manuel Streuhofer
860a7de899 shellcheck lead me astray 2018-01-21 23:19:16 +01:00
Manuel Streuhofer
236e3c7eca fix shellcheck errors
shellcheck 0.4.7 seems to have come up with new checks and now complains
about yet more possible issues. fixed them all as good as i could.
2018-01-21 23:02:03 +01:00
Kevin van Zonneveld
cf7d25e3d1 Build plz 2017-08-22 10:25:59 +02:00
Izaak "Zaak" Beekman
d25d6a0106 Merge pull request #93 from gmasse/fix_templater
templater.sh: Update Regexp to not match ${_} for replacement
2017-08-21 09:29:42 -04:00
Germain Masse
9b7a9ccd17 Fix Travis CI failure on src/templater.sh 2017-08-21 10:01:59 +02:00
Germain Masse
38622845a8 Update Regexp to not match ${_} for replacement 2017-08-21 09:34:44 +02:00
Izaak "Zaak" Beekman
0289532f18 Merge pull request #92 from gmasse/auto-color-screen
Enable color in screen or tmux
2017-08-14 15:14:29 -04:00
Germain Masse
2fcd0a765b
Fix typo in FAQ: 'Default:' to 'Default=' 2017-08-14 20:37:12 +02:00
Germain Masse
48848fd17c
Cange egrep to grep -E in templater.sh script to comply with ShellCheck 2017-08-14 20:35:18 +02:00
Germain Masse
84685a451b
Change egrep to grep -E in acceptance test script to comply with ShellCheck 2017-08-14 18:29:21 +02:00
Germain Masse
12ea4dd75f
Enable color in screen or tmux 2017-08-13 21:08:59 +02:00
Kevin van Zonneveld
63c402912a Upgrade Lanyon to v0.0.92 2017-07-06 11:39:50 +02:00
Kevin van Zonneveld
0c2a580041 Set new bot token 2017-05-12 11:31:55 +02:00
Giovanni Saponaro
eac5ad8022 Fix typos in megamount (#89) 2017-05-04 13:48:18 +02:00
Kevin van Zonneveld
9f3aa6ead9 Upgrade Lanyon to v0.0.86 2017-05-02 09:56:04 +02:00
Kevin van Zonneveld
c19c08a775 Upgrade Lanyon to v0.0.85 2017-04-29 14:45:41 +02:00
Kevin van Zonneveld
a0e9bb0c05 Upgrade Lanyon to v0.0.84 2017-04-27 15:16:03 +02:00
Kevin van Zonneveld
d134dfd145 Upgrade Lanyon to v0.0.83 2017-04-21 14:00:37 +02:00
Kevin van Zonneveld
f6996a1595 Upgrade Lanyon to v0.0.82 2017-04-20 10:22:53 +02:00
Kevin van Zonneveld
1c672bf8cb Upgrade Lanyon to v0.0.81 2017-04-06 14:38:50 +02:00
Kevin van Zonneveld
87545c8f9a Fix deploys 2017-04-06 13:18:15 +02:00
Kevin van Zonneveld
111a00e1f0 Upgrade Lanyon to v0.0.78 2017-04-06 12:56:19 +02:00
Kevin van Zonneveld
6f0cfaddb1 Upgrade Lanyon to v0.0.73 2017-04-05 12:39:13 +02:00
Kevin van Zonneveld
5f815c7f98 Upgrade Lanyon to v0.0.72 2017-04-05 12:05:38 +02:00
Kevin van Zonneveld
c4429de7d5 Upgrade Lanyon to v0.0.70 2017-04-05 11:23:48 +02:00
Kevin van Zonneveld
d35fa94ffc Upgrade Lanyon to v0.0.65 2017-03-23 15:34:43 +01:00
Kevin van Zonneveld
7759cba46f Upgrade Lanyon to v0.0.64 2017-03-23 14:56:33 +01:00
Kevin van Zonneveld
efd984e01d Upgrade Lanyon to v0.0.63 2017-02-22 11:04:34 +01:00
Kevin van Zonneveld
ef66310b27 Upgrade Lanyon to v0.0.62 2017-02-19 11:42:43 +01:00
Kevin van Zonneveld
3e9afe28c3 Upgrade Lanyon to v0.0.58 2017-02-15 18:41:37 +01:00
Kevin van Zonneveld
ef04df597b Fix diff 2017-02-15 09:49:46 +01:00
Kevin van Zonneveld
e7e85ddff3 Upgrade to lanyon@0.0.55 2017-02-15 09:49:36 +01:00
Kevin van Zonneveld
b2326bf75e Build plz 2017-02-15 09:15:27 +01:00
Izaak Beekman
9b86dcced8 Merge pull request #87 from kvz/fixup-after-230
fixup example.sh like 2.3.0 main.sh
2017-02-14 14:32:21 -05:00
Izaak Beekman
2bbf6eed2e
Merge branch 'master' into fixup-after-230 2017-02-14 12:24:02 -05:00
Kevin van Zonneveld
ff37895ea4 SCROLEX_MODE=passthru 2017-02-14 17:17:10 +01:00
Kevin van Zonneveld
39e0607bcb Merge branch 'master' into fixup-after-230 2017-02-14 17:09:32 +01:00
Kevin van Zonneveld
748fdcfab3 Upgrade lanyon@0.0.54 2017-02-14 16:00:48 +01:00
Kevin van Zonneveld
c52a73598e Move to install 2017-02-14 15:42:29 +01:00
Kevin van Zonneveld
755eb0d02f bc is not really needed 2017-02-14 15:24:34 +01:00
Kevin van Zonneveld
b1861f9fab Fix chicken/egg with Lanyon install 2017-02-14 15:12:04 +01:00
Kevin van Zonneveld
b280139595 Upgrade lanyon and don't install it in every single setup 2017-02-14 15:00:34 +01:00
Izaak Beekman
cb29b2f984
Restore @mstreuhofer's changes that I clobbered 2017-02-10 19:00:00 -05:00
Izaak Beekman
2d5506cb36
Perform syntax checking with all available bashes
Add tests to help catch bash4-isms and ensure syntax is checked with
 all bashes on PATH in a given system.
2017-02-10 18:58:36 -05:00
Izaak Beekman
986191210a
Update FAQ website instructions
`npm run start` didn't work for me... I had to get yarn and do `yarn
 install` first. I'm guessing this will be true for others.
2017-02-10 18:58:36 -05:00
Izaak Beekman
0d1f488365
Fix shellchk and show usage for new magic var
Update acceptance tests
2017-02-10 18:58:35 -05:00
Izaak Beekman
7eea26c7b4
Attempt fix for OS X CI build 2017-02-10 18:58:25 -05:00
Manuel Streuhofer
d879ae1fe0 fixup example.sh like 2.3.0 main.sh
__i_am_main_script logic fixed for example.sh
added double-sourced test
2017-02-10 20:40:38 +01:00
Kevin van Zonneveld
382217eebf Update version 2017-02-10 15:32:48 +01:00
Kevin van Zonneveld
ba2d901cc2 Release 2.3.0 2017-02-10 15:32:47 +01:00
Kevin van Zonneveld
36db2227c7 Update CHANGELOG.md 2017-02-10 15:32:34 +01:00
Izaak Beekman
7cf9ea708d Issue 44 issue 21 issue 47 (#85)
* Fix shifting over `--`: don't throw errexit

 Fixes #21

* Add error trapping (including Ctrl-C) info to FAQ

 Closes #47

* Add backtracing to help localize errors

 - Fixes #44
 - Backtracing is turned on when the debugging `-d` flag is passed,
   otherwise backtracing function defined but signal trap not set.
 - Update main-help fixture due to moving trap

* Untabify main.sh

 Might be a controversial move, but I loath tabs...

* Add checks for tab chars and trailing whitespace

 - Update poor-man's style enforcement script to check for these
   violations
 - Better document style guidlines in README with small tweaks

* Add a magic variable to indicate if being source

 if `__i_am_main_script=1 #true` then `main.sh` called directly
 Fixes #45
2017-02-10 15:03:07 +01:00
Izaak Beekman
7f9419cda0 Merge pull request #83 from kvz/prtemplate
Add Pull Request Template
2017-02-09 16:03:42 -05:00
Manuel Streuhofer
47be547cfa extend acceptance test to check for code style (#81)
* extend acceptance test to check for code style

* cleanup following own style guide
2016-12-21 19:30:28 +01:00
Kevin van Zonneveld
21cafb3c34 Update changelog 2016-12-21 09:59:32 +01:00
Kevin van Zonneveld
ea6bbd058f Update version 2016-12-21 09:52:22 +01:00
Kevin van Zonneveld
884c55c616 Release 2.2.0 2016-12-21 09:52:21 +01:00
Kevin van Zonneveld
31ee23ba9b Add back replace dependency 2016-12-21 09:52:11 +01:00
Kevin van Zonneveld
f44385ced3 Add PULL_REQUEST_TEMPLATE.md 2016-12-21 09:46:15 +01:00
Kevin van Zonneveld
9c3ba0ad77 Add more changelog entries for v2.2.0 2016-12-21 09:40:10 +01:00
Kevin van Zonneveld
00acb0383b Consistent labeling of github meta 2016-12-21 09:32:33 +01:00
Kevin van Zonneveld
0c878b7623 Fix casing and present tense 2016-12-21 09:31:06 +01:00
Manuel Streuhofer
d383e8c098 prepared changelog for release 2.2.0 (#82)
moved entries in changelog from `unreleased` to 2.1.0 (even
though technically it's too late for that since that version was already
released).

added new section for 2.2.0 and added some points on what changed.

bumped version to 2.2.0 in main.sh, example.sh and package.json

Closes #74
2016-12-21 09:29:02 +01:00
Kevin van Zonneveld
ac7fad3e29 Upgrade node dependencies (#78)
* Upgrade node dependencies

* Upgrade Lanyon to v0.0.34

* Upgrade Lanyon to v0.0.37

* Upgrade Lanyon to v0.0.38
2016-12-20 09:23:28 +01:00
Kevin van Zonneveld
d17152253c Fix shellcheck linting 2016-12-16 14:48:58 +01:00
Kevin van Zonneveld
8c35bc9e76 Cleanup superfluous <title> 2016-12-16 14:40:17 +01:00
Kevin van Zonneveld
bbb589ee0a Merge branch 'master' of github.com:kvz/bash3boilerplate 2016-12-16 14:18:22 +01:00
Kevin van Zonneveld
80f6c82c18 Upgrade Lanyon to v0.0.47 2016-12-16 14:16:02 +01:00
Kevin van Zonneveld
191b8118e0 Remove nodemon dependency by letting Lanyon handle web-scanning 2016-12-16 13:58:11 +01:00
Manuel Streuhofer
785e7e9f8b Cleanup all *.sh following shellcheck advice (#80)
* Cleanup all *.sh following shellcheck advice

Closes #79

* do not shellcheck scripts out of our control
2016-12-16 08:18:03 +01:00
Kevin van Zonneveld
044ef6d1c5 Cleanup files no longer needed after Lanyon 2016-12-15 20:07:47 +01:00
Kevin van Zonneveld
42e9ec669d Upgrade Lanyon to v0.0.46 2016-12-15 15:38:53 +01:00
Kevin van Zonneveld
d0bfc96166 Merge branch 'master' of github.com:kvz/bash3boilerplate 2016-12-15 15:12:10 +01:00
Kevin van Zonneveld
a5c3d1c793 Upgrade Lanyon to v0.0.45 2016-12-15 15:12:08 +01:00
Manuel Streuhofer
ce755604da run shellcheck as part of the acceptance test (#77)
* install shellcheck from debian sid repository

* cleanup acceptance shell script

use a uniq temp directory and cleanup
make sure commands we use/need are installed

* shellcheck main.sh

* shellcheck example.sh

* shellcheck test/acceptance.sh

* brace all variables, used [[ instead of [
2016-12-15 12:57:42 +01:00
Kevin van Zonneveld
f763b47d2b Upgrade Lanyon to v0.0.44 2016-12-15 12:22:09 +01:00
Kevin van Zonneveld
15b1092262 Fix Travis error
Unsupported platform for fsevents@1.0.15: wanted
{"os":"darwin","arch":"any"}

Unsupported platform for fsevents@1.0.15: wanted
{"os":"darwin","arch":"any"}

https://travis-ci.org/kvz/bash3boilerplate/jobs/184200578#L757

https://github.com/npm/npm/issues/14042
2016-12-15 12:16:31 +01:00
Kevin van Zonneveld
70f7a2905c Upgrade Lanyon to v0.0.43 2016-12-15 11:41:24 +01:00
Kevin van Zonneveld
44c856d41a Upgrade Lanyon to v0.0.42 2016-12-14 17:22:00 +01:00
Kevin van Zonneveld
971096d73b Upgrade Lanyon to v0.0.41 2016-12-14 16:00:52 +01:00
Kevin van Zonneveld
19dfb9cff4 Utilize Lanyon cachebusting 2016-12-14 15:42:06 +01:00
Kevin van Zonneveld
cfbfd527d5 Upgrade Lanyon to v0.0.40 2016-12-14 15:31:53 +01:00
Manuel Streuhofer
cf85af8c15 brace all variables, used [[ instead of [ (#76)
Closes #33
2016-12-14 09:54:25 +01:00
Izaak Beekman
02cb82c9e6 Merge pull request #73 from mstreuhofer/usage-validation
Added automatic usage validation for required args

Thanks again for another wonderful contribution, @mstreuhofer!
2016-12-09 15:25:57 -05:00
Manuel Streuhofer
9350e0574c added automatic usage validation for required args
If the description of an option contains the single word sentence
'Required.' it is understood as a required argument and automatic
validation will make sure that it is set or end the script by calling
help.

Alternatively, if the argument within the __usage string is {arg}
instead of [arg] it is understood as a required argument and automatic
validation will make sure that it is set or end the script by calling
help (even if 'Required.' is not in the description).

Closes #22
2016-12-09 00:54:52 +01:00
Izaak Beekman
2c91db3faa Merge pull request #72 from mstreuhofer/vade-retro-eval
removed all usage of eval, proper usage of unset

Safer code,  💯 @mstreuhofer
2016-12-08 18:27:09 -05:00
Manuel Streuhofer
1e69fd5e21 removed all usage of eval, proper usage of unset
replaced all `eval` with `printf -v` for security reasons.

the behaviour of unset without -v/-f is actually undefined so make the
intent clear.
2016-12-06 18:06:25 +01:00
Izaak Beekman
68323978d4 Merge pull request #70 from mstreuhofer/color
Fix auto-color-off code

 Thanks to @mstreuhofer for another great contribution 🎊 🙇
2016-12-05 12:37:28 -05:00
Izaak Beekman
0a1b799e77 Merge pull request #71 from mstreuhofer/extcmd
Reduced usage of external sed + egrep

 Thanks to @mstreuhofer for the PR 🎉 💯
2016-12-05 12:33:37 -05:00
Kevin van Zonneveld
c4c0e6ffec Downgrade Lanyon to v0.0.32 2016-12-04 14:41:32 +01:00
Kevin van Zonneveld
d21dd23827 Upgrade Lanyon to v0.0.33 2016-12-04 14:27:58 +01:00
Manuel Streuhofer
b8bdaf371a get rid of awk, sed & egrep usage 2016-12-03 18:52:40 +01:00
Manuel Streuhofer
290c65d4b9 fix auto-color-off code
turn off colors if NO_COLOR is "true" or TERM is not "xterm*" or STDERR
is not connected to a terminal, but ignore TERM and STDERR if NO_COLOR
is set to "false" explicitly.

Fixes #69
2016-12-03 18:52:10 +01:00
Kevin van Zonneveld
b38310e915 Move inject to Lanyon prebuild 2016-12-03 14:02:25 +01:00
Kevin van Zonneveld
b14eec4675 Accept HMR 2016-12-03 13:59:49 +01:00
Kevin van Zonneveld
8ce2ed44c0 Upgrade Lanyon to v0.0.32 2016-12-01 17:56:39 +01:00
Kevin van Zonneveld
96ce0c8206 Upgrade Lanyon to v0.0.26 2016-12-01 16:05:57 +01:00
Kevin van Zonneveld
f0cb04dec7 (hopefully) Fix matrix 2016-12-01 15:56:41 +01:00
Kevin van Zonneveld
046f3ab99a Inject for production 2016-12-01 15:24:57 +01:00
Kevin van Zonneveld
1e9d1548a3 Merge branch 'master' of github.com:kvz/bash3boilerplate 2016-12-01 14:55:43 +01:00
Kevin van Zonneveld
1f13dfae78 Upgrade Lanyon to v0.0.25 2016-12-01 14:55:41 +01:00
Manuel Streuhofer
9b739b4cf0 Fix some code caught by shellcheck (#68) 2016-12-01 14:40:56 +01:00
Kevin van Zonneveld
bdb501bec0 Upgrade Lanyon to v0.0.24 2016-12-01 14:27:37 +01:00
Kevin van Zonneveld
64dc269217 Upgrade Lanyon to v0.0.23 2016-12-01 14:12:27 +01:00
Kevin van Zonneveld
d556893774 Upgrade Lanyon to v0.0.22 2016-12-01 14:01:53 +01:00
Kevin van Zonneveld
93c9c25c88 Upgrade Lanyon to v0.0.21 2016-12-01 13:41:41 +01:00
Kevin van Zonneveld
f41c05d971 yarn still messes up nested bins: https://github.com/yarnpkg/yarn/issues/760 2016-12-01 13:34:12 +01:00
Kevin van Zonneveld
16d699b67b Upgrade Lanyon to v0.0.20 2016-12-01 13:10:10 +01:00
Kevin van Zonneveld
36b9ce280b With yarn cache, do not cache node_modules on Travis 2016-12-01 12:51:52 +01:00
Kevin van Zonneveld
a178a95c26 Utilize yarn on Travis 2016-12-01 12:49:06 +01:00
Kevin van Zonneveld
fc766c7437 Upgrade Lanyon to v0.0.19 2016-12-01 12:46:45 +01:00
Kevin van Zonneveld
96220cea12 Add workaround for https://github.com/travis-ci/travis-ci/issues/5092 2016-12-01 11:36:40 +01:00
Kevin van Zonneveld
ddd89a787a Add Travis caching 2016-12-01 10:47:57 +01:00
Kevin van Zonneveld
b4d16f5317 Add Travis caching 2016-12-01 10:47:17 +01:00
Kevin van Zonneveld
2295da9233 Postinstall isn't automatically run(?) 2016-11-30 20:56:57 +01:00
Kevin van Zonneveld
0bed7a3782 node project is needed for lanyon 2016-11-30 20:26:24 +01:00
Kevin van Zonneveld
5b5d5608b4 node project is needed for lanyon 2016-11-30 20:10:34 +01:00
Kevin van Zonneveld
c0a2a56cee Upgrade Lanyon to v0.0.15 2016-11-30 20:09:01 +01:00
Kevin van Zonneveld
3c114b9d1d Fix package.json 2016-11-30 20:07:55 +01:00
Kevin van Zonneveld
e61028f679 Lanyon should be a devDep 2016-11-30 19:59:21 +01:00
Kevin van Zonneveld
049002a1cc Lanyon deploys 2016-11-30 19:35:44 +01:00
Kevin van Zonneveld
a7665cbf4f Upgrade Lanyon to v0.0.13 2016-11-30 16:22:25 +01:00
Kevin van Zonneveld
74a701a66e Lanyon (#67)
* WIP

* Working locally

* Upgrade lanyon

* Upgrade Lanyon to v0.0.12

* Tweaks

* Simplify example scripts
2016-11-30 14:57:40 +01:00
Manuel Streuhofer
57ebf1569d Updated README and FAQ (#66)
* updated TOC
* fixed typos
* link to bash3boilerplate.sh/main.sh instead of blob/master/main.sh
* updated links from e.g. blob/master/main.sh#L13 to
  blob/v2.1.0/main.sh#L13
2016-11-29 10:36:49 +01:00
Izaak Beekman
e7a0b2f412 Merge pull request #63 from mstreuhofer/usage-defaults
Allow for multiline opt description in __usage. Fixes #7
2016-11-18 09:45:07 -05:00
Kevin van Zonneveld
064f30502f Build plz : ) 2016-11-14 12:16:06 +01:00
Manuel Streuhofer
539443b3ca Allow for multiline opt description in __usage. Fixes #7 2016-11-11 20:13:01 +01:00
Kevin van Zonneveld
0181129aff Add all logos 2016-11-11 11:22:46 +01:00
roooshee
87530e756e Adding b3bp logo (#64) 2016-11-11 09:51:43 +01:00
Manuel Streuhofer
dfd799b4e5 b3bp sourced mode (#61)
If main.sh is being sourced instead of being executed it respects the
variables __usage and __helptext being defined beforehand. Its behaviour
will depend on the sourcing script. If __usage is defined but empty no
argument parsing is done. If __helptext is defined but empty no helptext
will be shown.

Logging support still exists as it did before. The environment variables
LOG_LEVEL and NO_COLOR are supported just as they were before.
2016-11-09 10:03:00 +01:00
Manuel Streuhofer
d2195eee3c mention the used license in each script header (#60)
turns out that the README.md explains that "... licensed under MIT ...
the LICENSE does not have to be bundled as long as ..." but the scripts
themselfs don't mention any license.

fixed that by adding a one line mention of the used license and the two
lines explaining that the header comments have to stay intact.
2016-11-08 21:15:46 +01:00
Kevin van Zonneveld
9928ef16d7 Update version 2016-11-08 13:07:29 +01:00
Kevin van Zonneveld
8f06b1a927 Release 2.1.0 2016-11-08 13:07:28 +01:00
Kevin van Zonneveld
e6275924b5 Update CHANGELOG.md 2016-11-08 13:07:20 +01:00
Manuel Streuhofer
f82bbe59b0 better logging. support for multiple lines. (#57)
* better logging: support for multiple lines

* renamed logging function from _fmt to __b3bp_log

* adding example to show how multiline logging works

the main idea is to be able to log e.g. the output of a command and
b3bp taking care of splitting and prefixing every line.

* simplified code, removed hacky space-at-EOL
2016-11-08 13:03:26 +01:00
Manuel Streuhofer
4445c181bb cleanup environment variables (#58)
all internally used variable names (e.g. the ones used while parsing
__usage and running the getopts loop) start with '__b3bp_tmp'. This
makes it easy to unset them all after the work is done.

additional bugfix: run getopts only if any options were actually
specified in __usage
2016-11-08 13:02:37 +01:00
Kevin van Zonneveld
86ab1128ed Add FAQ about accessing unset vars #16 (#42) 2016-11-08 12:58:33 +01:00
Mathieu Aubin
839df144ca Optimized/Minification of png and jpg (#50)
Couldnt go as far as playing with the pxm without atrocious google-fu
2016-09-29 13:37:09 +02:00
Josh
195e84fe09 Fix minor typo in README.md (#49)
There was a space in an instance of the word instead
2016-08-18 10:20:55 +02:00
Kevin van Zonneveld
34e437b23c Improved english (#43)
* Not completely done yet

* Not completely done yet either

* Update README.md

* One of two ways

* Prefer `source` over `.` for readability

* Use backticks where possible

* Update FAQ.md
2016-06-28 15:14:24 +02:00
Kevin van Zonneveld
35b51072b3 No more os detection (#41) 2016-06-24 13:12:41 +02:00
Kevin van Zonneveld
8bbba18f7e Offer the main template for download as http://bash3boilerplate.sh/main.sh 2016-06-24 11:47:28 +02:00
Kevin van Zonneveld
03a2ec5adf Better OS detection (#39) 2016-06-23 16:20:45 +02:00
Kevin van Zonneveld
bd49dda4b4 First swing at linting via Spellcheck #35 2016-06-23 14:13:46 +02:00
Kevin van Zonneveld
56e02e9306 Better button placement 2016-06-23 14:12:43 +02:00
Kevin van Zonneveld
3f0a7c9166 Remove confusion preview 2016-06-23 14:11:11 +02:00
Kevin van Zonneveld
1f2e1842b3 Elaborate on what portability really means for us 2016-06-23 10:07:58 +02:00
Kevin van Zonneveld
2b3ee1d195 Merge branch 'master' of github.com:kvz/bash3boilerplate 2016-06-23 09:48:45 +02:00
Kevin van Zonneveld
2d302dd8ac Be more precise with the extra permissive LICENSE clause 2016-06-23 09:48:24 +02:00
Izaak Beekman
f6a3bb55d4 Merge pull request #36 from Blackbaud-BobbyEarl/master
Fixed typo in README.md
2016-06-22 21:32:18 -04:00
Bobby Earl
3d22171ba3 Fixed typo 2016-06-22 19:25:06 -04:00
Kevin van Zonneveld
b3c3746948 Fix activity feed on homepage 2016-06-22 23:21:45 +02:00
Kevin van Zonneveld
c8441451bc Don't show activity feed on FAQ or CHANGELOG 2016-06-22 21:40:22 +02:00
Kevin van Zonneveld
e4848e360a Update CHANGELOG.md. #34 2016-06-22 20:46:52 +02:00
Kevin van Zonneveld
e0055e5dc1 Fix the bad wording around defaults #34
Thanks to galaktos
2016-06-22 20:44:15 +02:00
Kevin van Zonneveld
845a9dfb50 Clarify that {} is not always required, but rather b3bp-recommended #34
Thanks to galaktos
2016-06-22 20:41:53 +02:00
Kevin van Zonneveld
ca8c0a19df Credit galaktos 2016-06-22 20:39:21 +02:00
Kevin van Zonneveld
1166c878be Improve copy around single equal signs #34
Thanks to galaktos
2016-06-22 20:38:36 +02:00
Kevin van Zonneveld
9dea81377e Fix unquoted variable access within [ tests… #34
Thanks to galaktos
2016-06-22 20:36:17 +02:00
Kevin van Zonneveld
272dd896d0 Shorter title 2016-06-22 10:14:33 +02:00
Kevin van Zonneveld
bc1b96db71 Clean up and categorize best practices 2016-06-22 10:11:56 +02:00
Kevin van Zonneveld
818d7c81c7 Return Windows as OS when under Git Bash (?) #32 2016-06-22 09:52:38 +02:00
Kevin van Zonneveld
494584b6fd Typos 2016-06-21 20:20:57 +02:00
Kevin van Zonneveld
8e9814bc6a Use only http://cobralab.ca/ 2016-06-21 16:12:38 +02:00
Kevin van Zonneveld
dba28c0e8e Make the activity log more pleasant 2016-06-21 14:15:20 +02:00
Kevin van Zonneveld
be3ca43dff Add social banners 2016-06-21 14:06:25 +02:00
Kevin van Zonneveld
28865fc633 Update CHANGELOG.md 2016-06-21 13:55:17 +02:00
Kevin van Zonneveld
0bfba0661c Silence Atom stylelint complaints 2016-06-21 13:55:09 +02:00
Kevin van Zonneveld
e56e21dc37 b3bp dogfooding for acceptance.sh 2016-06-21 13:51:51 +02:00
Kevin van Zonneveld
09cf71d23c Make version replacement work across new form 2016-06-21 13:49:42 +02:00
Kevin van Zonneveld
64488e569a For delete-key-friendliness, bundle the commandline definition block along with its parser 2016-06-21 13:49:11 +02:00
Kevin van Zonneveld
e0aadaf50c Comment each set with a single line 2016-06-21 13:48:37 +02:00
Kevin van Zonneveld
008face7c8 Less verbose header comments 2016-06-21 13:48:08 +02:00
Kevin van Zonneveld
4926bbc942 For delete-key-friendliness, don't crash on undeclared help vars 2016-06-21 13:38:47 +02:00
Kevin van Zonneveld
83b13e5f55 Adopt a few more best practices from my old blogpost http://kvz.io/blog/2013/11/21/bash-best-practices/ 2016-06-21 13:37:47 +02:00
Kevin van Zonneveld
649b5a0f44 Introduce errtrace, which is on by default (BREAKING) 2016-06-21 13:36:48 +02:00
Kevin van Zonneveld
f7fc992b2d Update CHANGELOG.md 2016-06-21 13:36:28 +02:00
Kevin van Zonneveld
efefd5cf2b Update fixtures after introducing helptext 2016-06-21 13:08:43 +02:00
Kevin van Zonneveld
5ee427eef5 Allow adding a help that is not parsed. See #24 2016-06-21 12:30:12 +02:00
Kevin van Zonneveld
b71ca507ab Merge branch 'whouses' 2016-06-21 12:25:54 +02:00
Kevin van Zonneveld
8bed4a2aaf Add a FAQ: how to contribute to the websit 2016-06-21 12:19:02 +02:00
Kevin van Zonneveld
4c45be4269 Add a GitHub activity feed to the website 2016-06-21 12:18:50 +02:00
Kevin van Zonneveld
156f12f53f Merge pull request #31 from kvz/whouses
Add a who uses section to the readme/website
2016-06-21 11:57:19 +02:00
Kevin van Zonneveld
16401017e0 Invite folks to get listed 2016-06-21 11:52:22 +02:00
Kevin van Zonneveld
2d25f6b0dc Add a who uses section to the readme/website 2016-06-21 11:47:18 +02:00
Kevin van Zonneveld
400f29b30c Unsure if we'll do custom packages actually 2016-06-21 11:34:51 +02:00
Kevin van Zonneveld
95365e6f92 Syntax highlighting 2016-06-21 11:24:20 +02:00
Kevin van Zonneveld
26e282c37f Smoother navigation and changelog 2016-06-21 11:20:59 +02:00
Kevin van Zonneveld
7effd3c9d1 Document the b3bp abbreviation 2016-06-21 10:44:21 +02:00
Kevin van Zonneveld
90f52ea19a Add GA 2016-06-21 10:37:33 +02:00
Kevin van Zonneveld
65338c1660 Add FAQ about BASH vs Bash 2016-06-21 10:32:39 +02:00
Kevin van Zonneveld
fe733c1356 Elaborate on new best practice a little 2016-06-21 10:32:29 +02:00
Kevin van Zonneveld
ff881d529f Update CHANGELOG.md 2016-06-21 10:21:05 +02:00
Kevin van Zonneveld
ae230acc3b Add best practice of using __double_underscore_prefixed_vars 2016-06-21 10:21:00 +02:00
Kevin van Zonneveld
0487f12fff Fix os condition for deploys 2016-06-21 10:14:19 +02:00
Kevin van Zonneveld
00f84ff8d9 More website automation 2016-06-21 10:06:45 +02:00
Kevin van Zonneveld
fb8e44864d Make linux the deploy master 2016-06-21 09:42:53 +02:00
Kevin van Zonneveld
d0ece6da76 Website (#30)
* Base on apex.run

* More custom themie

* Loop to write

* Support inline links

* Smaller header

* Auto-deploys via travis

* Rewording to make for a better homepage
2016-06-21 09:40:25 +02:00
Kevin van Zonneveld
707a14634c Update README.md 2016-06-20 10:15:37 +02:00
Kevin van Zonneveld
18525f72da Make the license less restrictive. See #14 (#28)
* Make the license less restrictive. See #14

So that people can use _just_ main.sh without bothering with also
distributing the license

* Add license update to changelog

* Add a comment about expansion, see #26

* Use an unmodified MIT License, with the more permissive clause inside the code

As modifying the MIT License will needlessly (but rightfully) cause
suspicion

* Credit @bravo-kernel for his feedback

* Fix another typo

* Reword copyright
2016-06-20 09:57:31 +02:00
Kevin van Zonneveld
244e54daa6 Credit @jokajak 2016-06-20 09:44:57 +02:00
Kevin van Zonneveld
12f1013611 Credit @gdevenyi for his testing and suggestions 2016-06-19 13:17:52 +02:00
Kevin van Zonneveld
d70312e916 Add a comment about expansion, see #26 2016-06-19 13:13:38 +02:00
Kevin van Zonneveld
fc7802d707 Respect --no-color by setting the NO_COLOR flag in main.sh. Fixes #25. thx @gdevenyi 2016-06-19 13:06:53 +02:00
Kevin van Zonneveld
8687e384eb Split out changelog into separate file, credit @rouson for the FAQ 2016-03-03 12:45:07 +01:00
Kevin van Zonneveld
bbd4b7689b Whitespace 2016-03-03 12:41:55 +01:00
Kevin van Zonneveld
300ca2e3ad We're welcoming contributions! 2016-03-03 11:49:15 +01:00
Kevin van Zonneveld
fcb6d93028 More code highlighting 2016-03-03 11:49:00 +01:00
Kevin van Zonneveld
e20bb2900c Use automatic markdown numbering 2016-03-03 11:48:40 +01:00
Kevin van Zonneveld
547825b336 Add an explanation of magic vars 2016-03-03 11:48:21 +01:00
Kevin van Zonneveld
87017c728f More portable shebang 2016-03-03 11:39:57 +01:00
Kevin van Zonneveld
0db28b0eec Fix two broken anchors 2016-03-03 11:38:28 +01:00
Kevin van Zonneveld
0b79205fb1 Let's standardize on in-line links.
It may be a bit messy, but I also don't particularly enjoy the context switching that comes from scrolling back & forth in order to see if the links are still valid, or what is being linked to exactly, after a long break from the project.
2016-03-03 11:37:41 +01:00
Kevin van Zonneveld
9be08bb692 Merge pull request #15 from rouson/draft-faq
Draft FAQ
2016-03-03 11:34:30 +01:00
Damian Rouson
41b9451b20 Draft FAQ.md 2016-03-02 11:03:57 -08:00
Damian Rouson
1fc44d2034 Add TOC and FAQ.md link to README.md 2016-03-02 10:19:48 -08:00
Kevin van Zonneveld
a4326476a3 Update README.md 2016-02-25 10:28:22 +01:00
Kevin van Zonneveld
c1fecf33c3 Merge pull request #11 from kvz/osxfailpasses
Fix Travis OSX testing
2016-02-23 10:23:23 +01:00
Kevin van Zonneveld
676989a779 Add to release notes 2016-02-23 10:22:34 +01:00
Kevin van Zonneveld
51213e8786 Fix test again, now that we got confirmed failures out of Travis OSX #10 2016-02-23 10:21:43 +01:00
Kevin van Zonneveld
6dc7e1f92a Don't use a subshell to handle diff failures. Refs #10 2016-02-23 10:16:58 +01:00
Kevin van Zonneveld
c111725665 Purposely fail. Does this pass OSX Travis build? 2016-02-23 10:10:39 +01:00
Kevin van Zonneveld
abb480c394 Use accptst prefix so we can re-use this thing elsewhere 2016-02-23 10:06:45 +01:00
Kevin van Zonneveld
fa7f217556 Update README.md 2016-02-23 09:47:11 +01:00
Kevin van Zonneveld
32e061c102 Merge pull request #9 from zbeekman/mangle-long-opts
Mangle long-option names to allow dashes
2016-02-23 09:46:21 +01:00
Izaak Beekman
1143670cae
Update expected test output 2016-02-22 10:11:12 -05:00
Izaak Beekman
a86d8d82b1
Mangle long-option names to allow dashes
Fixes problem where long options with dashes, like `--no-color` were
 broken. This was due to the fact that bash variable names must match
 `[_a-zA-Z][_0-9a-zA-Z]*` and the usage parsing and option handling was
 trying to create variables with dashes in their names. Short of
 employing Bash4 associative arrays, "name mangling" seemed like the
 best solution to this problem.

Solution: map dashes to underscores when creating bash variables in the
script that correspond to long option flags. The downside of this is
that `--no_color` and `--no-color` will collide, but users expecting to
use options that are identical except one has an underscore and the
other has a dash deserve the ensuing confusion.
2016-02-19 23:25:09 -05:00
Kevin van Zonneveld
db690268ea Whitespace 2016-02-17 13:46:05 +01:00
Kevin van Zonneveld
d43cecf24a No longer try to use gsed in templater on OSX thanks to .bak workaround 2016-02-17 13:44:28 +01:00
Kevin van Zonneveld
0917b75cb9 Commit version info next time 2016-02-17 13:43:00 +01:00
Kevin van Zonneveld
a6d2a2ad2f Version info 2016-02-17 13:42:26 +01:00
Kevin van Zonneveld
366d8c7c9c Update version 2016-02-17 13:41:46 +01:00
Kevin van Zonneveld
0001bfe30c Release 2.0.0 2016-02-17 13:41:45 +01:00
Kevin van Zonneveld
2b46168792 Breaking release means new major 2016-02-17 13:39:05 +01:00
Kevin van Zonneveld
1271bf807d Add tests for megamount and follow Library export best practices 2016-02-17 13:38:55 +01:00
Kevin van Zonneveld
583efe734b Whitespace 2016-02-17 13:35:25 +01:00
Kevin van Zonneveld
07ab2a95b4 Remove bump & semver from src (BREAKING) 2016-02-17 13:35:17 +01:00
Kevin van Zonneveld
7fbf9ea8e5 Add tests for templater and follow Library export best practices 2016-02-17 13:19:03 +01:00
Kevin van Zonneveld
707583a93c Fix paths 2016-02-17 13:01:18 +01:00
Kevin van Zonneveld
e538a2be34 Rename inival->ini_val 2016-02-17 12:58:28 +01:00
Kevin van Zonneveld
c3f5bcf8c9 Add tests for parse_url and follow Library export best practices 2016-02-17 12:58:18 +01:00
Kevin van Zonneveld
180282d97d Add tests for ini_val and follow Library export best practices 2016-02-17 12:48:57 +01:00
Kevin van Zonneveld
b404c87999 Place version in src too 2016-02-17 12:48:46 +01:00
Kevin van Zonneveld
f2823681d0 Update changelog 2016-02-17 09:54:52 +01:00
Kevin van Zonneveld
67f2eafc81 Update version 2016-02-17 09:53:20 +01:00
Kevin van Zonneveld
c8773b999b Release 1.2.1 2016-02-17 09:53:19 +01:00
Kevin van Zonneveld
591642cb38 Release automation 2016-02-17 09:53:01 +01:00
Kevin van Zonneveld
c3297e4a7a Better versioning 2016-02-17 09:35:59 +01:00
Kevin van Zonneveld
619688bb0f Merge pull request #8 from kvz/node-less-ci
Bypass npm on Travis so we don't require node at all
2016-02-17 09:01:07 +01:00
Kevin van Zonneveld
1557e9d66a Bypass npm on Travis so we don't require node at all 2016-02-17 08:44:32 +01:00
Kevin van Zonneveld
72cea95865 Document travis.yml 2016-02-17 08:41:35 +01:00
Kevin van Zonneveld
33887625a7 Update README.md 2016-02-17 08:39:15 +01:00
Kevin van Zonneveld
c4b4f44676 Merge pull request #6 from zbeekman/test-osx-too
Test on OSX and Linux on Travis-CI
2016-02-17 08:30:09 +01:00
Izaak Beekman
f114dea34d
Test on OSX and Linux on Travis-CI 2016-02-17 00:09:48 -05:00
Kevin van Zonneveld
0c4a6c78e5 Doc improvements 2016-02-16 22:41:01 +01:00
Kevin van Zonneveld
980a5950d6 Add release-date 2016-02-16 22:25:18 +01:00
71 changed files with 3582 additions and 757 deletions

7
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,7 @@
Thanks for contributing to b3bp! As part of your PR, have you:
- [ ] Added an item in [CHANGELOG.md](https://github.com/kvz/bash3boilerplate/blob/HEAD/CHANGELOG.md) with attribution?
- [ ] Added your name to the [README.md](https://github.com/kvz/bash3boilerplate/blob/HEAD/README.md#authors)
- [ ] Linted your code? (`make test` should do the trick)
If so, great! Feel free to replace this message with a description of your work and hit submit!

5
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,5 @@
groups:
production-dependencies:
dependency-type: 'production'
development-dependencies:
dependency-type: 'development'

30
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: b3bp CI
on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: actions/setup-node@v1
with:
node-version: 18.x
- name: Install
run: |
corepack yarn
- name: Lint
env:
SHELLCHECK_SEVERITY: warning
run: |
corepack yarn lint
- name: Test
run: |
corepack yarn test

5
.gitignore vendored
View File

@ -1,2 +1,5 @@
npm-debug.log
.yarn
assets/build
env.sh
node_modules
npm-debug.log

3
.shellcheckrc Normal file
View File

@ -0,0 +1,3 @@
external-sources=true
shell=bash
color=always

View File

@ -1,7 +0,0 @@
language: node_js
node_js:
- "4.2.1"
script: npm run test
# For some reason, `sudo: false` broke nvm. Tried this build two times:
# https://s3.amazonaws.com/archive.travis-ci.org/jobs/109619626/log.txt
sudo: false

View File

@ -0,0 +1,8 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {}
}

1
.yarnrc.yml Normal file
View File

@ -0,0 +1 @@
nodeLinker: node-modules

175
CHANGELOG.md Normal file
View File

@ -0,0 +1,175 @@
# Changelog
Here's is a combined todo/done list. You can see what todos are planned for the upcoming release, as well as ideas that may/may not make into a release in `Ideas`.
## Ideas
Unplanned.
- [ ] Better style guide checking (#84)
## main
Released: TBA.
[Diff](https://github.com/kvz/bash3boilerplate/compare/2.7.2...main).
- [ ]
## 2.7.2
Released: 2023-08-29
[Diff](https://github.com/kvz/bash3boilerplate/compare/v2.4.1...2.7.2).
- [x] Upgrade and cleanup node dependencies
- [x] Remove lanyon-based website in favor of simple redirect to github for bash3boilerplate.sh
- [x] Make tests pass again
- [x] Make linting and style checking separate actions
- [x] Add feature to edit/update comments in ini file (#132, @rfuehrer)
- [x] Upgrade to `lanyon@0.1.16`
- [x] Capture correct error_code in err_report (#124, @eval)
- [x] Enhanced ini file handling: create new file, create new sections, handle default section, read key from given section (@rfuehrer)
## v2.4.2
Released: 2019-11-07.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v2.4.1...v2.4.2).
- [x] Upgrade to `lanyon@0.1.16`
- [x] Capture correct error_code in err_report (#124, @eval)
- [x] Enhanced ini file handling: create new file, create new sections, handle default section, read key from given section (@rfuehrer)
## v2.4.1
Released: 2019-11-07.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v2.3.0...v2.4.1).
- [x] Upgrade to `lanyon@0.1.7`
- [x] Allow counting how many times an argument is used (@genesiscloud)
- [x] Fix typos in megamount (thanks @gsaponaro)
- [x] Enable color in screen or tmux (#92, @gmasse)
- [x] Change `egrep` to `grep -E` in test and lib scripts to comply with ShellCheck (#92, @gmasse)
- [x] Fix typo in FAQ (#92, @gmasse)
- [x] Fix Travis CI failure on src/templater.sh (@gmasse)
- [x] Add magic variable which contains full command invocation
- [x] More contrasted alert and emergency colors (#111 @gmeral)
- [x] Add support for repeatable arguments (@genesiscloud)
- [x] Fix remaining warnings with shellcheck v0.7.0 (#107, @genesiscloud)
## v2.4.0
Released: 2016-12-21.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v2.3.0...v2.4.0).
- [x] Upgrade to `lanyon@0.0.143`
## v2.3.0
Released: 2016-12-21.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v2.2.0...v2.3.0).
- [x] Add magic variable `__i_am_main_script` to distinguish if b3bp is being sourced or called directly (#45, @zbeekman)
- [x] Add style checks for tab characters and trailing whitespace (@zbeekman)
- [x] Add backtracing to help localize errors (#44, @zbeekman)
- [x] Additional FAQ entries (#47, suggested by @gdevenyi, implemented by @zbeekman)
- [x] Ensure that shifting over `--` doesn't throw an errexit error (#21, @zbeekman)
- [x] Add Pull Request template (#83)
## v2.2.0
Released: 2016-12-21.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v2.1.0...v2.2.0).
- [x] README and FAQ improvements (#66, @mstreuhofer)
- [x] Add support for sourcing b3bp (#61, @mstreuhofer)
- [x] Upgrade all Node.js dependencies for development (#78)
- [x] Switch to http://lanyon.io for static site building, add a new logo
- [x] Cleanup environment variables (#58, @mstreuhofer)
- [x] Support multi-line logs (#57, @mstreuhofer)
- [x] Run shellcheck as part of the acceptance test (#79, @mstreuhofer)
- [x] Brace all variables, used `[[` instead of `[` (#33, #76, @mstreuhofer)
- [x] Add automatic usage validation for required args (#22, #65, @mstreuhofer)
- [x] Remove all usage of eval (@mstreuhofer)
- [x] Get rid of awk, sed & egrep usage (#71, @mstreuhofer)
- [x] Fix auto-color-off code (#69, #70, @mstreuhofer)
- [x] Use shellcheck to find and fix unclean code (#68, #80, @mstreuhofer)
- [x] Allow for multiline opt description in `__usage` (#7, @mstreuhofer)
- [x] Allow `__usage` and `__helptext` to be defined before sourcing `main.sh` thus makeing b3bp behave like a library (@mstreuhofer)
- [x] Add the same License text to each script header (@mstreuhofer)
## v2.1.0
Released: 2016-11-08.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v2.0.0...v2.1.0).
- [x] Cleanup b3bp variables (adds prefixes across the board) (thanks @mstreuhofer)
- [x] Add multi-line logging support (thanks @mstreuhofer)
- [x] Mangle long-option names to allow dashes (thanks @zbeekman)
- [x] Remove OS detection altogether (#38, thx @zbeekman)
- [x] Offer the main template for download as http://bash3boilerplate.sh/main.sh
- [x] Better OS detection (#38, thx @moviuro)
- [x] Improve README copy (#34, thx galaktos)
- [x] Fix unquoted variable access within (#34 thx galaktos)
- [x] For delete-key-friendliness, bundle the commandline definition block along with its parser
- [x] Less verbose header comments
- [x] For delete-key-friendliness, don't crash on undeclared help vars
- [x] Introduce `errtrace`, which is on by default (BREAKING)
- [x] Add a configurable `helptext` that is left alone by the parses and allows you to have a richer help
- [x] Add a simple documentation website
- [x] Add best practice of using `__double_underscore_prefixed_vars` to indicate global variables that are solely controlled inside your script
- [x] Make license more permissive by not requiring distribution of the LICENSE file if the copyright & attribution comments are left intact
- [x] Respect `--no-color` by setting the `NO_COLOR` flag in `main.sh` (#25, thx @gdevenyi)
- [x] Split out changelog into separate file
- [x] Added a [FAQ](./FAQ.md) (#15, #14, thanks @rouson)
- [x] Fix Travis OSX testing (before, it would silently pass failures) (#10)
- [x] Enable dashes in long, GNU style options, as well as numbers (thanks @zbeekman)
## v2.0.0
Released: 2016-02-17.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v1.2.1...v2.0.0).
- [x] Add tests for `templater` and follow Library export best practices
- [x] Add tests for `ini_val` and follow Library export best practices
- [x] Add tests for `parse_url` and follow Library export best practices
- [x] Add tests for `megamount` and follow Library export best practices
- [x] Remove `bump` from `src` (BREAKING)
- [x] Remove `semver` from `src` (BREAKING)
## v1.2.1
Released: 2016-02-17.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v1.2.0...v1.2.1).
- [x] Add Travis CI automated testing for OSX (thanks @zbeekman)
## v1.2.0
Released: 2016-02-16.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v1.1.0...v1.2.0).
- [x] Allow disabling colors via `NO_COLOR` environment variable
- [x] Enable `errexit`, `nounset` and `pipefail` options at the top of the script already
- [x] More refined colors (thanks @arathai)
- [x] Add a changelog to the README
- [x] Add `__os` magic var (limited to discovering OSX and defaulting to Linux for now)
- [x] Add `__base` magic var (`main`, if the source script is `main.sh`)
- [x] Enable long, GNU style options (thanks @zbeekman)
- [x] Add Travis CI automated testing for Linux
## v1.1.0
Released: 2015-06-29.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v1.0.3...v1.1.0).
- [x] Add `ALLOW_REMAINDERS` configuration to templater
- [x] Fix typo: 'debugmdoe' to 'debugmode' (thanks @jokajak)
- [x] Use `${BASH_SOURCE[0]}` for `__file` instead of `${0}`
## v1.0.3
Released: 2014-11-02.
[Diff](https://github.com/kvz/bash3boilerplate/compare/5db569125319a89b9561b434db84e4d91faefb63...v1.0.3).
- [x] Add `ini_val`, `megamount`, `parse_url`
- [x] Add re-usable libraries in `./src`
- [x] Use npm as an additional distribution channel

171
FAQ.md Normal file
View File

@ -0,0 +1,171 @@
[This document is formatted with GitHub-Flavored Markdown. ]: #
[For better viewing, including hyperlinks, read it online at ]: #
[https://github.com/kvz/bash3boilerplate/blob/HEAD/FAQ.md ]: #
## Contents
- [What is a CLI](#what-is-a-cli)?
- [How do I incorporate BASH3 Boilerplate into my own project](#how-do-i-incorporate-bash3-boilerplate-into-my-own-project)?
- [How do I add a command-line flag](#how-do-i-add-a-command-line-flag)?
- [How do I access the value of a command-line argument](#how-do-i-access-the-value-of-a-command-line-argument)?
- [What is a magic variable](#what-is-a-magic-variable)?
- [How do I submit an issue report](#how-do-i-submit-an-issue-report)?
- [How can I contribute to this project](#how-can-i-contribute-to-this-project)?
- [Why are you typing BASH in all caps](#why-are-you-typing-bash-in-all-caps)?
- [You are saying you are portable, but why won't b3bp code run in dash / busybox / posh / ksh / mksh / zsh](#you-are-saying-you-are-portable-but-why-wont-b3bp-code-run-in-dash--busybox--posh--ksh--mksh--zsh)?
- [How do I do Operating System detection](#how-do-i-do-operating-system-detection)?
- [How do I access a potentially unset (environment) variable](#how-do-i-access-a-potentially-unset-environment-variable)?
- [How can I detect or trap CTRL-C and other signals](#how-can-i-detect-or-trap-ctrl-c-and-other-signals)?
- [How can I get the PID of my running script](how-can-i-get-the-pid-of-my-running-script)?
<!--more-->
# Frequently Asked Questions
## What is a CLI?
A "CLI" is a [command-line interface](https://en.wikipedia.org/wiki/Command-line_interface).
## How do I incorporate BASH3 Boilerplate into my own project?
You can incorporate BASH3 Boilerplate into your project in one of two ways:
1. Copy the desired portions of [`main.sh`](http://bash3boilerplate.sh/main.sh) into your own script.
1. Download [`main.sh`](http://bash3boilerplate.sh/main.sh) and start pressing the delete-key to remove unwanted things
Once the `main.sh` has been tailor-made for your project, you can either append your own script in the same file, or source it in the following ways:
1. Copy [`main.sh`](http://bash3boilerplate.sh/main.sh) into the same directory as your script and then edit and embed it into your script using Bash's `source` include feature, e.g.:
```bash
#!/usr/bin/env bash
source main.sh
```
1. Source [`main.sh`](http://bash3boilerplate.sh/main.sh) in your script or at the command line:
```bash
#!/usr/bin/env bash
source main.sh
```
## How do I add a command-line flag?
1. Copy the line from the `main.sh` [read block](https://github.com/kvz/bash3boilerplate/blob/v2.1.0/main.sh#L109-L115) that most resembles the desired behavior and paste the line into the same block.
1. Edit the single-character (e.g., `-d`) and, if present, the multi-character (e.g., `--debug`) versions of the flag in the copied line.
1. Omit the `[arg]` text in the copied line, if the desired flag takes no arguments.
1. Omit or edit the text after `Default=` to set or not set default values, respectively.
1. Omit the `Required.` text, if the flag is optional.
## How do I access the value of a command-line argument?
To find out the value of an argument, append the corresponding single-character flag to the text `$arg_`. For example, if the [read block]
contains the line
```bash
-t --temp [arg] Location of tempfile. Default="/tmp/bar"
```
then you can evaluate the corresponding argument and assign it to a variable as follows:
```bash
__temp_file_name="${arg_t}"
```
## What is a magic variable?
The [magic variables](https://github.com/kvz/bash3boilerplate/blob/v2.1.0/main.sh#L26-L28) in `main.sh` are special in that they have a different value, depending on your environment. You can use `${__file}` to get a reference to your current script, and `${__dir}` to get a reference to the directory it lives in. This is not to be confused with the location of the calling script that might be sourcing the `${__file}`, which is accessible via `${0}`, or the current directory of the administrator running the script, accessible via `$(pwd)`.
## How do I submit an issue report?
Please visit our [Issues](https://github.com/kvz/bash3boilerplate/issues) page.
## How can I contribute to this project?
Please fork this repository. After that, create a branch containing your suggested changes and submit a pull request based on the main branch
of <https://github.com/kvz/bash3boilerplate/>. We are always more than happy to accept your contributions!
## Why are you typing BASH in all caps?
As an acronym, Bash stands for Bourne-again shell, and is usually written with one uppercase.
This project's name, however, is "BASH3 Boilerplate". It is a reference to
"[HTML5 Boilerplate](https://html5boilerplate.com/)", which was founded to serve a similar purpose,
only for crafting webpages.
Somewhat inconsistent but true to Unix ancestry the abbreviation for our project is "b3bp".
## You are saying you are portable, but why won't b3bp code run in dash / busybox / posh / ksh / mksh / zsh?
When we say _portable_, we mean across Bash versions. Bash is widespread and most systems
offer at least version 3 of it. Make sure you have that available and b3bp will work for you.
We run automated tests to make sure that it will. Here is some proof for the following platforms:
- [Linux](https://travis-ci.org/kvz/bash3boilerplate/jobs/109804166#L91-L94) `GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)`
- [OSX](https://travis-ci.org/kvz/bash3boilerplate/jobs/109804167#L2453-L2455) `GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)`
This portability, however, does not mean that we try to be compatible with
KornShell, Zsh, posh, yash, dash, or other shells. We allow syntax that would explode if
you pasted it in anything but Bash 3 and up.
## How do I do Operating System detection?
We used to offer a magic `__os` variable, but we quickly [discovered](https://github.com/kvz/bash3boilerplate/issues/38) that it would be hard
to create a satisfactory abstraction that is not only correct, but also covers enough use-cases,
while still having a relatively small footprint in `main.sh`.
For simple OS detection, we recommend using the `${OSTYPE}` variable available in Bash as
is demoed in [this stackoverflow post](http://stackoverflow.com/a/8597411/151666):
```bash
if [[ "${OSTYPE}" = "linux-gnu" ]]; then
echo "GNU Linux"
elif [[ "${OSTYPE}" = "darwin"* ]]; then
echo "Mac OSX"
elif [[ "${OSTYPE}" = "cygwin" ]]; then
echo "POSIX compatibility layer and Linux environment emulation for Windows"
elif [[ "${OSTYPE}" = "msys" ]]; then
echo "Lightweight shell and GNU utilities compiled for Windows (part of MinGW)"
elif [[ "${OSTYPE}" = "win32" ]]; then
echo "I'm not sure this can happen."
elif [[ "${OSTYPE}" = "freebsd"* ]]; then
echo "..."
else
echo "Unknown."
fi
```
## How do I access a potentially unset (environment) variable?
The set -o nounset line in `main.sh` causes error termination when an unset environment variables is detected as unbound. There are multiple ways to avoid this.
Some code to illustrate:
```bash
# method 1
echo ${NAME1:-Damian} # echos Damian, $NAME1 is still unset
# method 2
echo ${NAME2:=Damian} # echos Damian, $NAME2 is set to Damian
# method 3
NAME3=${NAME3:-Damian}; echo ${NAME3} # echos Damian, $NAME3 is set to Damian
```
This subject is briefly touched on as well in the [Safety and Portability section under point 5](README.md#safety-and-portability). b3bp currently uses [method 1](https://github.com/kvz/bash3boilerplate/blob/v2.1.0/main.sh#L252) when we want to access a variable that could be undeclared, and [method 3](https://github.com/kvz/bash3boilerplate/blob/v2.1.0/main.sh#L31) when we also want to set a default to an undeclared variable, because we feel it is more readable than method 2. We feel `:=` is easily overlooked, and not very beginner friendly. Method 3 seems more explicit in that regard in our humble opinion.
## How can I detect or trap Ctrl-C and other signals?
You can trap [Unix signals](https://en.wikipedia.org/wiki/Unix_signal) like [Ctrl-C](https://en.wikipedia.org/wiki/Control-C) with code similar to:
```bash
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
function ctrl_c() {
echo "** Trapped CTRL-C"
}
```
See http://mywiki.wooledge.org/SignalTrap for a list of signals, examples, and an in depth discussion.
## How can I get the PID of my running script?
The PID of a running script is contained in the `${$}` variable. This is _not_ the pid of any subshells. With Bash 4 you can get the PID of your subshell with `${BASHPID}`. For a comprehensive list of Bash built in variables see, e.g., http://www.tldp.org/LDP/abs/html/internalvariables.html

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2014 Kevin van Zonneveld
Copyright (c) 2013 Kevin van Zonneveld and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

View File

@ -3,6 +3,9 @@
#
# https://www.npmjs.com/package/fakefile
#
# Please do not edit this file directly, but propose changed upstream instead:
# https://github.com/kvz/fakefile/blob/main/Makefile
#
# This Makefile offers convience shortcuts into any Node.js project that utilizes npm scripts.
# It functions as a wrapper around the actual listed in `package.json`
# So instead of typing:
@ -25,10 +28,26 @@
# OSX users will have to install bash-completion
# (http://davidalger.com/development/bash-completion-on-os-x-with-brew/)
ifeq ($(shell test -e ./yarn.lock && echo -n yes),yes)
RUNNER=yarn
INSTALLER=yarn install
else
RUNNER=npm run
INSTALLER=npm install
endif
define npm_script_targets
TARGETS := $(shell node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"));}')
TARGETS := $(shell \
node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"));}'
| grep -v -E "^install$$"
)
$$(TARGETS):
npm run $(subst -,:,$(MAKECMDGOALS))
$(RUNNER) $(shell \
node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"), k);}'
| grep -E "^$(MAKECMDGOALS)\s"
| head -n1
| awk '{print $$2}'
)
.PHONY: $$(TARGETS)
endef
@ -37,4 +56,4 @@ $(eval $(call npm_script_targets))
# These npm run scripts are available, without needing to be mentioned in `package.json`
install:
npm run install
$(INSTALLER)

188
README.md
View File

@ -1,104 +1,109 @@
[![Build Status](https://travis-ci.org/kvz/bash3boilerplate.svg?branch=master)](https://travis-ci.org/kvz/bash3boilerplate)
[This document is formatted with GitHub-Flavored Markdown. ]: #
[For better viewing, including hyperlinks, read it online at ]: #
[https://github.com/kvz/bash3boilerplate/blob/HEAD/README.md]: #
When hacking up BASH scripts, I often find there are some
higher level things like logging, configuration, command-line argument
parsing that:
- [Overview](#overview)
- [Goals](#goals)
- [Features](#features)
- [Installation](#installation)
- [Changelog](#changelog)
- [Frequently Asked Questions](#frequently-asked-questions)
- [Best Practices](#best-practices)
- [Who uses b3bp](#who-uses-b3bp)
- [Authors](#authors)
- [License](#license)
- I need every time
- Take quite some effort to get right
- Keep you from your actual work
## Overview
<!--more-->
When hacking up Bash scripts, there are often things such as logging or command-line argument parsing that:
- You need every time
- Come with a number of pitfalls you want to avoid
- Keep you from your actual work
Here's an attempt to bundle those things in a generalized way so that
they are reusable as-is in most of my (and hopefully your, if not ping
me) programs.
they are reusable as-is in most scripts.
We call it "BASH3 Boilerplate" or b3bp for short.
## Goals
Delete-key-friendly. I propose people use `main.sh` as a base and remove the
parts they don't need, rather than introducing a ton of packages, includes, compilers, etc.
Delete-Key-**Friendly**. Instead of introducing packages, includes, compilers, etc., we propose using [`main.sh`](https://bash3boilerplate.sh/main.sh) as a base and removing the parts you don't need.
While this may feel a bit archaic at first, it is exactly the strength of Bash scripts that we should want to embrace.
Aiming for portability, I'm targeting Bash 3 (OSX still ships
with 3 for instance). If you're going to ask people to install
**Portable**. We are targeting Bash 3 (OSX still ships
with 3, for instance). If you are going to ask people to install
Bash 4 first, you might as well pick a more advanced language as a
dependency.
## Features
- Structure
- Conventions that will make sure that all your scripts follow the same, battle-tested structure
- Safe by default (break on error, pipefail, etc.)
- Configuration by environment variables
- Configuration by command-line arguments (definitions parsed from help info,
so no duplication needed)
- Magic variables like `__file` and `__dir`
- Logging that supports colors and is compatible with [Syslog Severity levels](http://en.wikipedia.org/wiki/Syslog#Severity_levels)
- Simple command-line argument parsing that requires no external dependencies. Definitions are parsed from help info, ensuring there will be no duplication
- Helpful magic variables like `__file` and `__dir`
- Logging that supports colors and is compatible with [Syslog Severity levels](https://en.wikipedia.org/wiki/Syslog#Severity_levels), as well as the [twelve-factor](https://12factor.net/) guidelines
## Installation
There are 3 ways you can install (parts of) b3bp:
There are three different ways to install b3bp:
1. Just get the main template: `wget https://raw.githubusercontent.com/kvz/bash3boilerplate/master/main.sh`
2. Clone the entire project: `git clone git@github.com:kvz/bash3boilerplate.git`
3. As of `v1.0.3`, b3bp can be installed as a `package.json` dependency via: `npm install --save bash3boilerplate`
### Option 1: Download the main template
Although `3` introduces a node.js dependency, this does allow for easy version pinning & distrubtions in environments that already have this prerequisite. But nothing prevents you from just using `curl` and keep your project or build system low on external dependencies.
Use curl or wget to download the source and save it as your script. Then you can start deleting the unwanted bits, and adding your own logic.
## Versioning
```bash
wget https://bash3boilerplate.sh/main.sh
vim main.sh
```
This project implements the Semantic Versioning guidelines.
### Option 2: Clone the entire project
Releases will be numbered with the following format:
Besides `main.sh`, this will also get you the entire b3bp repository. This includes a few extra functions that we keep in the `./src` directory.
`<major>.<minor>.<patch>`
```bash
git clone git@github.com:kvz/bash3boilerplate.git
```
And constructed with the following guidelines:
### Option 3: Require via npm
- Breaking backward compatibility bumps the major (and resets the minor and patch)
- New additions without breaking backward compatibility bumps the minor (and resets the patch)
- Bug fixes and misc changes bumps the patch
As of `v1.0.3`, b3bp can also be installed as a Node module, meaning you can define it as a dependency in `package.json` via:
For more information on SemVer, please visit [http://semver.org](http://semver.org).
```bash
npm init
npm install --save --save-exact bash3boilerplate
```
Even though this option introduces a Node.js dependency, it does allow for easy version pinning and distribution in environments that already have this prerequisite. This is, however, entirely optional and nothing prevents you from ignoring this possibility.
## Changelog
### v1.2.0 (Unreleased)
Please see the [CHANGELOG.md](./CHANGELOG.md) file.
- Allow disabling colors via `NO_COLOR` environment variable
- Enable errexit, nounset and pipefail at the top
- More refined colors (thanks @arathai)
- Add Changelog
- Add `__os` magic var
- Add `__base` magic var
- Enable long, GNU style options (thanks @zbeekman)
## Frequently Asked Questions
### v1.1.0 (2015-06-29)
- Add `ALLOW_REMAINDERS` configuration to templater
- Fix typo: 'debugmdoe' to 'debugmode' (thanks @jokajak)
- Use `${BASH_SOURCE[0]}` for `__file` instead of `${0}`
### v1.0.3 (2014-11-02)
- Add `ini_val`, `megamount`, `parse_url`
- Add re-usable libraries in `./src`
- Use npm for distribution
Please see the [FAQ.md](./FAQ.md) file.
## Best practices
As of `v1.0.3`, b3bp adds some nice re-usable libraries in `./src`. Later on we'll be using snippets inside this directory to build custom packages. In order to make the snippets in `./src` more useful, we recommend these guidelines.
As of `v1.0.3`, b3bp offers some nice re-usable libraries in `./src`. In order to make the snippets in `./src` more useful, we recommend the following guidelines.
### Library exports
### Function packaging
It's nice to have a bash package that can be used in the terminal and also be invoked as a command line function. To achieve this the exporting of your functionality *should* follow this pattern:
It is nice to have a Bash package that can not only be used in the terminal, but also invoked as a command line function. In order to achieve this, the exporting of your functionality _should_ follow this pattern:
```bash
if [ "${BASH_SOURCE[0]}" != ${0} ]; then
export -f my_script
else
if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then
my_script "${@}"
exit $?
fi
export -f my_script
```
This allows a user to `source` your script or invoke as a script.
This allows a user to `source` your script or invoke it as a script.
```bash
# Running as a script
@ -108,24 +113,63 @@ $ source my_script.sh
$ my_script some more args --blah
```
(taken from the [bpkg](https://raw.githubusercontent.com/bpkg/bpkg/master/README.md) project)
(taken from the [bpkg](https://raw.githubusercontent.com/bpkg/bpkg/HEAD/README.md) project)
## Todo
### Scoping
- [ ] Make `src` libs adhere to Best practices
- [ ] `make build` system for generating custom builds
- [ ] tests & releases via Travis
1. In functions, use `local` before every variable declaration.
1. Use `UPPERCASE_VARS` to indicate environment variables that can be controlled outside your script.
1. Use `__double_underscore_prefixed_vars` to indicate global variables that are solely controlled inside your script, with the exception of arguments that are already prefixed with `arg_`, as well as functions, over which b3bp poses no restrictions.
## Sponsoring
### Coding style
<!-- badges/ -->
[![Gittip donate button](http://img.shields.io/gittip/kvz.png)](https://www.gittip.com/kvz/ "Sponsor the development of bash3boilerplate via Gittip")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=green)](https://flattr.com/submit/auto?user_id=kvz&url=https://github.com/kvz/bash3boilerplate&title=bash3boilerplate&language=&tags=github&category=software "Sponsor the development of bash3boilerplate via Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=green)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kevin%40vanzonneveld%2enet&lc=NL&item_name=Open%20source%20donation%20to%20Kevin%20van%20Zonneveld&currency_code=USD&bn=PP-DonationsBF%3abtn_donate_SM%2egif%3aNonHosted "Sponsor the development of bash3boilerplate via Paypal")
[![BitCoin donate button](http://img.shields.io/bitcoin/donate.png?color=green)](https://coinbase.com/checkouts/19BtCjLCboRgTAXiaEvnvkdoRyjd843Dg2 "Sponsor the development of bash3boilerplate via BitCoin")
<!-- /badges -->
1. Use two spaces for tabs, do not use tab characters.
1. Do not introduce whitespace at the end of lines or on blank lines as they obfuscate version control diffs.
1. Use long options (`logger --priority` vs `logger -p`). If you are on the CLI, abbreviations make sense for efficiency. Nevertheless, when you are writing reusable scripts, a few extra keystrokes will pay off in readability and avoid ventures into man pages in the future, either by you or your collaborators. Similarly, we prefer `set -o nounset` over `set -u`.
1. Use a single equal sign when checking `if [[ "${NAME}" = "Kevin" ]]`; double or triple signs are not needed.
1. Use the new bash builtin test operator (`[[ ... ]]`) rather than the old single square bracket test operator or explicit call to `test`.
### Safety and Portability
1. Use `{}` to enclose your variables. Otherwise, Bash will try to access the `$ENVIRONMENT_app` variable in `/srv/$ENVIRONMENT_app`, whereas you probably intended `/srv/${ENVIRONMENT}_app`. Since it is easy to miss cases like this, we recommend that you make enclosing a habit.
1. Use `set`, rather than relying on a shebang like `#!/usr/bin/env bash -e`, since that is neutralized when someone runs your script as `bash yourscript.sh`.
1. Use `#!/usr/bin/env bash`, as it is more portable than `#!/bin/bash`.
1. Use `${BASH_SOURCE[0]}` if you refer to current file, even if it is sourced by a parent script. In other cases, use `${0}`.
1. Use `:-` if you want to test variables that could be undeclared. For instance, with `if [[ "${NAME:-}" = "Kevin" ]]`, `$NAME` will evaluate to `Kevin` if the variable is empty. The variable itself will remain unchanged. The syntax to assign a default value is `${NAME:=Kevin}`.
## Who uses b3bp?
- [Transloadit](https://transloadit.com)
- [OpenCoarrays](https://www.opencoarrays.org)
- [Sourcery Institute](https://www.sourceryinstitute.org)
- [Computational Brain Anatomy Laboratory](https://cobralab.ca/)
- [Genesis Cloud](https://genesiscloud.com/)
We are looking for endorsements! Are you also using b3bp? [Let us know](https://github.com/kvz/bash3boilerplate/issues/new?title=I%20use%20b3bp) and get listed.
## Authors
- [Kevin van Zonneveld](https://kvz.io)
- [Izaak Beekman](https://izaakbeekman.com/)
- [Manuel Streuhofer](https://github.com/mstreuhofer)
- [Alexander Rathai](mailto:Alexander.Rathai@gmail.com)
- [Dr. Damian Rouson](https://www.sourceryinstitute.org/) (documentation, feedback)
- [@jokajak](https://github.com/jokajak) (documentation)
- [Gabriel A. Devenyi](https://staticwave.ca/) (feedback)
- [@bravo-kernel](https://github.com/bravo-kernel) (feedback)
- [@skanga](https://github.com/skanga) (feedback)
- [galaktos](https://www.reddit.com/user/galaktos) (feedback)
- [@moviuro](https://github.com/moviuro) (feedback)
- [Giovanni Saponaro](https://github.com/gsaponaro) (feedback)
- [Germain Masse](https://github.com/gmasse)
- [A. G. Madi](https://github.com/warpengineer)
- [Lukas Stockner](mailto:oss@genesiscloud.com)
- [Gert Goet](https://github.com/eval)
- [@rfuehrer](https://github.com/rfuehrer)
## License
Copyright (c) 2013 Kevin van Zonneveld, [http://kvz.io](http://kvz.io)
Licensed under MIT: [http://kvz.io/licenses/LICENSE-MIT](http://kvz.io/licenses/LICENSE-MIT)
Copyright (c) 2013 Kevin van Zonneveld and [contributors](https://github.com/kvz/bash3boilerplate#authors).
Licensed under [MIT](https://raw.githubusercontent.com/kvz/bash3boilerplate/HEAD/LICENSE).
You are not obligated to bundle the LICENSE file with your b3bp projects as long
as you leave these references intact in the header comments of your source files.

1
docs/CNAME Normal file
View File

@ -0,0 +1 @@
bash3boilerplate.sh

15
docs/index.html Normal file
View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
http-equiv="refresh"
content="0;url=https://github.com/kvz/bash3boilerplate"
/>
<title>Redirecting...</title>
</head>
<body>
If you are not redirected,
<a href="https://github.com/kvz/bash3boilerplate">click here</a>.
</body>
</html>

147
example.sh Executable file
View File

@ -0,0 +1,147 @@
#!/usr/bin/env bash
# This file:
#
# - Demos BASH3 Boilerplate (change this for your script)
#
# Usage:
#
# LOG_LEVEL=7 ./example.sh -f /tmp/x -d (change this for your script)
#
# Based on a template by BASH3 Boilerplate v2.3.0
# http://bash3boilerplate.sh/#authors
#
# The MIT License (MIT)
# Copyright (c) 2013 Kevin van Zonneveld and contributors
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
# as you leave these references intact in the header comments of your source files.
### BASH3 Boilerplate (b3bp) Header
##############################################################################
# Commandline options. This defines the usage page, and is used to parse cli
# opts & defaults from. The parsing is unforgiving so be precise in your syntax
# - A short option must be preset for every long option; but every short option
# need not have a long option
# - `--` is respected as the separator between options and arguments
# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}.
# you can use bash variables to work around this (so use ${HOME} instead)
# shellcheck disable=SC2034
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-f --file [arg] Filename to process. Required.
-t --temp [arg] Location of tempfile. Default="/tmp/bar"
-v Enable verbose mode, print script as it is executed
-d --debug Enables debug mode
-h --help This page
-n --no-color Disable color output
-1 --one Do just one thing
-i --input [arg] File to process. Can be repeated.
-x Specify a flag. Can be repeated.
EOF
# shellcheck disable=SC2034
read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered
This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not
parsed and will be added as-is to the help.
EOF
# shellcheck source=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=${?}
# shellcheck disable=SC2154
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)
##############################################################################
# debug mode
if [[ "${arg_d:?}" = "1" ]]; then
set -o xtrace
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
LOG_LEVEL="7"
# Enable error backtracing
trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
fi
# verbose mode
if [[ "${arg_v:?}" = "1" ]]; then
set -o verbose
fi
# no color mode
if [[ "${arg_n:?}" = "1" ]]; then
NO_COLOR="true"
fi
# help mode
if [[ "${arg_h:?}" = "1" ]]; then
# Help exists with code 1
help "Help using ${0}"
fi
### Validation. Error out if the things required for your script are not present
##############################################################################
[[ "${arg_f:-}" ]] || help "Setting a filename with -f or --file is required"
[[ "${LOG_LEVEL:-}" ]] || emergency "Cannot continue without LOG_LEVEL. "
### Runtime
##############################################################################
# shellcheck disable=SC2154
info "__i_am_main_script: ${__i_am_main_script}"
# shellcheck disable=SC2154
info "__file: ${__file}"
# shellcheck disable=SC2154
info "__dir: ${__dir}"
# shellcheck disable=SC2154
info "__base: ${__base}"
info "OSTYPE: ${OSTYPE}"
info "arg_f: ${arg_f}"
info "arg_d: ${arg_d}"
info "arg_v: ${arg_v}"
info "arg_h: ${arg_h}"
if [[ -n "${arg_i:-}" ]]; then
info "arg_i: ${#arg_i[@]}"
for input_file in "${arg_i[@]}"; do
info " - ${input_file}"
done
else
info "arg_i: 0"
fi
# shellcheck disable=SC2015
[[ -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/'")"
# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software
debug "Info useful to developers for debugging the application, not useful during operations."
info "Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required."
notice "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."
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."
error "Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time."
critical "Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection."
alert "Should be corrected immediately, therefore notify staff who can fix the problem. An example would be the loss of a primary ISP connection."
emergency "A \"panic\" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call."

542
main.sh
View File

@ -1,244 +1,452 @@
#!/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 1.2.0
#
# Authors:
# - Kevin van Zonneveld (http://kvz.io)
# - Izaak Beekman (https://izaakbeekman.com/)
# - Alexander Rathai (Alexander.Rathai@gmail.com)
# - Demos BASH3 Boilerplate (change this for your script)
#
# Usage:
# LOG_LEVEL=7 ./main.sh -f /tmp/x -d
#
# Licensed under MIT
# Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io)
# LOG_LEVEL=7 ./main.sh -f /tmp/x -d (change this for your script)
#
# Based on a template by BASH3 Boilerplate vv2.7.2
# http://bash3boilerplate.sh/#authors
#
# The MIT License (MIT)
# Copyright (c) 2013 Kevin van Zonneveld and contributors
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
# as you leave these references intact in the header comments of your source files.
### Configuration
#####################################################################
# 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
# when someone runs your script as `bash yourscript.sh`
# 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
# Bash will remember & return the highest exitcode in a chain of pipes.
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip`
# 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
# Environment variables and their defaults
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
__i_am_main_script="0" # false
if [[ "${__usage+x}" ]]; then
if [[ "${BASH_SOURCE[1]}" = "${0}" ]]; then
__i_am_main_script="1" # true
fi
__b3bp_external_usage="true"
__b3bp_tmp_source_idx=1
fi
else
__i_am_main_script="1" # true
[[ "${__usage+x}" ]] && unset -v __usage
[[ "${__helptext+x}" ]] && unset -v __helptext
fi
# Set magic variables for current file, directory, os, etc.
__dir="$(cd "$(dirname "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")"
__base="$(basename "${__file}" .sh)"
# shellcheck disable=SC2034,SC2015
__invocation="$(printf %q "${__file}")$( (($#)) && printf ' %q' "$@" || true)"
# Define the environment variables (and their defaults) that this script depends on
LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency
NO_COLOR="${NO_COLOR:-}" # true = disable color. otherwise autodetected
### Functions
##############################################################################
function __b3bp_log () {
local log_level="${1}"
shift
# shellcheck disable=SC2034
local color_debug="\\x1b[35m"
# shellcheck disable=SC2034
local color_info="\\x1b[32m"
# shellcheck disable=SC2034
local color_notice="\\x1b[34m"
# shellcheck disable=SC2034
local color_warning="\\x1b[33m"
# shellcheck disable=SC2034
local color_error="\\x1b[31m"
# shellcheck disable=SC2034
local color_critical="\\x1b[1;31m"
# shellcheck disable=SC2034
local color_alert="\\x1b[1;37;41m"
# shellcheck disable=SC2034
local color_emergency="\\x1b[1;4;5;37;41m"
local colorvar="color_${log_level}"
local color="${!colorvar:-${color_error}}"
local color_reset="\\x1b[0m"
if [[ "${NO_COLOR:-}" = "true" ]] || { [[ "${TERM:-}" != "xterm"* ]] && [[ "${TERM:-}" != "screen"* ]]; } || [[ ! -t 2 ]]; then
if [[ "${NO_COLOR:-}" != "false" ]]; then
# Don't use colors on pipes or non-recognized terminals
color=""; color_reset=""
fi
fi
# all remaining arguments are to be printed
local log_line=""
while IFS=$'\n' read -r log_line; do
echo -e "$(date -u +"%Y-%m-%d %H:%M:%S UTC") ${color}$(printf "[%9s]" "${log_level}")${color_reset} ${log_line}" 1>&2
done <<< "${@:-}"
}
function emergency () { __b3bp_log emergency "${@}"; exit 1; }
function alert () { [[ "${LOG_LEVEL:-0}" -ge 1 ]] && __b3bp_log alert "${@}"; true; }
function critical () { [[ "${LOG_LEVEL:-0}" -ge 2 ]] && __b3bp_log critical "${@}"; true; }
function error () { [[ "${LOG_LEVEL:-0}" -ge 3 ]] && __b3bp_log error "${@}"; true; }
function warning () { [[ "${LOG_LEVEL:-0}" -ge 4 ]] && __b3bp_log warning "${@}"; true; }
function notice () { [[ "${LOG_LEVEL:-0}" -ge 5 ]] && __b3bp_log notice "${@}"; true; }
function info () { [[ "${LOG_LEVEL:-0}" -ge 6 ]] && __b3bp_log info "${@}"; true; }
function debug () { [[ "${LOG_LEVEL:-0}" -ge 7 ]] && __b3bp_log debug "${@}"; true; }
function help () {
echo "" 1>&2
echo " ${*}" 1>&2
echo "" 1>&2
echo " ${__usage:-No usage available}" 1>&2
echo "" 1>&2
if [[ "${__helptext:-}" ]]; then
echo " ${__helptext}" 1>&2
echo "" 1>&2
fi
exit 1
}
### Parse commandline options
##############################################################################
# Commandline options. This defines the usage page, and is used to parse cli
# opts & defaults from. The parsing is unforgiving so be precise in your syntax
# - A short option must be preset for every long option; but every short option
# need not have a long option
# - `--` is respected as the separator between options and arguments
read -r -d '' usage <<-'EOF' || true # exits non-zero when EOF encountered
# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}.
# you can use bash variables to work around this (so use ${HOME} instead)
# shellcheck disable=SC2015
[[ "${__usage+x}" ]] || read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-f --file [arg] Filename to process. Required.
-t --temp [arg] Location of tempfile. Default="/tmp/bar"
-v Enable verbose mode, print script as it is executed
-d --debug Enables debug mode
-h --help This page
-n --no-color Disable color output
-1 --one Do just one thing
-i --input [arg] File to process. Can be repeated.
-x Specify a flag. Can be repeated.
EOF
# Set magic variables for current file and its directory.
# BASH_SOURCE[0] is used so we can display the current file even if it is sourced by a parent script.
# If you need the script that was executed, consider using $0 instead.
__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
### Functions
#####################################################################
function _fmt () {
local color_debug="\x1b[35m"
local color_info="\x1b[32m"
local color_notice="\x1b[34m"
local color_warning="\x1b[33m"
local color_error="\x1b[31m"
local color_critical="\x1b[1;31m"
local color_alert="\x1b[1;33;41m"
local color_emergency="\x1b[1;4;5;33;41m"
local colorvar=color_$1
local color="${!colorvar:-$color_error}"
local color_reset="\x1b[0m"
if [ "${NO_COLOR}" = "true" ] || [[ "${TERM:-}" != "xterm"* ]] || [ -t 1 ]; then
# Don't use colors on pipes or non-recognized terminals
color=""; color_reset=""
fi
echo -e "$(date -u +"%Y-%m-%d %H:%M:%S UTC") ${color}$(printf "[%9s]" ${1})${color_reset}";
}
function emergency () { echo "$(_fmt emergency) ${@}" 1>&2 || true; exit 1; }
function alert () { [ "${LOG_LEVEL}" -ge 1 ] && echo "$(_fmt alert) ${@}" 1>&2 || true; }
function critical () { [ "${LOG_LEVEL}" -ge 2 ] && echo "$(_fmt critical) ${@}" 1>&2 || true; }
function error () { [ "${LOG_LEVEL}" -ge 3 ] && echo "$(_fmt error) ${@}" 1>&2 || true; }
function warning () { [ "${LOG_LEVEL}" -ge 4 ] && echo "$(_fmt warning) ${@}" 1>&2 || true; }
function notice () { [ "${LOG_LEVEL}" -ge 5 ] && echo "$(_fmt notice) ${@}" 1>&2 || true; }
function info () { [ "${LOG_LEVEL}" -ge 6 ] && echo "$(_fmt info) ${@}" 1>&2 || true; }
function debug () { [ "${LOG_LEVEL}" -ge 7 ] && echo "$(_fmt debug) ${@}" 1>&2 || true; }
function help () {
echo "" 1>&2
echo " ${@}" 1>&2
echo "" 1>&2
echo " ${usage}" 1>&2
echo "" 1>&2
exit 1
}
function cleanup_before_exit () {
info "Cleaning up. Done"
}
trap cleanup_before_exit EXIT
### Parse commandline options
#####################################################################
# shellcheck disable=SC2015
[[ "${__helptext+x}" ]] || read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered
This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not
parsed and will be added as-is to the help.
EOF
# Translate usage string -> getopts arguments, and set $arg_<flag> defaults
while read line; do
# fetch single character version of option sting
opt="$(echo "${line}" |awk '{print $1}' |sed -e 's#^-##')"
while read -r __b3bp_tmp_line; do
if [[ "${__b3bp_tmp_line}" =~ ^- ]]; then
# fetch single character version of option string
__b3bp_tmp_opt="${__b3bp_tmp_line%% *}"
__b3bp_tmp_opt="${__b3bp_tmp_opt:1}"
# fetch long version if present
long_opt="$(echo "${line}" |awk '/\-\-/ {print $2}' |sed -e 's#^--##')"
# fetch long version if present
__b3bp_tmp_long_opt=""
# map long name back to short name
varname="short_opt_${long_opt}"
eval "${varname}=\"${opt}\""
# check if option takes an argument
varname="has_arg_${opt}"
if ! echo "${line}" |egrep '\[.*\]' >/dev/null 2>&1; then
init="0" # it's a flag. init with 0
eval "${varname}=0"
else
opt="${opt}:" # add : if opt has arg
init="" # it has an arg. init with ""
eval "${varname}=1"
fi
opts="${opts:-}${opt}"
varname="arg_${opt:0:1}"
if ! echo "${line}" |egrep '\. Default=' >/dev/null 2>&1; then
eval "${varname}=\"${init}\""
else
match="$(echo "${line}" |sed 's#^.*Default=\(\)#\1#g')"
eval "${varname}=\"${match}\""
fi
done <<< "${usage}"
# Allow long options like --this
opts="${opts}-:"
# Reset in case getopts has been used previously in the shell.
OPTIND=1
# Overwrite $arg_<flag> defaults with the actual CLI options
while getopts "${opts}" opt; do
[ "${opt}" = "?" ] && help "Invalid use of script: ${@} "
if [ "${opt}" = "-" ]; then
# OPTARG is long-option-name or long-option=value
if [[ "${OPTARG}" =~ .*=.* ]]; then
# --key=value format
long=${OPTARG/=*/}
# Set opt to the short option corresponding to the long option
eval "opt=\"\${short_opt_${long}}\""
OPTARG=${OPTARG#*=}
else
# --key value format
# Map long name to short version of option
eval "opt=\"\${short_opt_${OPTARG}}\""
# Only assign OPTARG if option takes an argument
eval "OPTARG=\"\${@:OPTIND:\${has_arg_${opt}}}\""
# shift over the argument if argument is expected
((OPTIND+=has_arg_${opt}))
if [[ "${__b3bp_tmp_line}" = *"--"* ]]; then
__b3bp_tmp_long_opt="${__b3bp_tmp_line#*--}"
__b3bp_tmp_long_opt="${__b3bp_tmp_long_opt%% *}"
fi
# we have set opt/OPTARG to the short value and the argument as OPTARG if it exists
fi
varname="arg_${opt:0:1}"
default="${!varname}"
value="${OPTARG:-}"
if [ -z "${OPTARG:-}" ] && [ "${default}" = "0" ]; then
value="1"
# map opt long name to+from opt short name
printf -v "__b3bp_tmp_opt_long2short_${__b3bp_tmp_long_opt//-/_}" '%s' "${__b3bp_tmp_opt}"
printf -v "__b3bp_tmp_opt_short2long_${__b3bp_tmp_opt}" '%s' "${__b3bp_tmp_long_opt//-/_}"
# check if option takes an argument
if [[ "${__b3bp_tmp_line}" =~ \[.*\] ]]; then
__b3bp_tmp_opt="${__b3bp_tmp_opt}:" # add : if opt has arg
__b3bp_tmp_init="" # it has an arg. init with ""
printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "1"
elif [[ "${__b3bp_tmp_line}" =~ \{.*\} ]]; then
__b3bp_tmp_opt="${__b3bp_tmp_opt}:" # add : if opt has arg
__b3bp_tmp_init="" # it has an arg. init with ""
# remember that this option requires an argument
printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2"
else
__b3bp_tmp_init="0" # it's a flag. init with 0
printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "0"
fi
__b3bp_tmp_opts="${__b3bp_tmp_opts:-}${__b3bp_tmp_opt}"
if [[ "${__b3bp_tmp_line}" =~ ^Can\ be\ repeated\. ]] || [[ "${__b3bp_tmp_line}" =~ \.\ *Can\ be\ repeated\. ]]; then
# remember that this option can be repeated
printf -v "__b3bp_tmp_is_array_${__b3bp_tmp_opt:0:1}" '%s' "1"
else
printf -v "__b3bp_tmp_is_array_${__b3bp_tmp_opt:0:1}" '%s' "0"
fi
fi
eval "${varname}=\"${value}\""
debug "cli arg ${varname} = ($default) -> ${!varname}"
[[ "${__b3bp_tmp_opt:-}" ]] || continue
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]}"
fi
fi
fi
fi
if [[ "${__b3bp_tmp_line}" =~ ^Required\. ]] || [[ "${__b3bp_tmp_line}" =~ \.\ *Required\. ]]; then
# remember that this option requires an argument
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:-}"
# run getopts only if options were specified in __usage
if [[ "${__b3bp_tmp_opts:-}" ]]; then
# Allow long options like --this
__b3bp_tmp_opts="${__b3bp_tmp_opts}-:"
# Reset in case getopts has been used previously in the shell.
OPTIND=1
# start parsing command line
set +o nounset # unexpected arguments will cause unbound variables
# to be dereferenced
# Overwrite $arg_<flag> defaults with the actual CLI options
while getopts "${__b3bp_tmp_opts}" __b3bp_tmp_opt; do
[[ "${__b3bp_tmp_opt}" = "?" ]] && help "Invalid use of script: ${*} "
if [[ "${__b3bp_tmp_opt}" = "-" ]]; then
# OPTARG is long-option-name or long-option=value
if [[ "${OPTARG}" =~ .*=.* ]]; then
# --key=value format
__b3bp_tmp_long_opt=${OPTARG/=*/}
# Set opt to the short option corresponding to the long option
__b3bp_tmp_varname="__b3bp_tmp_opt_long2short_${__b3bp_tmp_long_opt//-/_}"
printf -v "__b3bp_tmp_opt" '%s' "${!__b3bp_tmp_varname}"
OPTARG=${OPTARG#*=}
else
# --key value format
# Map long name to short version of option
__b3bp_tmp_varname="__b3bp_tmp_opt_long2short_${OPTARG//-/_}"
printf -v "__b3bp_tmp_opt" '%s' "${!__b3bp_tmp_varname}"
# Only assign OPTARG if option takes an argument
__b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt}"
__b3bp_tmp_varvalue="${!__b3bp_tmp_varname}"
[[ "${__b3bp_tmp_varvalue}" != "0" ]] && __b3bp_tmp_varvalue="1"
printf -v "OPTARG" '%s' "${@:OPTIND:${__b3bp_tmp_varvalue}}"
# shift over the argument if argument is expected
((OPTIND+=__b3bp_tmp_varvalue))
fi
# we have set opt/OPTARG to the short value and the argument as OPTARG if it exists
fi
__b3bp_tmp_value="${OPTARG}"
__b3bp_tmp_varname="__b3bp_tmp_is_array_${__b3bp_tmp_opt:0:1}"
if [[ "${!__b3bp_tmp_varname}" != "0" ]]; then
# repeatables
# shellcheck disable=SC2016
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}"
# shellcheck disable=SC2004
__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}"
if [[ -z "${OPTARG}" ]]; then
__b3bp_tmp_value=$((__b3bp_tmp_default + 1))
fi
printf -v "${__b3bp_tmp_varname}" '%s' "${__b3bp_tmp_value}"
debug "cli arg ${__b3bp_tmp_varname} = (${__b3bp_tmp_default}) -> ${!__b3bp_tmp_varname}"
fi
done
set -o nounset # no more unbound variable references expected
shift $((OPTIND-1))
if [[ "${1:-}" = "--" ]] ; then
shift
fi
fi
### Automatic validation of required option arguments
##############################################################################
for __b3bp_tmp_varname in ${!__b3bp_tmp_has_arg_*}; do
# validate only options which required an argument
[[ "${!__b3bp_tmp_varname}" = "2" ]] || continue
__b3bp_tmp_opt_short="${__b3bp_tmp_varname##*_}"
__b3bp_tmp_varname="arg_${__b3bp_tmp_opt_short}"
[[ "${!__b3bp_tmp_varname}" ]] && continue
__b3bp_tmp_varname="__b3bp_tmp_opt_short2long_${__b3bp_tmp_opt_short}"
printf -v "__b3bp_tmp_opt_long" '%s' "${!__b3bp_tmp_varname}"
[[ "${__b3bp_tmp_opt_long:-}" ]] && __b3bp_tmp_opt_long=" (--${__b3bp_tmp_opt_long//_/-})"
help "Option -${__b3bp_tmp_opt_short}${__b3bp_tmp_opt_long:-} requires an argument"
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
### Cleanup Environment variables
##############################################################################
for __tmp_varname in ${!__b3bp_tmp_*}; do
unset -v "${__tmp_varname}"
done
unset -v __tmp_varname
### Switches (like -d for debugmode, -h for showing helppage)
#####################################################################
### Externally supplied __usage. Nothing else to do here
##############################################################################
if [[ "${__b3bp_external_usage:-}" = "true" ]]; then
unset -v __b3bp_external_usage
return
fi
### 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 "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)
##############################################################################
# debug mode
if [ "${arg_d}" = "1" ]; then
if [[ "${arg_d:?}" = "1" ]]; then
set -o xtrace
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
LOG_LEVEL="7"
# Enable error backtracing
trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
fi
# verbose mode
if [ "${arg_v}" = "1" ]; then
if [[ "${arg_v:?}" = "1" ]]; then
set -o verbose
fi
# no color mode
if [[ "${arg_n:?}" = "1" ]]; then
NO_COLOR="true"
fi
# help mode
if [ "${arg_h}" = "1" ]; then
if [[ "${arg_h:?}" = "1" ]]; then
# Help exists with code 1
help "Help using ${0}"
fi
### Validation (decide what's required for running your script and error out)
#####################################################################
### Validation. Error out if the things required for your script are not present
##############################################################################
[ -z "${arg_f:-}" ] && help "Setting a filename with -f or --file is required"
[ -z "${LOG_LEVEL:-}" ] && emergency "Cannot continue without LOG_LEVEL. "
[[ "${arg_f:-}" ]] || help "Setting a filename with -f or --file is required"
[[ "${LOG_LEVEL:-}" ]] || emergency "Cannot continue without LOG_LEVEL. "
### Runtime
#####################################################################
##############################################################################
info "__i_am_main_script: ${__i_am_main_script}"
info "__file: ${__file}"
info "__dir: ${__dir}"
info "__base: ${__base}"
info "__os: ${__os}"
info "OSTYPE: ${OSTYPE}"
info "arg_f: ${arg_f}"
info "arg_d: ${arg_d}"
info "arg_v: ${arg_v}"
info "arg_h: ${arg_h}"
# 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
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/'")"
# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software
debug "Info useful to developers for debugging the application, not useful during operations."
info "Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required."
notice "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."
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"
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."
error "Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time."
critical "Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection."
alert "Should be corrected immediately, therefore notify staff who can fix the problem. An example would be the loss of a primary ISP connection."

View File

@ -1,19 +1,29 @@
{
"name": "bash3boilerplate",
"description": "Copypastable templates to write better bash scripts",
"version": "1.2.0",
"scripts": {
"release:major": "env SEMANTIC=major npm run release",
"release:minor": "env SEMANTIC=minor npm run release",
"release:patch": "env SEMANTIC=patch npm run release",
"test": "test/acceptance.sh",
"save:fixtures": "cross-env SAVE_FIXTURES=true npm run test",
"release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && git push --tags && npm publish"
"version": "2.7.2",
"packageManager": "yarn@3.6.0+sha224.19e47520fa56c6146388fdeb438d9dcf6630c3f277a2e1180995c3bb",
"engines": {
"node": ">= 18",
"yarn": "3.6.0"
},
"dependencies": {
"fakefile": "0.0.6"
"scripts": {
"lint:shellcheck": "shellcheck --severity=${SHELLCHECK_SEVERITY:-info} $(find . -name '*.sh' -maxdepth 2)",
"lint:style": "test/style.pl $(find . -name '*.sh' -maxdepth 2)",
"lint": "npm-run-all -l 'lint:**'",
"release:major": "env SEMANTIC=major yarn release",
"release:minor": "env SEMANTIC=minor yarn release",
"release:patch": "env SEMANTIC=patch yarn release",
"release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && yarn version:replace && git commit main.sh src/*.sh -m 'Update version' && git push && git push --tags -f && npm publish",
"test:debug:main:repeated": "env LOG_LEVEL=7 test/acceptance.sh main-repeated",
"test:update": "env SAVE_FIXTURES=true yarn test",
"test": "test/acceptance.sh",
"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"
},
"devDependencies": {
"cross-env": "1.0.7"
"fakefile": "1.1.0",
"npm-run-all": "4.1.5",
"replace": "1.2.2"
}
}

View File

@ -1,131 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2014, Transloadit Ltd.
#
# This file:
#
# - Bumps a semantic version as specified in first argument
# - Or: Bumps a semantic version in a file as specified in first argument
# - Returns the version if no levelName is provided in second argument
# - Only supports Go files ending in 'var Version = ...'
#
# Run as:
#
# ./bump.sh 0.0.1 patch
# ./bump.sh ./VERSION patch
# ./bump.sh ./VERSION patch
# ./bump.sh ./VERSION major 1
# ./bump.sh ./version.go patch 2
#
# Returns:
#
# v0.0.1
#
# Requires:
#
# - gsed on OSX (brew install gnu-sed)
#
# Authors:
#
# - Kevin van Zonneveld <kevin@transloadit.com>
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__root="$(cd "$(dirname "${__dir}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
gsed=""
[ -n "$(which sed)" ] && gsed="$(which sed)"
[ -n "$(which gsed)" ] && gsed="$(which gsed)"
. ${__dir}/semver.sh
function readFromFile() {
local filepath="${1}"
local extension="${filepath##*.}"
if [ "${extension}" = "go" ]; then
curVersion="$(awk -F'"' '/^var Version = / {print $2}' "${filepath}" | tail -n1)" || true
else
curVersion="$(echo $(cat "${filepath}"))" || true
fi
if [ -z "${curVersion}" ]; then
curVersion="v0.0.0"
fi
echo "${curVersion}"
}
function writeToFile() {
local filepath="${1}"
local newVersion="${2}"
local extension="${filepath##*.}"
if [ "${extension}" = "go" ]; then
buf="$(cat "${filepath}" |egrep -v '^var Version = ')" || true
echo -e "${buf}\nvar Version = \"${newVersion}\"" > "${filepath}"
else
echo "${newVersion}" > "${filepath}"
fi
}
function bump() {
local version="${1}"
local levelName="${2}"
local bump="${3}"
local major=0
local minor=0
local patch=0
local special=""
local newVersion=""
semverParseInto "${version}" major minor patch special
if [ "${levelName}" = "major" ]; then
let "major = major + ${bump}"
minor=0
patch=0
special=""
fi
if [ "${levelName}" = "minor" ]; then
let "minor = minor + ${bump}"
patch=0
special=""
fi
if [ "${levelName}" = "patch" ]; then
let "patch = patch + ${bump}"
special=""
fi
if [ "${levelName}" = "special" ]; then
special="${bump}"
fi
newVersion="v${major}.${minor}.${patch}"
if [ -n "${special}" ]; then
newVersion=".${newVersion}"
fi
echo "${newVersion}"
}
if [ -f "${1}" ]; then
filepath="${1}"
curVersion="$(readFromFile "${filepath}")"
else
curVersion="${1}"
fi
newVersion=$(bump "${curVersion}" "${2:-}" "${3:-1}")
echo "${newVersion}"
if [ -n "${filepath:-}" ]; then
writeToFile "${filepath}" "${newVersion}"
fi

View File

@ -1,38 +1,113 @@
#!/usr/bin/env bash
# BASH3 Boilerplate: ini_val
#
# This file:
#
# - Can read and write .ini files using pure bash
#
# Limitations:
#
# - All keys inside a section of the .ini file must be unique
# - Optional comment parameter for the creation of new entries
#
# Usage as a function:
#
# source ini_val.sh
# ini_val data.ini connection.host 127.0.0.1 "Host name or IP address"
#
# Usage as a command:
#
# ini_val.sh data.ini connection.host 127.0.0.1 "Host name or IP address"
#
# Based on a template by BASH3 Boilerplate vv2.7.2
# http://bash3boilerplate.sh/#authors
#
# The MIT License (MIT)
# Copyright (c) 2013 Kevin van Zonneveld and contributors
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
# as you leave these references intact in the header comments of your source files.
function ini_val() {
local file="${1}"
local sectionkey="${2}"
local val="${3}"
local delim=" = "
local file="${1:-}"
local sectionkey="${2:-}"
local val="${3:-}"
local comment="${4:-}"
local delim="="
local comment_delim=";"
local section=""
local key=""
local current=""
# add default section
local section_default="default"
# Split on . for section. However, section is optional
read section key <<<$(IFS="."; echo ${sectionkey})
if [ -z "${key}" ]; then
key="${section}"
section=""
if [[ ! -f "${file}" ]]; then
# touch file if not exists
touch "${file}"
fi
local current=$(awk -F"${delim}" "/^${key}${delim}/ {for (i=2; i<NF; i++) printf \$i \" \"; print \$NF}" "${file}")
if [ -z "${val}" ]; then
# Split on . for section. However, section is optional
IFS='.' read -r section key <<< "${sectionkey}"
if [[ ! "${key}" ]]; then
key="${section}"
# default section if not given
section="${section_default}"
fi
# get current value (if exists)
current=$(sed -En "/^\[/{h;d;};G;s/^${key}([[:blank:]]*)${delim}(.*)\n\[${section}\]$/\2/p" "${file}"|awk '{$1=$1};1')
# get current comment (if exists)
current_comment=$(sed -En "/^\[${section}\]/,/^\[.*\]/ s|^(${comment_delim}\[${key}\])(.*)|\2|p" "${file}"|awk '{$1=$1};1')
if ! grep -q "\[${section}\]" "${file}"; then
# create section if not exists (empty line to seperate new section for better readability)
echo >> "${file}"
echo "[${section}]" >> "${file}"
fi
if [[ ! "${val}" ]]; then
# get a value
echo "${current}"
else
# set a value
if [ -z "${current}" ]; then
# doesn't exist yet, add
if [ -z "${section}" ]; then
# no section was given, add to bottom of file
echo "${key}${delim}${val}" >> "${file}"
else
# add to section
sed "/\[${section}\]/a ${key}${delim}${val}" -i "${file}"
fi
else
# replace existing
sed "/^${key}${delim}/s/${delim}.*/${delim}${val}/" -i "${file}"
if [[ ! "${section}" ]]; then
# if no section is given, propagate the default section
section=${section_default}
fi
if [[ ! "${comment}" ]]; then
# if no comment given, keep old comment
comment="${current_comment}"
fi
# maintenance area
# a) remove comment if new given / respect section
sed -i.bak "/^\[${section}\]/,/^\[.*\]/ s|^\(${comment_delim}\[${key}\] \).*$||" "${file}"
# b) remove old key / respect section
sed -i.bak "/^\[${section}\]/,/^\[.*\]/ s|^\(${key}=\).*$||" "${file}"
# c) remove all empty lines in ini file
sed -i.bak '/^[[:space:]]*$/d' "${file}"
# d) insert line break before every section for better readability
sed -i.bak $'s/^\\[/\\\n\\[/g' "${file}"
# add to section
if [[ ! "${comment}" ]]; then
# add new key/value _without_ comment
RET="/\\[${section}\\]/a\\
${key}${delim}${val}"
else
# add new key/value _with_ preceeding comment
RET="/\\[${section}\\]/a\\
${comment_delim}[${key}] ${comment}\\
${key}${delim}${val}"
fi
sed -i.bak -e "${RET}" "${file}"
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
rm -f "${file}.bak"
fi
}
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
export -f ini_val
else
ini_val "${@}"
exit ${?}
fi

View File

@ -1,10 +1,49 @@
__dir=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
#!/usr/bin/env bash
# BASH3 Boilerplate: megamount
#
# This file:
#
# - Takes a URL (smb, nfs, afs) and tries to mount it at a given target directory
# - Forcefully unmounts any active mount at the target directory first
# - Displays the mount's contents for verification
#
# Depends on:
#
# - ./parse_url.sh
#
# Usage as a function:
#
# source megamount.sh
# megamount smb://janedoe:abc123@192.168.0.1/documents /mnt/documents
#
# Usage as a command:
#
# megamount.sh smb://janedoe:abc123@192.168.0.1/documents /mnt/documents
#
# Based on a template by BASH3 Boilerplate vv2.7.2
# http://bash3boilerplate.sh/#authors
#
# The MIT License (MIT)
# Copyright (c) 2013 Kevin van Zonneveld and contributors
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
# as you leave these references intact in the header comments of your source files.
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=src/parse_url.sh
source "${__dir}/parse_url.sh"
function megamount () {
local url="${1}"
local target="${2}"
local proto
local user
local pass
local host
local port
local path
proto=$(parse_url "${url}" "proto")
user=$(parse_url "${url}" "user")
pass=$(parse_url "${url}" "pass")
@ -12,21 +51,28 @@ function megamount () {
port=$(parse_url "${url}" "port")
path=$(parse_url "${url}" "path")
umount -lf "${target}" || true
(umount -lf "${target}" || umount -f "${target}") > /dev/null 2>&1 || true
mkdir -p "${target}"
if [ "${proto}" = "smb://" ]; then
if [[ "${proto}" = "smb://" ]]; then
mount -t cifs --verbose -o "username=${user},password=${pass},hard" "//${host}/${path}" "${target}"
elif [ "${proto}" = "afp://" ]; then
elif [[ "${proto}" = "afp://" ]]; then
# start syslog-ng
# afpfsd || echo "Unable to run afpfsd. Does /dev/log exist?" && exit 1
mount_afp "${url}" "${target}"
elif [ "${proto}" = "nfs://" ]; then
mount -t nfs --verbose -o "vers=3,nolock,soft,intr,rsize=32768,wsize=32768" ${host}:/${path} ${target}
elif [[ "${proto}" = "nfs://" ]]; then
mount -t nfs --verbose -o "vers=3,nolock,soft,intr,rsize=32768,wsize=32768" "${host}:/${path}" "${target}"
else
echo "ERR: Unknown protocol ${proto}"
echo "ERR: Unknown protocol: '${proto}'"
exit 1
fi
# chmod 777 "${target}"
ls -al "${target}/"
}
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
export -f megamount
else
megamount "${@}"
exit ${?}
fi

View File

@ -1,30 +1,66 @@
#!/usr/bin/env bash
# BASH3 Boilerplate: parse_url
#
# This file:
#
# - Takes a URL and parses protocol, user, pass, host, port, path.
#
# Based on:
#
# - http://stackoverflow.com/a/6174447/151666
#
# Usage as a function:
#
# source parse_url.sh
# parse_url 'http://johndoe:abc123@example.com:8080/index.html' pass
#
# Usage as a command:
#
# parse_url.sh 'http://johndoe:abc123@example.com:8080/index.html'
#
# Based on a template by BASH3 Boilerplate vv2.7.2
# http://bash3boilerplate.sh/#authors
#
# The MIT License (MIT)
# Copyright (c) 2013 Kevin van Zonneveld and contributors
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
# as you leave these references intact in the header comments of your source files.
function parse_url() {
# Based on http://stackoverflow.com/a/6174447/151666
local parse="${1}"
local need="${2}"
local need="${2:-}"
local proto="$(echo $parse | grep :// | sed -e's,^\(.*://\).*,\1,g')"
local url="$(echo ${parse/$proto/})"
local userpass="$(echo $url | grep @ | cut -d@ -f1)"
local user="$(echo $userpass | grep : | cut -d: -f1)"
local pass="$(echo $userpass | grep : | cut -d: -f2)"
local hostport="$(echo ${url/$userpass@/} | cut -d/ -f1)"
local host="$(echo $hostport | grep : | cut -d: -f1)"
local port="$(echo $hostport | grep : | cut -d: -f2)"
local path="$(echo $url | grep / | cut -d/ -f2-)"
local proto
local url
local userpass
local user
local pass
local hostport
local host
local port
local path
[ -z "${user}" ] && user="${userpass}"
[ -z "${host}" ] && host="${hostport}"
if [ -z "${port}" ]; then
[ "${proto}" = "http://" ] && port="80"
[ "${proto}" = "https://" ] && port="443"
[ "${proto}" = "mysql://" ] && port="3306"
[ "${proto}" = "redis://" ] && port="6379"
proto="$(echo "${parse}" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
url="${parse/${proto}/}"
userpass="$(echo "${url}" | grep @ | cut -d@ -f1)"
user="$(echo "${userpass}" | grep : | cut -d: -f1)"
pass="$(echo "${userpass}" | grep : | cut -d: -f2)"
hostport="$(echo "${url/${userpass}@/}" | cut -d/ -f1)"
host="$(echo "${hostport}" | grep : | cut -d: -f1)"
port="$(echo "${hostport}" | grep : | cut -d: -f2)"
path="$(echo "${url}" | grep / | cut -d/ -f2-)"
[[ ! "${user}" ]] && user="${userpass}"
[[ ! "${host}" ]] && host="${hostport}"
if [[ ! "${port}" ]]; then
[[ "${proto}" = "http://" ]] && port="80"
[[ "${proto}" = "https://" ]] && port="443"
[[ "${proto}" = "mysql://" ]] && port="3306"
[[ "${proto}" = "redis://" ]] && port="6379"
fi
if [ -n "${need}" ]; then
echo ${!need}
if [[ "${need}" ]]; then
echo "${!need}"
else
echo ""
echo " Use second argument to return just 1 variable."
@ -39,3 +75,10 @@ function parse_url() {
echo ""
fi
}
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
export -f parse_url
else
parse_url "${@}"
exit ${?}
fi

View File

@ -1,132 +0,0 @@
#!/usr/bin/env sh
# From: https://github.com/cloudflare/semver_bash
# https://raw.githubusercontent.com/cloudflare/semver_bash/master/semver.sh
function semverParseInto() {
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
#MAJOR
eval $2=`echo $1 | sed -e "s#$RE#\1#"`
#MINOR
eval $3=`echo $1 | sed -e "s#$RE#\2#"`
#MINOR
eval $4=`echo $1 | sed -e "s#$RE#\3#"`
#SPECIAL
eval $5=`echo $1 | sed -e "s#$RE#\4#"`
}
function semverEQ() {
local MAJOR_A=0
local MINOR_A=0
local PATCH_A=0
local SPECIAL_A=0
local MAJOR_B=0
local MINOR_B=0
local PATCH_B=0
local SPECIAL_B=0
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
if [ $MAJOR_A -ne $MAJOR_B ]; then
return 1
fi
if [ $MINOR_A -ne $MINOR_B ]; then
return 1
fi
if [ $PATCH_A -ne $PATCH_B ]; then
return 1
fi
if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then
return 1
fi
return 0
}
function semverLT() {
local MAJOR_A=0
local MINOR_A=0
local PATCH_A=0
local SPECIAL_A=0
local MAJOR_B=0
local MINOR_B=0
local PATCH_B=0
local SPECIAL_B=0
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
if [ $MAJOR_A -lt $MAJOR_B ]; then
return 0
fi
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then
return 0
fi
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then
return 0
fi
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then
return 1
fi
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]] ; then
return 1
fi
if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then
return 0
fi
if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then
return 0
fi
return 1
}
function semverGT() {
semverEQ $1 $2
local EQ=$?
semverLT $1 $2
local LT=$?
if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then
return 0
else
return 1
fi
}
if [ "___semver.sh" == "___`basename $0`" ]; then
MAJOR=0
MINOR=0
PATCH=0
SPECIAL=""
semverParseInto $1 MAJOR MINOR PATCH SPECIAL
echo "$1 -> M: $MAJOR m:$MINOR p:$PATCH s:$SPECIAL"
semverParseInto $2 MAJOR MINOR PATCH SPECIAL
echo "$2 -> M: $MAJOR m:$MINOR p:$PATCH s:$SPECIAL"
semverEQ $1 $2
echo "$1 == $2 -> $?."
semverLT $1 $2
echo "$1 < $2 -> $?."
semverGT $1 $2
echo "$1 > $2 -> $?."
fi

View File

@ -1,48 +1,68 @@
#!/usr/bin/env bash
# Copyright (c) 2014, Transloadit Ltd.
# BASH3 Boilerplate: templater
#
# This file:
# - takes a source (template) & destination (config) filepath argument
# - and then replaces placeholders with variables found in the environment
#
# Run as:
# - takes a source (template) & destination (config) filepath argument
# - then replaces placeholders with variables found in the environment
#
# Usage as a function:
#
# source templater.sh
# export NAME=kevin
# templater input.cfg output.cfg
#
# Usage as a command:
#
# ALLOW_REMAINDERS=1 templater.sh input.cfg output.cfg
#
# Authors:
# - Kevin van Zonneveld <kevin@transloadit.com>
# Based on a template by BASH3 Boilerplate vv2.7.2
# http://bash3boilerplate.sh/#authors
#
# The MIT License (MIT)
# Copyright (c) 2013 Kevin van Zonneveld and contributors
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
# as you leave these references intact in the header comments of your source files.
set -o pipefail
set -o errexit
# set -o xtrace
# set -o nounset
function templater() {
ALLOW_REMAINDERS="${ALLOW_REMAINDERS:-0}"
sed=""
[ -n "$(which sed)" ] && sed="$(which sed)"
[ -n "$(which gsed)" ] && sed="$(which gsed)"
templateSrc="${1:-}"
templateDst="${2:-}"
ALLOW_REMAINDERS="${ALLOW_REMAINDERS:-0}"
if [[ ! -f "${templateSrc}" ]]; then
echo "ERROR: Template source '${templateSrc}' needs to exist"
exit 1
fi
if [[ ! "${templateDst}" ]]; then
echo "ERROR: Template destination '${templateDst}' needs to be specified"
exit 1
fi
templateSrc="${1}"
templateDst="${2}"
if [[ "$(command -v perl)" ]]; then
perl -p -e 's/\$\{(\w+)\}/(exists $ENV{$1} ? $ENV{$1} : "\${$1}")/eg' < "${templateSrc}" > "${templateDst}"
else
cp -f "${templateSrc}" "${templateDst}"
if [ ! -f "${templateSrc}" ]; then
echo "ERROR: Template source '${templateSrc}' needs to exist"
exit 1
fi
if [ ! -n "${templateDst}" ]; then
echo "ERROR: Template destination '${templateDst}' needs to exist"
exit 1
fi
cp -f "${templateSrc}" "${templateDst}"
for var in $(env |awk -F= '{print $1}' |egrep '^[A-Z0-9_]+$'); do
${sed} "s#\${${var}}#${!var}#g" -i "${templateDst}"
done
# cat "${templateDst}"
if grep '${' ${templateDst} && [ "${ALLOW_REMAINDERS}" == "0" ]; then
echo "ERROR: Unable to replace the above template vars"
exit 1
for var in $(env |awk -F= '{print $1}' |grep -E '^(_[A-Z0-9_]+|[A-Z0-9][A-Z0-9_]*)$'); do
sed -i.bak -e "s#\${${var}}#${!var//#/\\#/}#g" "${templateDst}"
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
rm -f "${templateDst}.bak"
done
fi
# cat "${templateDst}"
# shellcheck disable=SC2016
if grep '${' "${templateDst}" && [[ "${ALLOW_REMAINDERS}" = "0" ]]; then
echo "ERROR: Unable to replace the above template vars"
exit 1
fi
}
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
export -f templater
else
templater "${@}"
exit ${?}
fi

View File

@ -1,65 +1,94 @@
#!/usr/bin/env bash
# This file:
#
# - Executes one (or all) test scenarios
# - Replaces dynamic things like hostnames, IPs, dates, etc
# - Optionally saves the results as fixtures, that later runs will be compared against
#
# Usage:
#
# ./deploy.sh
#
# Based on a template by BASH3 Boilerplate v2.0.0
# http://bash3boilerplate.sh/#authors
#
# The MIT License (MIT)
# Copyright (c) 2013 Kevin van Zonneveld and contributors
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
# as you leave these references intact in the header comments of your source files.
set -o pipefail
# 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)"
__base="$(basename "${__file}" .sh)"
__root="$(cd "$(dirname "${__dir}")" && pwd)"
scenarios="${1:-$(ls ${__dir}/scenario/|egrep -v ^prepare$)}"
__sysTmpDir="${TMPDIR:-/tmp}"
__sysTmpDir="${__sysTmpDir%/}" # <-- remove trailing slash on macosx
__b3bpTmpDir="${__sysTmpDir}/b3bp"
mkdir -p "${__b3bpTmpDir}"
__accptstTmpDir=$(mktemp -d "${__sysTmpDir}/${__base}.XXXXXX")
if [[ "${OSTYPE}" == "darwin"* ]]; then
cmdSed=gsed
else
cmdSed=sed
function cleanup_before_exit () { rm -r "${__accptstTmpDir:?}"; }
trap cleanup_before_exit EXIT
cmdSed="sed"
cmdTimeout="timeout"
if [[ "${OSTYPE}" = "darwin"* ]]; then
cmdSed="gsed"
cmdTimeout="gtimeout"
fi
if [[ "${OSTYPE}" == "darwin"* ]]; then
cmdTimeout="gtimeout --kill-after=6m 5m"
else
cmdTimeout="timeout --kill-after=6m 5m"
fi
__node="$(which node)"
__os="linux"
if [[ "${OSTYPE}" == "darwin"* ]]; then
__os="darwin"
fi
__arch="amd64"
if ! which "${cmdSed}" > /dev/null; then
if [[ ! "$(command -v ${cmdSed})" ]]; then
echo "Please install ${cmdSed}"
exit 1
fi
if [[ ! "$(command -v ${cmdTimeout})" ]]; then
echo "Please install ${cmdTimeout}"
exit 1
fi
__node="$(command -v node)"
__arch="amd64"
# explicitly setting NO_COLOR to false will make b3bp ignore TERM
# not being "xterm*" or "screen*" and STDERR not being connected to a terminal
# it's the opposite of NO_COLOR="true" - it forces color, no matter what
export NO_COLOR="false"
# Running prepare before other scenarios is important on Travis,
# so that stdio can diverge - and we can enforce stricter
# stdio comparison on all other tests.
for scenario in $(echo ${scenarios}); do
while IFS=$'\n' read -r scenario; do
scenario="$(dirname "${scenario}")"
scenario="${scenario##${__dir}/scenario/}"
[[ "${scenario}" = "prepare" ]] && continue
[[ "${1:-}" ]] && [[ "${scenario}" != "${1}" ]] && continue
echo "==> Scenario: ${scenario}"
pushd "${__dir}/scenario/${scenario}" > /dev/null
# Run scenario
(${cmdTimeout} bash ./run.sh \
> "${__b3bpTmpDir}/${scenario}.stdio" 2>&1; \
echo "${?}" > "${__b3bpTmpDir}/${scenario}.exitcode" \
(${cmdTimeout} --kill-after=6m 5m bash ./run.sh \
> "${__accptstTmpDir}/${scenario}.stdio" 2>&1; \
echo "${?}" > "${__accptstTmpDir}/${scenario}.exitcode" \
) || true
# Clear out environmental specifics
for typ in $(echo stdio exitcode); do
curFile="${__b3bpTmpDir}/${scenario}.${typ}"
for typ in stdio exitcode; do
curFile="${__accptstTmpDir}/${scenario}.${typ}"
"${cmdSed}" -i \
-e "s@${__node}@{node}@g" "${curFile}" \
-e "s@${__root}@{root}@g" "${curFile}" \
@ -69,16 +98,16 @@ for scenario in $(echo ${scenarios}); 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@${__os}@{os}@g" "${curFile}" \
-e "s@${__arch}@{arch}@g" "${curFile}" \
-e "s@${OSTYPE}@{OSTYPE}@g" "${curFile}" \
-e "s@OSX@{os}@g" "${curFile}" \
-e "s@Linux@{os}@g" "${curFile}" \
|| false
if [ "$(cat "${curFile}" |grep 'B3BP:STDIO_REPLACE_IPS' |wc -l)" -gt 0 ]; then
if grep -q 'ACCPTST:STDIO_REPLACE_IPS' "${curFile}"; then
"${cmdSed}" -i \
-r 's@[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}@{ip}@g' \
"${curFile}"
@ -89,45 +118,45 @@ for scenario in $(echo ${scenarios}); do
-r 's@\{ip\}\s+@{ip} @g' \
"${curFile}"
fi
if [ "$(cat "${curFile}" |grep 'B3BP:STDIO_REPLACE_UUIDS' |wc -l)" -gt 0 ]; then
if grep -q 'ACCPTST:STDIO_REPLACE_UUIDS' "${curFile}"; then
"${cmdSed}" -i \
-r 's@[0-9a-f\-]{32,40}@{uuid}@g' \
"${curFile}"
fi
if [ "$(cat "${curFile}" |grep 'B3BP:STDIO_REPLACE_BIGINTS' |wc -l)" -gt 0 ]; then
if grep -q 'ACCPTST:STDIO_REPLACE_BIGINTS' "${curFile}"; then
# Such as: 3811298194
"${cmdSed}" -i \
-r 's@[0-9]{7,64}@{bigint}@g' \
"${curFile}"
fi
if [ "$(cat "${curFile}" |grep 'B3BP:STDIO_REPLACE_DATETIMES' |wc -l)" -gt 0 ]; then
if grep -q 'ACCPTST:STDIO_REPLACE_DATETIMES' "${curFile}"; then
# Such as: 2016-02-10 15:38:44.420094
"${cmdSed}" -i \
-r 's@[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}@{datetime}@g' \
"${curFile}"
fi
if [ "$(cat "${curFile}" |grep 'B3BP:STDIO_REPLACE_LONGTIMES' |wc -l)" -gt 0 ]; then
if grep -q 'ACCPTST:STDIO_REPLACE_LONGTIMES' "${curFile}"; then
# Such as: 2016-02-10 15:38:44.420094
"${cmdSed}" -i \
-r 's@[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6}@{longtime}@g' \
"${curFile}"
fi
if [ "$(cat "${curFile}" |grep 'B3BP:STDIO_REPLACE_DURATIONS' |wc -l)" -gt 0 ]; then
if grep -q 'ACCPTST:STDIO_REPLACE_DURATIONS' "${curFile}"; then
# Such as: 0:00:00.001991
"${cmdSed}" -i \
-r 's@[0-9]{1,2}:[0-9]{2}:[0-9]{2}.[0-9]{6}@{duration}@g' \
"${curFile}"
fi
if [ "$(cat "${curFile}" |grep 'B3BP:STDIO_REPLACE_REMOTE_EXEC' |wc -l)" -gt 0 ]; then
egrep -v 'remote-exec\): [ a-zA-Z]' "${curFile}" > "${__sysTmpDir}/b3bp-filtered.txt"
mv "${__sysTmpDir}/b3bp-filtered.txt" "${curFile}"
if grep -q 'ACCPTST:STDIO_REPLACE_REMOTE_EXEC' "${curFile}"; then
grep -Ev 'remote-exec\): [ a-zA-Z]' "${curFile}" > "${__sysTmpDir}/accptst-filtered.txt"
mv "${__sysTmpDir}/accptst-filtered.txt" "${curFile}"
fi
done
# Save these as new fixtures?
if [ "${SAVE_FIXTURES:-}" = "true" ]; then
for typ in $(echo stdio exitcode); do
curFile="${__b3bpTmpDir}/${scenario}.${typ}"
if [[ "${SAVE_FIXTURES:-}" = "true" ]]; then
for typ in stdio exitcode; do
curFile="${__accptstTmpDir}/${scenario}.${typ}"
cp -f \
"${curFile}" \
"${__dir}/fixture/${scenario}.${typ}"
@ -135,32 +164,69 @@ for scenario in $(echo ${scenarios}); do
fi
# Compare
for typ in $(echo stdio exitcode); do
curFile="${__b3bpTmpDir}/${scenario}.${typ}"
for typ in stdio exitcode; do
curFile="${__accptstTmpDir}/${scenario}.${typ}"
echo -n " comparing ${typ}.. "
if [ "${typ}" = "stdio" ]; then
if [ "$(cat "${curFile}" |grep 'B3BP:STDIO_SKIP_COMPARE' |wc -l)" -gt 0 ]; then
if [[ "${typ}" = "stdio" ]]; then
if grep -q 'ACCPTST:STDIO_SKIP_COMPARE' "${curFile}"; then
echo "skip"
continue
fi
fi
diff \
--strip-trailing-cr \
"${__dir}/fixture/${scenario}.${typ}" \
"${curFile}" || ( \
echo -e "\n\n==> MISMATCH OF: ${typ}";
echo -e "\n\n==> EXPECTED STDIO: ";
cat "${__dir}/fixture/${scenario}.stdio";
echo -e "\n\n==> ACTUAL STDIO: ";
cat "${__b3bpTmpDir}/${scenario}.stdio";
exit 1; \
)
if ! diff --strip-trailing-cr "${__dir}/fixture/${scenario}.${typ}" "${curFile}"; then
echo -e "\\n\\n==> MISMATCH OF: ${scenario}.${typ} ---^"
echo -e "\\n\\n==> EXPECTED STDIO: "
cat "${__dir}/fixture/${scenario}.stdio" || true
echo -e "\\n\\n==> ACTUAL STDIO: "
cat "${__accptstTmpDir}/${scenario}.stdio" || true
exit 1
fi
echo "✓"
done
popd > /dev/null
done
done <<< "$(find "${__dir}/scenario" -type f -iname 'run.sh')"
[[ "${1:-}" ]] && exit 0
# Ensure correct syntax with all available bashes
# 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
failed="false"
while IFS=$'\n' read -r file; do
[[ "${file}" =~ ^\./node_modules/ ]] && 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 <<< "$(which -a bash 2>/dev/null)"
exit 0

View File

@ -0,0 +1,25 @@
ACCPTST:STDIO_REPLACE_DATETIMES
{datetime} UTC [ debug] cli arg arg_f = () -> {tmpdir}/x
{datetime} UTC [ info] __i_am_main_script: 0
{datetime} UTC [ info] __file: {root}/example.sh
{datetime} UTC [ info] __dir: {root}
{datetime} UTC [ info] __base: example
{datetime} UTC [ info] OSTYPE: {OSTYPE}
{datetime} UTC [ info] arg_f: {tmpdir}/x
{datetime} UTC [ info] arg_d: 0
{datetime} UTC [ info] arg_v: 0
{datetime} UTC [ info] arg_h: 0
{datetime} UTC [ info] arg_i: 0
{datetime} UTC [ info] arg_x: 0
{datetime} UTC [ info] multiple lines example - line #1
{datetime} UTC [ info] multiple lines example - line #2
{datetime} UTC [ info] imagine logging the output of 'ls -al /path/'
{datetime} UTC [ debug] Info useful to developers for debugging the application, not useful during operations.
{datetime} UTC [ info] Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required.
{datetime} UTC [ notice] 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 [ 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.
{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 [ info] Cleaning up. Done

View File

@ -1,11 +0,0 @@
B3BP:STDIO_REPLACE_DATETIMES
Help using {root}/main.sh
-f --file [arg] Filename to process. Required.
-t --temp [arg] Location of tempfile. Default="{tmpdir}/bar"
-v Enable verbose mode, print script as it is executed
-d --debug Enables debug mode
-h --help This page
{datetime} UTC [ info] Cleaning up. Done

View File

@ -0,0 +1,42 @@
--> command: Read 3 values
exists
127.0.0.1
nginx, nodejs
--> command: Replace three values in-place and show result
[default]
orphan=no more
[connection]
host=192.168.0.1
[software]
packages=vim
[comment]
;[command] got this new comment
command=works like a chame
;[new_command] last addition will be moved downwards again after next command
new_command=commented too
--> function: Read 3 values
exists
127.0.0.1
nginx, nodejs
--> function: Replace three values in-place and show result
[default]
orphan=no more
[connection]
host=192.168.0.1
[software]
packages=vim
[comment]
;[command] got this new comment
command=works like a chame
;[new_command] last addition will be moved downwards again after next command
new_command=commented too

View File

@ -1,19 +1,25 @@
B3BP:STDIO_REPLACE_DATETIMES
ACCPTST:STDIO_REPLACE_DATETIMES
{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] __dir: {root}
{datetime} UTC [ info] __base: main
{datetime} UTC [ info] __os: {os}
{datetime} UTC [ info] OSTYPE: {OSTYPE}
{datetime} UTC [ info] arg_f: {tmpdir}/x
{datetime} UTC [ info] arg_d: 0
{datetime} UTC [ info] arg_v: 0
{datetime} UTC [ info] arg_h: 0
{datetime} UTC [ info] arg_i: 0
{datetime} UTC [ info] arg_x: 0
{datetime} UTC [ info] multiple lines example - line #1
{datetime} UTC [ info] multiple lines example - line #2
{datetime} UTC [ info] imagine logging the output of 'ls -al /path/'
{datetime} UTC [ debug] Info useful to developers for debugging the application, not useful during operations.
{datetime} UTC [ info] Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required.
{datetime} UTC [ notice] 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 [ 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 [ 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.
{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

@ -0,0 +1,19 @@
ACCPTST:STDIO_REPLACE_DATETIMES
Help using {root}/main.sh
-f --file [arg] Filename to process. Required.
-t --temp [arg] Location of tempfile. Default="{tmpdir}/bar"
-v Enable verbose mode, print script as it is executed
-d --debug Enables debug mode
-h --help This page
-n --no-color Disable color output
-1 --one Do just one thing
-i --input [arg] File to process. Can be repeated.
-x Specify a flag. Can be repeated.
This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not
parsed and will be added as-is to the help.
{datetime} UTC [ info] Cleaning up. Done

View File

@ -0,0 +1 @@
0

View File

@ -1,4 +1,4 @@
B3BP:STDIO_REPLACE_DATETIMES
ACCPTST:STDIO_REPLACE_DATETIMES
{datetime} UTC [ info] arg_f: {tmpdir}/x
{datetime} UTC [ info] arg_f: {tmpdir}/x
{datetime} UTC [ info] arg_f: {tmpdir}/x

View File

@ -0,0 +1 @@
1

View File

@ -1,17 +1,23 @@
B3BP:STDIO_REPLACE_DATETIMES
ACCPTST:STDIO_REPLACE_DATETIMES
{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] __dir: {root}
{datetime} UTC [ info] __base: main
{datetime} UTC [ info] __os: {os}
{datetime} UTC [ info] OSTYPE: {OSTYPE}
{datetime} UTC [ info] arg_f: {tmpdir}/x
{datetime} UTC [ info] arg_d: 0
{datetime} UTC [ info] arg_v: 0
{datetime} UTC [ info] arg_h: 0
{datetime} UTC [ info] arg_i: 0
{datetime} UTC [ info] arg_x: 0
{datetime} UTC [ info] multiple lines example - line #1
{datetime} UTC [ info] multiple lines example - line #2
{datetime} UTC [ info] imagine logging the output of 'ls -al /path/'
{datetime} UTC [ debug] Info useful to developers for debugging the application, not useful during operations.
{datetime} UTC [ info] Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required.
{datetime} UTC [ notice] 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 [ 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 [ 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.
{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.

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,9 @@
ACCPTST:STDIO_REPLACE_DATETIMES
{datetime} UTC [ info] arg_i:
{datetime} UTC [ info] - simple_input
{datetime} UTC [ info] - input_in_quotes
{datetime} UTC [ info] - input with spaces
{datetime} UTC [ info] - input with "quotes"
{datetime} UTC [ info] - last_input
{datetime} UTC [ info] arg_x: 3
{datetime} UTC [ info] arg_x: 4

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,7 @@
ACCPTST:STDIO_REPLACE_DATETIMES
{datetime} UTC [ info] arg_1: 0
{datetime} UTC [ info] arg_2: 0
{datetime} UTC [ info] arg_3: 'THREE'
{datetime} UTC [ info] arg_4: "FOUR"
{datetime} UTC [ info] arg_5: OOOPS
{datetime} UTC [ info] arg_6:

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,169 @@
ACCPTST:STDIO_REPLACE_DATETIMES
# complain about -3
Option -3 (--three) requires an argument
-0 --zero Do nothing.
-1 --one Do one thing. Required.
More description.
-2 --two Do two things.
More. Required. Description.
-3 --three [arg] Do three things.
Required.
-4 --four {arg} Do four things.
-5 --five {arg} Do five things. Required. Maybe.
-6 --six [arg] Do six things. Not Required.
Required, it is not.
-7 --seven [arg] Required. Or bust.
-8 --eight [arg] Do eight things.
More.Required.Description.
-a [arg] Do A. Required.
Default="do-a"
-b {arg} Do B.Default="do-b"
-c [arg] Required. Default="do-c"
-d {arg} Default="do-d"
This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not
parsed and will be added as-is to the help.
# complain about -4
Option -4 (--four) requires an argument
-0 --zero Do nothing.
-1 --one Do one thing. Required.
More description.
-2 --two Do two things.
More. Required. Description.
-3 --three [arg] Do three things.
Required.
-4 --four {arg} Do four things.
-5 --five {arg} Do five things. Required. Maybe.
-6 --six [arg] Do six things. Not Required.
Required, it is not.
-7 --seven [arg] Required. Or bust.
-8 --eight [arg] Do eight things.
More.Required.Description.
-a [arg] Do A. Required.
Default="do-a"
-b {arg} Do B.Default="do-b"
-c [arg] Required. Default="do-c"
-d {arg} Default="do-d"
This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not
parsed and will be added as-is to the help.
# complain about -5
Option -5 (--five) requires an argument
-0 --zero Do nothing.
-1 --one Do one thing. Required.
More description.
-2 --two Do two things.
More. Required. Description.
-3 --three [arg] Do three things.
Required.
-4 --four {arg} Do four things.
-5 --five {arg} Do five things. Required. Maybe.
-6 --six [arg] Do six things. Not Required.
Required, it is not.
-7 --seven [arg] Required. Or bust.
-8 --eight [arg] Do eight things.
More.Required.Description.
-a [arg] Do A. Required.
Default="do-a"
-b {arg} Do B.Default="do-b"
-c [arg] Required. Default="do-c"
-d {arg} Default="do-d"
This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not
parsed and will be added as-is to the help.
# complain about -8 (because -7 syntax is not supported)
Option -8 (--eight) requires an argument
-0 --zero Do nothing.
-1 --one Do one thing. Required.
More description.
-2 --two Do two things.
More. Required. Description.
-3 --three [arg] Do three things.
Required.
-4 --four {arg} Do four things.
-5 --five {arg} Do five things. Required. Maybe.
-6 --six [arg] Do six things. Not Required.
Required, it is not.
-7 --seven [arg] Required. Or bust.
-8 --eight [arg] Do eight things.
More.Required.Description.
-a [arg] Do A. Required.
Default="do-a"
-b {arg} Do B.Default="do-b"
-c [arg] Required. Default="do-c"
-d {arg} Default="do-d"
This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not
parsed and will be added as-is to the help.
# complain about -d (because -d syntax is not supported)
Option -d requires an argument
-0 --zero Do nothing.
-1 --one Do one thing. Required.
More description.
-2 --two Do two things.
More. Required. Description.
-3 --three [arg] Do three things.
Required.
-4 --four {arg} Do four things.
-5 --five {arg} Do five things. Required. Maybe.
-6 --six [arg] Do six things. Not Required.
Required, it is not.
-7 --seven [arg] Required. Or bust.
-8 --eight [arg] Do eight things.
More.Required.Description.
-a [arg] Do A. Required.
Default="do-a"
-b {arg} Do B.Default="do-b"
-c [arg] Required. Default="do-c"
-d {arg} Default="do-d"
This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not
parsed and will be added as-is to the help.
# complain about nothing
{datetime} UTC [ info] arg_0: 0
{datetime} UTC [ info] arg_1: 0
{datetime} UTC [ info] arg_2: 0
{datetime} UTC [ info] arg_3: arg3
{datetime} UTC [ info] arg_4: arg4
{datetime} UTC [ info] arg_5: arg5
{datetime} UTC [ info] arg_6:
{datetime} UTC [ info] arg_7:
{datetime} UTC [ info] arg_8: arg8
{datetime} UTC [ info] arg_a: do-a
{datetime} UTC [ info] arg_b: do-b
{datetime} UTC [ info] arg_c: do-c
{datetime} UTC [ info] arg_d: argd
# test for issue #108
{datetime} UTC [ info] arg_0: 1
{datetime} UTC [ info] arg_1: 0
{datetime} UTC [ info] arg_2: 0
{datetime} UTC [ info] arg_3: arg3
{datetime} UTC [ info] arg_4: value
{datetime} UTC [ info] arg_5: arg5
{datetime} UTC [ info] arg_6:
{datetime} UTC [ info] arg_7:
{datetime} UTC [ info] arg_8: arg8
{datetime} UTC [ info] arg_a: do-a
{datetime} UTC [ info] arg_b: do-b
{datetime} UTC [ info] arg_c: do-c
{datetime} UTC [ info] arg_d: argd

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
ERR: Unknown protocol: 'foobarfs://'
ERR: Unknown protocol: 'foobarfs://'

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,24 @@
abc123
Use second argument to return just 1 variable.
parse_url() demo:
proto: http://
user: johndoe
pass: abc123
host: example.com
port: 8080
path: index.html
abc123
Use second argument to return just 1 variable.
parse_url() demo:
proto: http://
user: johndoe
pass: abc123
host: example.com
port: 8080
path: index.html

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,14 @@
--
[connection]
host = 127.0.0.1
--
[connection]
host = 127.0.0.1
--
port = ${I_DONT_EXIST}
[connection]
host = 127.0.0.1
port = ${I_DONT_EXIST}
--
port = ${I_DONT_EXIST}
ERROR: Unable to replace the above template vars

View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
echo "B3BP:STDIO_REPLACE_DATETIMES"
env LOG_LEVEL=8 bash "${__root}/main.sh" -f /tmp/x

View 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

View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
echo "B3BP:STDIO_REPLACE_DATETIMES"
bash "${__root}/main.sh" -h

View File

@ -0,0 +1,8 @@
[default]
orphan=exists
[connection]
host=127.0.0.1
[software]
packages=nginx, nodejs

54
test/scenario/ini_val/run.sh Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
# echo "ACCPTST:STDIO_REPLACE_DATETIMES"
# Use as standalone:
cp -f data.ini dummy.ini
echo "--> command: Read 3 values"
bash "${__root}/src/ini_val.sh" ./dummy.ini orphan
bash "${__root}/src/ini_val.sh" ./dummy.ini connection.host
bash "${__root}/src/ini_val.sh" ./dummy.ini software.packages
bash "${__root}/src/ini_val.sh" ./dummy.ini comment.command
echo "--> command: Replace three values in-place and show result"
bash "${__root}/src/ini_val.sh" ./dummy.ini orphan "no more"
bash "${__root}/src/ini_val.sh" ./dummy.ini connection.host "192.168.0.1"
bash "${__root}/src/ini_val.sh" ./dummy.ini software.packages "vim"
bash "${__root}/src/ini_val.sh" ./dummy.ini comment.command "commented" "this key is commented"
bash "${__root}/src/ini_val.sh" ./dummy.ini comment.new_command "commented too" "last addition will be moved downwards again after next command"
bash "${__root}/src/ini_val.sh" ./dummy.ini comment.command "works like a chame" "got this new comment"
cat dummy.ini
rm -f dummy.ini
# Use as include:
cp -f data.ini dummy.ini
# shellcheck source=main.sh
source "${__root}/src/ini_val.sh"
echo "--> function: Read 3 values"
ini_val ./dummy.ini orphan
ini_val ./dummy.ini connection.host
ini_val ./dummy.ini software.packages
ini_val ./dummy.ini comment.command
echo "--> function: Replace three values in-place and show result"
ini_val ./dummy.ini orphan "no more"
ini_val ./dummy.ini connection.host "192.168.0.1"
ini_val ./dummy.ini software.packages "vim"
ini_val ./dummy.ini comment.command "commented" "this key is commited"
ini_val ./dummy.ini comment.new_command "commented too" "last addition will be moved downwards again after next command"
ini_val ./dummy.ini comment.command "works like a chame" "got this new comment"
cat dummy.ini
rm -f dummy.ini

View File

@ -1,17 +0,0 @@
#!/usr/bin/env bash
# set -o pipefail
# set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
echo "B3BP:STDIO_REPLACE_DATETIMES"
(env LOG_LEVEL=6 bash "${__root}/main.sh" --file /tmp/x;
env LOG_LEVEL=6 bash "${__root}/main.sh" --file=/tmp/x;
env LOG_LEVEL=6 bash "${__root}/main.sh" -f /tmp/x) 2>&1 |grep arg_f

View File

@ -0,0 +1,12 @@
#!/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)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
env LOG_LEVEL=7 bash "${__root}/main.sh" -f /tmp/x

12
test/scenario/main-help/run.sh Executable file
View File

@ -0,0 +1,12 @@
#!/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)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
bash "${__root}/main.sh" -f /tmp/x -h

View File

@ -0,0 +1,16 @@
#!/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)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
(
env LOG_LEVEL=6 bash "${__root}/main.sh" --file /tmp/x;
env LOG_LEVEL=6 bash "${__root}/main.sh" --file=/tmp/x;
env LOG_LEVEL=6 bash "${__root}/main.sh" -f /tmp/x
) 2>&1 |grep arg_f

View File

@ -0,0 +1,12 @@
#!/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)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
env LOG_LEVEL=7 NO_COLOR=true bash "${__root}/main.sh" -f /tmp/x

View File

@ -0,0 +1,19 @@
#!/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)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
(
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="${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

@ -0,0 +1,32 @@
#!/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)"
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-1 --one Do one thing. Default="ONE"
More description.
-2 --two Do two things.
More description. Default="TWO"
-3 --three [arg] Do three things. Default="'THREE'"
More description.
-4 --four [arg] Do four things.
More description. Default='"FOUR"'
-5 --five [arg] Do five things. Default="FIVE"
More description. Default='OOOPS'
-6 --six [arg] Do six things.
More description.
EOF
export __usage
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
# shellcheck source=main.sh
source "${__root}/main.sh"
for argument in ${!arg_*}; do info "${argument}: ${!argument}"; done

View File

@ -0,0 +1,64 @@
#!/usr/bin/env bash
# shellcheck source=main.sh
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)"
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-0 --zero Do nothing.
-1 --one Do one thing. Required.
More description.
-2 --two Do two things.
More. Required. Description.
-3 --three [arg] Do three things.
Required.
-4 --four {arg} Do four things.
-5 --five {arg} Do five things. Required. Maybe.
-6 --six [arg] Do six things. Not Required.
Required, it is not.
-7 --seven [arg] Required. Or bust.
-8 --eight [arg] Do eight things.
More.Required.Description.
-a [arg] Do A. Required.
Default="do-a"
-b {arg} Do B.Default="do-b"
-c [arg] Required. Default="do-c"
-d {arg} Default="do-d"
EOF
export __usage
export NO_COLOR="true"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
echo "# complain about -3"
(source "${__root}/main.sh") || true
echo "# complain about -4"
(source "${__root}/main.sh" -3 arg3) || true
echo "# complain about -5"
(source "${__root}/main.sh" -3 arg3 -4 arg4) || true
echo "# complain about -8 (because -7 syntax is not supported)"
(source "${__root}/main.sh" -3 arg3 -4 arg4 -5 arg5) || true
echo "# complain about -d (because -d syntax is not supported)"
(source "${__root}/main.sh" -3 arg3 -4 arg4 -5 arg5 -8 arg8) || true
echo "# complain about nothing"
(
source "${__root}/main.sh" -3 arg3 -4 arg4 -5 arg5 -8 arg8 -d argd
for argument in ${!arg_*}; do info "${argument}: ${!argument}"; done
)
echo "# test for issue #108"
(
source "${__root}/main.sh" -3 arg3 -5 arg5 -8 arg8 -d argd --four value --zero
for argument in ${!arg_*}; do info "${argument}: ${!argument}"; done
)

View File

@ -0,0 +1,21 @@
#!/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)"
__sysTmpDir="${TMPDIR:-/tmp}"
__sysTmpDir="${__sysTmpDir%/}" # <-- remove trailing slash on macosx
# Currently I only know how to test a failing condition here since
# it's too invasive to create actual mounts to play with on a system
bash "${__root}/src/megamount.sh" 'foobarfs://janedoe:abc123@192.168.0.1/documents' "${__sysTmpDir}/mnt/documents" || true
# shellcheck source=src/megamount.sh
source "${__root}/src/megamount.sh"
megamount 'foobarfs://janedoe:abc123@192.168.0.1/documents' "${__sysTmpDir}/mnt/documents"

View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
echo "B3BP:STDIO_REPLACE_DATETIMES"
env LOG_LEVEL=8 NO_COLOR=true bash "${__root}/main.sh" -f /tmp/x

View File

@ -0,0 +1,17 @@
#!/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)"
bash "${__root}/src/parse_url.sh" 'http://johndoe:abc123@example.com:8080/index.html' pass
bash "${__root}/src/parse_url.sh" 'http://johndoe:abc123@example.com:8080/index.html'
# shellcheck source=src/parse_url.sh
source "${__root}/src/parse_url.sh"
parse_url 'http://johndoe:abc123@example.com:8080/index.html' pass
parse_url 'http://johndoe:abc123@example.com:8080/index.html'

View File

@ -0,0 +1,2 @@
[connection]
host = ${TARGET_HOST}

View File

@ -0,0 +1,3 @@
[connection]
host = ${TARGET_HOST}
port = ${I_DONT_EXIST}

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename "${__file}" .sh)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
__templaterTmpFile=$(mktemp "${TMPDIR:-/tmp}/${__base}.XXXXXX")
function cleanup_before_exit () { rm "${__templaterTmpFile:?}"; }
trap cleanup_before_exit EXIT
echo "--"
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./app.template.cfg "${__templaterTmpFile}"
cat "${__templaterTmpFile}"
echo "--"
export TARGET_HOST="127.0.0.1"
# shellcheck source=src/templater.sh
source "${__root}/src/templater.sh"
templater ./app.template.cfg "${__templaterTmpFile}"
cat "${__templaterTmpFile}"
echo "--"
env ALLOW_REMAINDERS="1" TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./break.template.cfg "${__templaterTmpFile}"
cat "${__templaterTmpFile}"
echo "--"
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./break.template.cfg "${__templaterTmpFile}"
cat "${__templaterTmpFile}"

45
test/style.pl Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env perl
use strict;
use warnings;
die "usage: $0 <file>\n" if (not @ARGV);
my $rc = 0;
my $file = shift;
open(my $fh, '<', $file) or die "Cannot open \`$file' for read: $!\n";
while (<$fh>) {
next if (/^\s*#/);
my $errors = 0;
# remove everything between single quotes
# this will remove too much in case of: echo "var='$var'"
# and thus miss an opportunity to complain later on
# also it mangles the input line irreversible
s/'[^']+'/'___'/g;
# highlight unbraced variables--
# unless properly backslash'ed
$errors += s/((?:^|[^\\]))(((\\\\)+)?\$\w)/$1\033[31m$2\033[0m/g;
# highlight single square brackets
$errors += s/((?:^|\s+))\[([^\[].+[^\]])\](\s*(;|&&|\|\|))/$1\033[31m\[\033[0m$2\033[31m\]\033[0m$3/g;
# highlight double equal sign
$errors += s/(\[\[.*)(==)(.*\]\])/$1\033[31m$2\033[0m$3/g;
# highlight tabs mixed with whitespace at beginning of lines
$errors += s/^( *)(\t+ *)/\033[31m\[$2\]\033[0m/;
# highlight trailing whitespace
$errors += s/([ \t]+)$/\033[31m\[$1\]\033[0m/;
next if (not $errors);
print "${file}[$.]: $_";
$rc = 1;
}
close($fh);
exit $rc;

1372
yarn.lock Normal file

File diff suppressed because it is too large Load Diff