mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-06-25 00:13:23 +00:00
Compare commits
168 Commits
v1.0.2
...
improved-e
Author | SHA1 | Date | |
---|---|---|---|
868237f5e1 | |||
6597d9eaa6 | |||
4649b1e4cb | |||
f012ea6b70 | |||
89a260e2cc | |||
6b8caf9e98 | |||
1bf44da016 | |||
2c9175dd50 | |||
c1f7354a7f | |||
35b51072b3 | |||
8bbba18f7e | |||
03a2ec5adf | |||
bd49dda4b4 | |||
56e02e9306 | |||
3f0a7c9166 | |||
1f2e1842b3 | |||
2b3ee1d195 | |||
2d302dd8ac | |||
f6a3bb55d4 | |||
3d22171ba3 | |||
b3c3746948 | |||
c8441451bc | |||
e4848e360a | |||
e0055e5dc1 | |||
845a9dfb50 | |||
ca8c0a19df | |||
1166c878be | |||
9dea81377e | |||
272dd896d0 | |||
bc1b96db71 | |||
818d7c81c7 | |||
494584b6fd | |||
8e9814bc6a | |||
dba28c0e8e | |||
be3ca43dff | |||
28865fc633 | |||
0bfba0661c | |||
e56e21dc37 | |||
09cf71d23c | |||
64488e569a | |||
e0aadaf50c | |||
008face7c8 | |||
4926bbc942 | |||
83b13e5f55 | |||
649b5a0f44 | |||
f7fc992b2d | |||
efefd5cf2b | |||
5ee427eef5 | |||
b71ca507ab | |||
8bed4a2aaf | |||
4c45be4269 | |||
156f12f53f | |||
16401017e0 | |||
2d25f6b0dc | |||
400f29b30c | |||
95365e6f92 | |||
26e282c37f | |||
7effd3c9d1 | |||
90f52ea19a | |||
65338c1660 | |||
fe733c1356 | |||
ff881d529f | |||
ae230acc3b | |||
0487f12fff | |||
00f84ff8d9 | |||
fb8e44864d | |||
d0ece6da76 | |||
707a14634c | |||
18525f72da | |||
244e54daa6 | |||
12f1013611 | |||
d70312e916 | |||
fc7802d707 | |||
8687e384eb | |||
bbd4b7689b | |||
300ca2e3ad | |||
fcb6d93028 | |||
e20bb2900c | |||
547825b336 | |||
87017c728f | |||
0db28b0eec | |||
0b79205fb1 | |||
9be08bb692 | |||
41b9451b20 | |||
1fc44d2034 | |||
a4326476a3 | |||
c1fecf33c3 | |||
676989a779 | |||
51213e8786 | |||
6dc7e1f92a | |||
c111725665 | |||
abb480c394 | |||
fa7f217556 | |||
32e061c102 | |||
1143670cae | |||
a86d8d82b1 | |||
db690268ea | |||
d43cecf24a | |||
0917b75cb9 | |||
a6d2a2ad2f | |||
366d8c7c9c | |||
0001bfe30c | |||
2b46168792 | |||
1271bf807d | |||
583efe734b | |||
07ab2a95b4 | |||
7fbf9ea8e5 | |||
707583a93c | |||
e538a2be34 | |||
c3f5bcf8c9 | |||
180282d97d | |||
b404c87999 | |||
f2823681d0 | |||
67f2eafc81 | |||
c8773b999b | |||
591642cb38 | |||
c3297e4a7a | |||
619688bb0f | |||
1557e9d66a | |||
72cea95865 | |||
33887625a7 | |||
c4b4f44676 | |||
f114dea34d | |||
0c4a6c78e5 | |||
980a5950d6 | |||
cc57b8db69 | |||
2019c5146a | |||
d365e8dcea | |||
915f858d5e | |||
cbe70aa80e | |||
ff907092a3 | |||
cdc69d9e03 | |||
56721e9cd5 | |||
df3d535ab1 | |||
894c7fe538 | |||
2196cc4411 | |||
5b4800bad8 | |||
472c9e3b74 | |||
90ad85f419 | |||
d9a0c11e49 | |||
9935335ee8 | |||
e90ad7421f | |||
9d2bcdbfb4 | |||
bfb8d40f6c | |||
dd5950975d | |||
7a9d116d2c | |||
ae074aac0c | |||
30cfd19fd9 | |||
ecd6a9f04b | |||
7a3a07989f | |||
dbedd8f983 | |||
dde3b70596 | |||
bdc8778b2c | |||
63cd89a659 | |||
68219d21d4 | |||
c71b6d14c4 | |||
4c256ed58d | |||
f2e8ff236a | |||
8147ee81b5 | |||
437d384815 | |||
19fcad6851 | |||
df0ad9fe25 | |||
23b68a1bfc | |||
5b8cf352c8 | |||
2f4e089311 | |||
4cef357986 | |||
964f013e9c | |||
61d23a4d03 |
17
.gitignore
vendored
17
.gitignore
vendored
@ -1 +1,18 @@
|
||||
npm-debug.log
|
||||
node_modules
|
||||
|
||||
test/scenario/templater/break.cfg
|
||||
|
||||
website/index.md
|
||||
website/_site/
|
||||
website/_vendor/
|
||||
|
||||
website/changelog.md
|
||||
|
||||
website/faq.md
|
||||
|
||||
website/.jekyll-metadata
|
||||
|
||||
env.sh
|
||||
|
||||
website/main.sh
|
||||
|
27
.travis.yml
Normal file
27
.travis.yml
Normal file
@ -0,0 +1,27 @@
|
||||
language: generic
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
sudo: false
|
||||
- os: osx
|
||||
env:
|
||||
global:
|
||||
- secure: "LBDI3qOC+d2kmPSS8W6L9UF7HFiu1JC4HwK4j0sjGBh+gjRMpCRxFX7p51pbHd480ItDucN/0CMKy+e0umIRR/xrZSbuQqxby68eoT1tQ5nG9gpDTTEgu1n7Z3vPl9aEitMPlP1ovqRRSViBsYU3E5DRb7Vw2lDpCOj/lqAZT0Y="
|
||||
install:
|
||||
# Install acceptance test dependencies for OSX
|
||||
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then which gsed || brew install gnu-sed; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then which gtimeout || brew install coreutils; fi
|
||||
# Show versions used
|
||||
- bash --version
|
||||
- awk --version
|
||||
script: test/acceptance.sh
|
||||
# Travis docs: Note that pull request builds skip deployment step altogether.
|
||||
# https://docs.travis-ci.com/user/deployment/#Conditional-Releases-with-on
|
||||
deploy:
|
||||
skip_cleanup: true
|
||||
provider: script
|
||||
script: website/_bin/deploy.sh
|
||||
on:
|
||||
branch: master
|
||||
condition: $TRAVIS_OS_NAME = linux
|
70
CHANGELOG.md
Normal file
70
CHANGELOG.md
Normal file
@ -0,0 +1,70 @@
|
||||
# Changelog
|
||||
|
||||
## master
|
||||
|
||||
Released: Unreleased. [Commit log](https://github.com/kvz/bash3boilerplate/compare/v2.0.0...master)
|
||||
|
||||
- Remove OS detection altogether (#38, thx @zbeekman)
|
||||
- Offer the main template for download as http://bash3boilerplate.sh/main.sh
|
||||
- Better OS detection (#38, thx @moviuro)
|
||||
- Improve README copy (#34, thx galaktos)
|
||||
- Fix unquoted variable access within (#34 thx galaktos)
|
||||
- For delete-key-friendliness, bundle the commandline definition block along with its parser
|
||||
- Less verbose header comments
|
||||
- For delete-key-friendliness, don't crash on undeclared help vars
|
||||
- Introduce `errtrace`, which is on by default (BREAKING)
|
||||
- Add a configurable `helptext` that is left alone by the parses and allows you to have a richer help
|
||||
- Add a simple documentation website
|
||||
- Add best practice of using `__double_underscore_prefixed_vars` to indicate global variables that are solely controlled inside your script
|
||||
- Make license more permissive by not requiring distribution of the LICENSE file if the copyright & attribution comments are left intact
|
||||
- Respect `--no-color` by setting the `NO_COLOR` flag in `main.sh` (#25, thx @gdevenyi)
|
||||
- Split out changelog into separate file
|
||||
- Added a [FAQ](./FAQ.md) (#15, #14, thanks @rouson)
|
||||
- Fix Travis OSX testing (before, it would silently pass failures) (#10)
|
||||
- Enable dashes in long, GNU style options, as well as numbers (thanks @zbeekman)
|
||||
|
||||
## v2.0.0
|
||||
|
||||
Released: 2016-02-17. [Commit log](https://github.com/kvz/bash3boilerplate/compare/v1.2.1...v2.0.0)
|
||||
|
||||
- Add tests for `templater` and follow Library export best practices
|
||||
- Add tests for `ini_val` and follow Library export best practices
|
||||
- Add tests for `parse_url` and follow Library export best practices
|
||||
- Add tests for `megamount` and follow Library export best practices
|
||||
- Remove `bump` from `src` (BREAKING)
|
||||
- Remove `semver` from `src` (BREAKING)
|
||||
|
||||
## v1.2.1
|
||||
|
||||
Released: 2016-02-17. [Commit log](https://github.com/kvz/bash3boilerplate/compare/v1.2.0...v1.2.1)
|
||||
|
||||
- Add Travis CI automated testing for OSX (thanks @zbeekman)
|
||||
|
||||
## v1.2.0
|
||||
|
||||
Released: 2016-02-16. [Commit log](https://github.com/kvz/bash3boilerplate/compare/v1.1.0...v1.2.0)
|
||||
|
||||
- Allow disabling colors via `NO_COLOR` environment variable
|
||||
- Enable `errexit`, `nounset` and `pipefail` options at the top of the script already
|
||||
- More refined colors (thanks @arathai)
|
||||
- Add a changelog to the README
|
||||
- Add `__os` magic var (limited to discovering OSX and defaulting to Linux for now)
|
||||
- Add `__base` magic var (`main`, if the source script is `main.sh`)
|
||||
- Enable long, GNU style options (thanks @zbeekman)
|
||||
- Add Travis CI automated testing for Linux
|
||||
|
||||
## v1.1.0
|
||||
|
||||
Released: 2015-06-29. [Commit log](https://github.com/kvz/bash3boilerplate/compare/v1.0.3...v1.1.0)
|
||||
|
||||
- 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
|
||||
|
||||
Released: 2014-11-02. [Commit log](https://github.com/kvz/bash3boilerplate/compare/5db569125319a89b9561b434db84e4d91faefb63...v1.0.3)
|
||||
|
||||
- Add `ini_val`, `megamount`, `parse_url`
|
||||
- Add re-usable libraries in `./src`
|
||||
- Use npm as an additional distribution channel
|
151
FAQ.md
Normal file
151
FAQ.md
Normal file
@ -0,0 +1,151 @@
|
||||
[This document is formatted with GitHub-Flavored Markdown. ]:#
|
||||
[For better viewing, including hyperlinks, read it online at ]:#
|
||||
[https://github.com/kvz/bash3boilerplate/blob/master/FAQ.md ]:#
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is a cli](#what-is-a-cli)?
|
||||
* [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)?
|
||||
* [How do I incorporate BASH3 Boilerplate into my own project](#how-do-i-incorporate-bash3boilerplate-into-my-own-project)?
|
||||
* [What is a magic variable](#what-is-a-magic-variable)?
|
||||
* [How do I incorporate BASH3 Boilerplate into my own project](#how-do-i-incorporate-bash3boilerplate-into-my-own-project)?
|
||||
* [How can I contribute to this project](#how-can-i-contribute-to-this-project)?
|
||||
|
||||
<!--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?
|
||||
|
||||
After [installing b3bp](http://bash3boilerplate.sh/#installation), you can incorporate it into your project in one of two ways:
|
||||
|
||||
1. Copy the desired portions of [main.sh](https://github.com/kvz/bash3boilerplate/blob/master/main.sh) into your own script.
|
||||
2. Use [main.sh](https://github.com/kvz/bash3boilerplate/blob/master/main.sh) as a template and start pressing the delete-key for 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](https://github.com/kvz/bash3boilerplate/blob/master/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
|
||||
```
|
||||
|
||||
2. Source [main.sh](https://github.com/kvz/bash3boilerplate/blob/master/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/master/main.sh#L53) 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 `$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_filename="${arg_t}"
|
||||
```
|
||||
|
||||
## What is a magic variable?
|
||||
|
||||
The [magic variables](https://github.com/kvz/bash3boilerplate/blob/master/main.sh#L63) 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 master 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".
|
||||
|
||||
## How can I locally develop and preview the b3bp website?
|
||||
|
||||
You should have a working Node.js >=10 and Ruby >=2 install on your workstation. When that is the case, you can run:
|
||||
|
||||
```bash
|
||||
npm run web:preview
|
||||
```
|
||||
|
||||
This will install and start all required services and automatically open a webbrowser that reloads as soon as you make any changes to the source.
|
||||
|
||||
The source mainly consists of:
|
||||
|
||||
- `./README.md` (Front page)
|
||||
- `./FAQ.md` (FAQ page)
|
||||
- `./CHANGELOG.md` (changelog page)
|
||||
- `./website/_layouts/default.html` (the design in which all pages are rendered)
|
||||
- `./website/public/app.js` (main JS file)
|
||||
- `./website/public/style.css` (main CSS file)
|
||||
|
||||
The rest is dark magic from which you should probably steer clear. : )
|
||||
|
||||
Any changes should be proposed as PRs. Anything added to `master` is automatically deployed using a combination of Travis CI and GitHub Pages.
|
||||
|
||||
## 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) `GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)`
|
||||
- [OSX](https://travis-ci.org/kvz/bash3boilerplate/jobs/109804167#L2453) `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
|
||||
```
|
4
LICENSE
4
LICENSE
@ -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.
|
||||
|
50
Makefile
50
Makefile
@ -1,16 +1,40 @@
|
||||
SHELL := /usr/bin/env bash
|
||||
# Licensed under MIT.
|
||||
# Copyright (2016) by Kevin van Zonneveld https://twitter.com/kvz
|
||||
#
|
||||
# https://www.npmjs.com/package/fakefile
|
||||
#
|
||||
# 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:
|
||||
#
|
||||
# $ npm script build:assets
|
||||
#
|
||||
# you could also type:
|
||||
#
|
||||
# $ make build-assets
|
||||
#
|
||||
# Notice that colons (:) are replaced by dashes for Makefile compatibility.
|
||||
#
|
||||
# The benefits of this wrapper are:
|
||||
#
|
||||
# - You get to keep the the scripts package.json, which is more portable
|
||||
# (Makefiles & Windows are harder to mix)
|
||||
# - Offer a polite way into the project for developers coming from different
|
||||
# languages (npm scripts is obviously very Node centric)
|
||||
# - Profit from better autocomplete (make <TAB><TAB>) than npm currently offers.
|
||||
# OSX users will have to install bash-completion
|
||||
# (http://davidalger.com/development/bash-completion-on-os-x-with-brew/)
|
||||
|
||||
release-major:
|
||||
npm version major -m "Release %s"
|
||||
git push
|
||||
npm publish
|
||||
define npm_script_targets
|
||||
TARGETS := $(shell node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"));}')
|
||||
$$(TARGETS):
|
||||
npm run $(subst -,:,$(MAKECMDGOALS))
|
||||
|
||||
release-minor:
|
||||
npm version minor -m "Release %s"
|
||||
git push
|
||||
npm publish
|
||||
.PHONY: $$(TARGETS)
|
||||
endef
|
||||
|
||||
release-patch:
|
||||
npm version patch -m "Release %s"
|
||||
git push
|
||||
npm publish
|
||||
$(eval $(call npm_script_targets))
|
||||
|
||||
# These npm run scripts are available, without needing to be mentioned in `package.json`
|
||||
install:
|
||||
npm run install
|
||||
|
176
README.md
176
README.md
@ -1,45 +1,165 @@
|
||||
# bash3boilerplate
|
||||
[](https://travis-ci.org/kvz/bash3boilerplate)
|
||||
|
||||
<!-- badges/ -->
|
||||
[](http://travis-ci.org/kvz/bash3boilerplate "Check this project's build status on TravisCI")
|
||||
[](https://www.gittip.com/kvz/ "Sponsor the development of bash3boilerplate via Gittip")
|
||||
[](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")
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kevin%40vanzonneveld%2enet&lc=NL&item_name=Open%20source%20donation%20to%20Kevin%20van%20Zonneveld¤cy_code=USD&bn=PP-DonationsBF%3abtn_donate_SM%2egif%3aNonHosted "Sponsor the development of bash3boilerplate via Paypal")
|
||||
[](https://coinbase.com/checkouts/19BtCjLCboRgTAXiaEvnvkdoRyjd843Dg2 "Sponsor the development of bash3boilerplate via BitCoin")
|
||||
<!-- /badges -->
|
||||
[This document is formatted with GitHub-Flavored Markdown. ]:#
|
||||
[For better viewing, including hyperlinks, read it online at ]:#
|
||||
[https://github.com/kvz/bash3boilerplate/blob/master/README.md]:#
|
||||
|
||||
When hacking up BASH scripts, I often find there are some
|
||||
higherlevel things like logging, configuration, commandline argument
|
||||
parsing that:
|
||||
* [Overview](#overview)
|
||||
* [Goals](#goals)
|
||||
* [Features](#features)
|
||||
* [Installation](#installation)
|
||||
* [Changelog](#changelog)
|
||||
* [Best Practices](#best-practices)
|
||||
* [Frequently Asked Questions](#frequently-asked-questions)
|
||||
* [Authors](#authors)
|
||||
* [License](#license)
|
||||
|
||||
- I need everytime
|
||||
- Take quite some effort to get right
|
||||
## 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.
|
||||
|
||||
An up to date [intro is found on my blog](http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/).
|
||||
## Goals
|
||||
|
||||
## Versioning
|
||||
Delete-Key-**Friendly**. In stead of introducing packages, compilers, etc., we propose using [`main.sh`](http://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.
|
||||
|
||||
This project implements the Semantic Versioning guidelines.
|
||||
**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.
|
||||
|
||||
Releases will be numbered with the following format:
|
||||
## Features
|
||||
|
||||
`<major>.<minor>.<patch>`
|
||||
- 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
|
||||
- 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](http://en.wikipedia.org/wiki/Syslog#Severity_levels), as well as the [twelve-factor](http://12factor.net/) guidelines
|
||||
|
||||
And constructed with the following guidelines:
|
||||
## Who uses b3bp?
|
||||
|
||||
* 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
|
||||
- [Transloadit](https://transloadit.com)
|
||||
- [OpenCoarrays](http://www.opencoarrays.org)
|
||||
- [Sourcery Institute](http://www.sourceryinstitute.org)
|
||||
- [Computational Brain Anatomy Laboratory](http://cobralab.ca/)
|
||||
|
||||
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.
|
||||
|
||||
For more information on SemVer, please visit [http://semver.org](http://semver.org).
|
||||
## Installation
|
||||
|
||||
There are three different ways to install b3bp:
|
||||
|
||||
### option 1: Download the main template
|
||||
|
||||
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.
|
||||
|
||||
```bash
|
||||
wget http://bash3boilerplate.sh/main.sh
|
||||
vim main.sh
|
||||
```
|
||||
|
||||
### option 2: Clone the entire project
|
||||
|
||||
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.
|
||||
|
||||
```bash
|
||||
git clone git@github.com:kvz/bash3boilerplate.git
|
||||
```
|
||||
|
||||
### option 3: Require via npm
|
||||
|
||||
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:
|
||||
|
||||
```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
|
||||
|
||||
Please see the [CHANGELOG.md](./CHANGELOG.md) file.
|
||||
|
||||
## Best practices
|
||||
|
||||
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.
|
||||
|
||||
### Function packaging
|
||||
|
||||
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
|
||||
my_script "${@}"
|
||||
exit $?
|
||||
fi
|
||||
```
|
||||
|
||||
This allows a user to `source` your script or invoke it as a script.
|
||||
|
||||
```bash
|
||||
# Running as a script
|
||||
$ ./my_script.sh some args --blah
|
||||
# Sourcing the script
|
||||
$ source my_script.sh
|
||||
$ my_script some more args --blah
|
||||
```
|
||||
|
||||
(taken from the [bpkg](https://raw.githubusercontent.com/bpkg/bpkg/master/README.md) project)
|
||||
|
||||
### Scoping
|
||||
|
||||
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.
|
||||
|
||||
### Coding style
|
||||
|
||||
1. Use two spaces for tabs.
|
||||
1. Use long options (`logger --priority` vs `logger -p`). If you are on 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.
|
||||
|
||||
### 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}`.
|
||||
|
||||
## Frequently Asked Questions
|
||||
|
||||
Please see the [FAQ.md](./FAQ.md) file.
|
||||
|
||||
## Authors
|
||||
|
||||
- [Kevin van Zonneveld](http://kvz.io)
|
||||
- [Izaak Beekman](https://izaakbeekman.com/)
|
||||
- [Alexander Rathai](mailto:<Alexander.Rathai@gmail.com>)
|
||||
- [Dr. Damian Rouson](http://www.sourceryinstitute.org/) (documentation, feedback)
|
||||
- [@jokajak](https://github.com/jokajak) (documentation)
|
||||
- [Gabriel A. Devenyi](http://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)
|
||||
|
||||
## 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/master/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.
|
||||
|
201
main.sh
201
main.sh
@ -1,60 +1,54 @@
|
||||
#!/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.0.0
|
||||
#
|
||||
# Authors:
|
||||
# - Kevin van Zonneveld (http://kvz.io)
|
||||
# - 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 v2.0.0
|
||||
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
||||
# http://bash3boilerplate.sh/#authors
|
||||
|
||||
# Exit on error. Append || true if you expect an error.
|
||||
set -o errexit
|
||||
# Exit on error inside any functions or subshells.
|
||||
set -o errtrace
|
||||
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
|
||||
set -o nounset
|
||||
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
|
||||
set -o pipefail
|
||||
# Turn on traces, useful while debugging but commented out by default
|
||||
# set -o xtrace
|
||||
|
||||
### Configuration
|
||||
#####################################################################
|
||||
|
||||
# Environment variables and their defaults
|
||||
LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency
|
||||
|
||||
# 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
|
||||
read -r -d '' usage <<-'EOF'
|
||||
-f [arg] Filename to process. Required.
|
||||
-t [arg] Location of tempfile. Default="/tmp/bar"
|
||||
-d Enables debug mode
|
||||
-h This page
|
||||
EOF
|
||||
|
||||
# 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 "${0}")"
|
||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||
__base="$(basename ${__file} .sh)"
|
||||
|
||||
# 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 _fmt () {
|
||||
local color_ok="\x1b[32m"
|
||||
local color_bad="\x1b[31m"
|
||||
|
||||
local color="${color_bad}"
|
||||
if [ "${1}" = "debug" ] || [ "${1}" = "info" ] || [ "${1}" = "notice" ]; then
|
||||
color="${color_ok}"
|
||||
fi
|
||||
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 [[ "${TERM}" != "xterm"* ]] || [ -t 1 ]; then
|
||||
if [ "${NO_COLOR}" = "true" ] || [[ "${TERM:-}" != "xterm"* ]] || [ -t 1 ]; then
|
||||
# Don't use colors on pipes or non-recognized terminals
|
||||
color=""; color_reset=""
|
||||
fi
|
||||
@ -73,7 +67,9 @@ function help () {
|
||||
echo "" 1>&2
|
||||
echo " ${@}" 1>&2
|
||||
echo "" 1>&2
|
||||
echo " ${usage}" 1>&2
|
||||
echo " ${__usage:-No usage available}" 1>&2
|
||||
echo "" 1>&2
|
||||
echo " ${__helptext:-}" 1>&2
|
||||
echo "" 1>&2
|
||||
exit 1
|
||||
}
|
||||
@ -85,18 +81,54 @@ trap cleanup_before_exit EXIT
|
||||
|
||||
|
||||
### 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
|
||||
# - 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)
|
||||
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
|
||||
EOF
|
||||
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 string
|
||||
opt="$(echo "${line}" |awk '{print $1}' |sed -e 's#^-##')"
|
||||
|
||||
# fetch long version if present
|
||||
long_opt="$(echo "${line}" |awk '/\-\-/ {print $2}' |sed -e 's#^--##')"
|
||||
long_opt_mangled="$(sed 's#-#_#g' <<< $long_opt)"
|
||||
|
||||
# map long name back to short name
|
||||
varname="short_opt_${long_opt_mangled}"
|
||||
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}"
|
||||
opts="${opts:-}${opt}"
|
||||
|
||||
varname="arg_${opt:0:1}"
|
||||
if ! echo "${line}" |egrep '\. Default=' >/dev/null 2>&1; then
|
||||
@ -105,17 +137,42 @@ while read line; do
|
||||
match="$(echo "${line}" |sed 's#^.*Default=\(\)#\1#g')"
|
||||
eval "${varname}=\"${match}\""
|
||||
fi
|
||||
done <<< "${usage}"
|
||||
done <<< "${__usage}"
|
||||
|
||||
# Allow long options like --this
|
||||
opts="${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 "${opts}" opt; do
|
||||
line="$(echo "${usage}" |grep "\-${opt}")"
|
||||
|
||||
|
||||
[ "${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/=*/}
|
||||
long_mangled="$(sed 's#-#_#g' <<< $long)"
|
||||
# Set opt to the short option corresponding to the long option
|
||||
eval "opt=\"\${short_opt_${long_mangled}}\""
|
||||
OPTARG=${OPTARG#*=}
|
||||
else
|
||||
# --key value format
|
||||
# Map long name to short version of option
|
||||
long_mangled="$(sed 's#-#_#g' <<< $OPTARG)"
|
||||
eval "opt=\"\${short_opt_${long_mangled}}\""
|
||||
# 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}))
|
||||
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}"
|
||||
|
||||
@ -127,14 +184,15 @@ while getopts "${opts}" opt; do
|
||||
eval "${varname}=\"${value}\""
|
||||
debug "cli arg ${varname} = ($default) -> ${!varname}"
|
||||
done
|
||||
set -o nounset # no more unbound variable references expected
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
[ "$1" = "--" ] && shift
|
||||
[ "${1:-}" = "--" ] && shift
|
||||
|
||||
|
||||
### Switches (like -d for debugmdoe, -h for showing helppage)
|
||||
#####################################################################
|
||||
### Command-line argument switches (like -d for debugmode, -h for showing helppage)
|
||||
##############################################################################
|
||||
|
||||
# debug mode
|
||||
if [ "${arg_d}" = "1" ]; then
|
||||
@ -142,6 +200,16 @@ if [ "${arg_d}" = "1" ]; then
|
||||
LOG_LEVEL="7"
|
||||
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
|
||||
@ -149,30 +217,27 @@ if [ "${arg_h}" = "1" ]; then
|
||||
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 is required"
|
||||
[ -z "${LOG_LEVEL}" ] && emergency "Cannot continue without LOG_LEVEL. "
|
||||
[ -z "${arg_f:-}" ] && help "Setting a filename with -f or --file is required"
|
||||
[ -z "${LOG_LEVEL:-}" ] && emergency "Cannot continue without LOG_LEVEL. "
|
||||
|
||||
|
||||
### Runtime
|
||||
#####################################################################
|
||||
##############################################################################
|
||||
|
||||
# Exit on error. Append ||true if you expect an error.
|
||||
# set -e is safer than #!/bin/bash -e because that is neutralised if
|
||||
# someone runs your script like `bash yourscript.sh`
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
info "__file: ${__file}"
|
||||
info "__dir: ${__dir}"
|
||||
info "__base: ${__base}"
|
||||
info "OSTYPE: ${OSTYPE}"
|
||||
|
||||
# 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`
|
||||
set -o pipefail
|
||||
|
||||
if [[ "${OSTYPE}" == "darwin"* ]]; then
|
||||
info "You are on OSX"
|
||||
fi
|
||||
info "arg_f: ${arg_f}"
|
||||
info "arg_d: ${arg_d}"
|
||||
info "arg_v: ${arg_v}"
|
||||
info "arg_h: ${arg_h}"
|
||||
|
||||
# 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."
|
||||
|
30
package.json
30
package.json
@ -1,4 +1,32 @@
|
||||
{
|
||||
"name": "bash3boilerplate",
|
||||
"version": "1.0.2"
|
||||
"description": "Copypastable templates to write better bash scripts",
|
||||
"version": "2.0.0",
|
||||
"scripts": {
|
||||
"deploy": "website/_bin/travis-deploy.sh",
|
||||
"lint": "shellcheck --shell=bash $(find . -name '*.sh' -maxdepth 2)",
|
||||
"release:major": "env SEMANTIC=major npm run release",
|
||||
"release:minor": "env SEMANTIC=minor npm run release",
|
||||
"release:patch": "env SEMANTIC=patch npm run release",
|
||||
"release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && npm run version:replace && git commit main.sh src/*.sh -m 'Update version' && git push && git push --tags && npm publish",
|
||||
"save:fixtures": "cross-env SAVE_FIXTURES=true npm run test",
|
||||
"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",
|
||||
"web:build": "cd website && bundle exec jekyll build --incremental",
|
||||
"web:inject": "./website/_bin/inject.sh",
|
||||
"web:install": "npm install && cd website && bundle install --path ./_vendor",
|
||||
"web:preview": "npm-run-all web:install --parallel web:watch web:serve",
|
||||
"web:serve": "cd website/_site && browser-sync start --server --files .",
|
||||
"web:watch": "nodemon --verbose --watch ./ --ignore 'website/*.md' --ignore 'website/_site/*' --ext html,json,md,js,css,png,jpg --exec 'npm-run-all web:inject web:build'"
|
||||
},
|
||||
"dependencies": {
|
||||
"fakefile": "0.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cross-env": "1.0.7",
|
||||
"browser-sync": "2.11.0",
|
||||
"nodemon": "1.8.1",
|
||||
"npm-run-all": "2.1.1"
|
||||
}
|
||||
}
|
||||
|
131
src/bump.sh
131
src/bump.sh
@ -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
|
72
src/ini_val.sh
Executable file
72
src/ini_val.sh
Executable file
@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
# BASH3 Boilerplate: ini_val
|
||||
#
|
||||
# This file:
|
||||
#
|
||||
# - Can read and write .ini files using pure bash
|
||||
#
|
||||
# Limitations:
|
||||
#
|
||||
# - All keys inside the .ini file must be unique, regardless of the use of sections
|
||||
#
|
||||
# Usage as a function:
|
||||
#
|
||||
# source ini_val.sh
|
||||
# ini_val data.ini connection.host 127.0.0.1
|
||||
#
|
||||
# Usage as a command:
|
||||
#
|
||||
# ini_val.sh data.ini connection.host 127.0.0.1
|
||||
#
|
||||
# Based on a template by BASH3 Boilerplate v2.0.0
|
||||
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
||||
# http://bash3boilerplate.sh/#authors
|
||||
|
||||
function ini_val() {
|
||||
local file="${1:-}"
|
||||
local sectionkey="${2:-}"
|
||||
local val="${3:-}"
|
||||
local delim=" = "
|
||||
local section=""
|
||||
local key=""
|
||||
|
||||
# Split on . for section. However, section is optional
|
||||
read section key <<<$(IFS="."; echo ${sectionkey})
|
||||
if [ -z "${key}" ]; then
|
||||
key="${section}"
|
||||
section=""
|
||||
fi
|
||||
|
||||
local current=$(awk -F "${delim}" "/^${key}${delim}/ {for (i=2; i<NF; i++) printf \$i \" \"; print \$NF}" "${file}")
|
||||
if [ -z "${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 -i.bak -e "/\[${section}\]/a ${key}${delim}${val}" "${file}"
|
||||
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
|
||||
rm -f "${file}.bak"
|
||||
fi
|
||||
else
|
||||
# replace existing
|
||||
sed -i.bak -e "/^${key}${delim}/s/${delim}.*/${delim}${val}/" "${file}"
|
||||
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
|
||||
rm -f "${file}.bak"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "${BASH_SOURCE[0]}" != "${0}" ]; then
|
||||
export -f ini_val
|
||||
else
|
||||
ini_val "${@}"
|
||||
exit ${?}
|
||||
fi
|
65
src/megamount.sh
Normal file
65
src/megamount.sh
Normal file
@ -0,0 +1,65 @@
|
||||
#!/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
|
||||
# - Forceully unmounts any active mount at the target directory first
|
||||
# - Displays the mounts 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 v2.0.0
|
||||
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
||||
# http://bash3boilerplate.sh/#authors
|
||||
|
||||
__dir=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
|
||||
source "${__dir}/parse_url.sh"
|
||||
|
||||
function megamount () {
|
||||
local url="${1}"
|
||||
local target="${2}"
|
||||
|
||||
local proto=$(parse_url "${url}" "proto")
|
||||
local user=$(parse_url "${url}" "user")
|
||||
local pass=$(parse_url "${url}" "pass")
|
||||
local host=$(parse_url "${url}" "host")
|
||||
local port=$(parse_url "${url}" "port")
|
||||
local path=$(parse_url "${url}" "path")
|
||||
|
||||
(umount -lf "${target}" || umount -f "${target}") > /dev/null 2>&1 || true
|
||||
mkdir -p "${target}"
|
||||
if [ "${proto}" = "smb://" ]; then
|
||||
mount -t cifs --verbose -o "username=${user},password=${pass},hard" "//${host}/${path}" "${target}"
|
||||
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}"
|
||||
else
|
||||
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
|
70
src/parse_url.sh
Normal file
70
src/parse_url.sh
Normal file
@ -0,0 +1,70 @@
|
||||
#!/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 v2.0.0
|
||||
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
||||
# http://bash3boilerplate.sh/#authors
|
||||
|
||||
function parse_url() {
|
||||
local parse="${1}"
|
||||
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-)"
|
||||
|
||||
[ -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"
|
||||
fi
|
||||
|
||||
if [ -n "${need}" ]; then
|
||||
echo ${!need}
|
||||
else
|
||||
echo ""
|
||||
echo " Use second argument to return just 1 variable."
|
||||
echo " parse_url() demo: "
|
||||
echo ""
|
||||
echo " proto: ${proto}"
|
||||
echo " user: ${user}"
|
||||
echo " pass: ${pass}"
|
||||
echo " host: ${host}"
|
||||
echo " port: ${port}"
|
||||
echo " path: ${path}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "${BASH_SOURCE[0]}" != "${0}" ]; then
|
||||
export -f parse_url
|
||||
else
|
||||
parse_url "${@}"
|
||||
exit ${?}
|
||||
fi
|
132
src/semver.sh
132
src/semver.sh
@ -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
|
@ -1,42 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2014, Transloadit Ltd.
|
||||
# BASH3 Boilerplate: templater
|
||||
#
|
||||
# This file:
|
||||
#
|
||||
# This file
|
||||
# - takes a source (template) & destination (config) filepath argument
|
||||
# - and then replaces placeholders with variables found in the environment
|
||||
# - then replaces placeholders with variables found in the environment
|
||||
#
|
||||
# Authors:
|
||||
# - Kevin van Zonneveld <kevin@transloadit.com>
|
||||
# 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
|
||||
#
|
||||
# Based on a template by BASH3 Boilerplate v2.0.0
|
||||
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
||||
# http://bash3boilerplate.sh/#authors
|
||||
|
||||
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:-}"
|
||||
|
||||
templateSrc="${1}"
|
||||
templateDst="${2}"
|
||||
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 be specified"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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}; then
|
||||
echo "ERROR: Unable to replace the above template vars"
|
||||
exit 1
|
||||
cp -f "${templateSrc}" "${templateDst}"
|
||||
for var in $(env |awk -F= '{print $1}' |egrep '^[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
|
||||
|
||||
# cat "${templateDst}"
|
||||
|
||||
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
|
||||
|
177
test/acceptance.sh
Executable file
177
test/acceptance.sh
Executable file
@ -0,0 +1,177 @@
|
||||
#!/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
|
||||
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
||||
# http://bash3boilerplate.sh/#authors
|
||||
|
||||
# Exit on error. Append || true if you expect an error.
|
||||
set -o errexit
|
||||
# Exit on error inside any functions or subshells.
|
||||
set -o errtrace
|
||||
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
|
||||
set -o nounset
|
||||
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
|
||||
set -o pipefail
|
||||
# Turn on traces, useful while debugging but commented out by default
|
||||
# set -o xtrace
|
||||
|
||||
# Set magic variables for current file, directory, os, etc.
|
||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||
__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
|
||||
__accptstTmpDir="${__sysTmpDir}/accptst"
|
||||
mkdir -p "${__accptstTmpDir}"
|
||||
|
||||
if [[ "${OSTYPE}" == "darwin"* ]]; then
|
||||
cmdSed=gsed
|
||||
else
|
||||
cmdSed=sed
|
||||
fi
|
||||
|
||||
if [[ "${OSTYPE}" == "darwin"* ]]; then
|
||||
cmdTimeout="gtimeout --kill-after=6m 5m"
|
||||
else
|
||||
cmdTimeout="timeout --kill-after=6m 5m"
|
||||
fi
|
||||
|
||||
__node="$(which node)"
|
||||
__arch="amd64"
|
||||
|
||||
|
||||
if ! which "${cmdSed}" > /dev/null; then
|
||||
echo "Please install ${cmdSed}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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
|
||||
echo "==> Scenario: ${scenario}"
|
||||
pushd "${__dir}/scenario/${scenario}" > /dev/null
|
||||
|
||||
# Run scenario
|
||||
(${cmdTimeout} 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="${__accptstTmpDir}/${scenario}.${typ}"
|
||||
"${cmdSed}" -i \
|
||||
-e "s@${__node}@{node}@g" "${curFile}" \
|
||||
-e "s@${__root}@{root}@g" "${curFile}" \
|
||||
-e "s@${__sysTmpDir}@{tmpdir}@g" "${curFile}" \
|
||||
-e "s@/tmp@{tmpdir}@g" "${curFile}" \
|
||||
-e "s@${HOME:-/home/travis}@{home}@g" "${curFile}" \
|
||||
-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@{home}/build/{user}/fre{node}@{node}@g" "${curFile}" \
|
||||
-e "s@${HOSTNAME}@{hostname}@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 'ACCPTST:STDIO_REPLACE_IPS' |wc -l)" -gt 0 ]; then
|
||||
"${cmdSed}" -i \
|
||||
-r 's@[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}@{ip}@g' \
|
||||
"${curFile}"
|
||||
|
||||
# IPs vary in length. Ansible uses padding. {ip} does not vary in length
|
||||
# so kill the padding after it for consistent output
|
||||
"${cmdSed}" -i \
|
||||
-r 's@\{ip\}\s+@{ip} @g' \
|
||||
"${curFile}"
|
||||
fi
|
||||
if [ "$(cat "${curFile}" |grep 'ACCPTST:STDIO_REPLACE_UUIDS' |wc -l)" -gt 0 ]; then
|
||||
"${cmdSed}" -i \
|
||||
-r 's@[0-9a-f\-]{32,40}@{uuid}@g' \
|
||||
"${curFile}"
|
||||
fi
|
||||
if [ "$(cat "${curFile}" |grep 'ACCPTST:STDIO_REPLACE_BIGINTS' |wc -l)" -gt 0 ]; then
|
||||
# Such as: 3811298194
|
||||
"${cmdSed}" -i \
|
||||
-r 's@[0-9]{7,64}@{bigint}@g' \
|
||||
"${curFile}"
|
||||
fi
|
||||
if [ "$(cat "${curFile}" |grep 'ACCPTST:STDIO_REPLACE_DATETIMES' |wc -l)" -gt 0 ]; 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 'ACCPTST:STDIO_REPLACE_LONGTIMES' |wc -l)" -gt 0 ]; 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 'ACCPTST:STDIO_REPLACE_DURATIONS' |wc -l)" -gt 0 ]; 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 'ACCPTST:STDIO_REPLACE_REMOTE_EXEC' |wc -l)" -gt 0 ]; then
|
||||
egrep -v '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="${__accptstTmpDir}/${scenario}.${typ}"
|
||||
cp -f \
|
||||
"${curFile}" \
|
||||
"${__dir}/fixture/${scenario}.${typ}"
|
||||
done
|
||||
fi
|
||||
|
||||
# Compare
|
||||
for typ in $(echo stdio exitcode); do
|
||||
curFile="${__accptstTmpDir}/${scenario}.${typ}"
|
||||
|
||||
echo -n " comparing ${typ}.. "
|
||||
|
||||
if [ "${typ}" = "stdio" ]; then
|
||||
if [ "$(cat "${curFile}" |grep 'ACCPTST:STDIO_SKIP_COMPARE' |wc -l)" -gt 0 ]; then
|
||||
echo "skip"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
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
|
0
test/fixture/.empty
Normal file
0
test/fixture/.empty
Normal file
1
test/fixture/ini_val.exitcode
Normal file
1
test/fixture/ini_val.exitcode
Normal file
@ -0,0 +1 @@
|
||||
0
|
24
test/fixture/ini_val.stdio
Normal file
24
test/fixture/ini_val.stdio
Normal file
@ -0,0 +1,24 @@
|
||||
--> command: Read 3 values
|
||||
exists
|
||||
127.0.0.1
|
||||
nginx, nodejs
|
||||
--> command: Replace three values in-place and show result
|
||||
orphan = no more
|
||||
|
||||
[connection]
|
||||
host = 192.168.0.1
|
||||
|
||||
[software]
|
||||
packages = vim
|
||||
--> function: Read 3 values
|
||||
exists
|
||||
127.0.0.1
|
||||
nginx, nodejs
|
||||
--> function: Replace three values in-place and show result
|
||||
orphan = no more
|
||||
|
||||
[connection]
|
||||
host = 192.168.0.1
|
||||
|
||||
[software]
|
||||
packages = vim
|
1
test/fixture/main-debug.exitcode
Normal file
1
test/fixture/main-debug.exitcode
Normal file
@ -0,0 +1 @@
|
||||
1
|
19
test/fixture/main-debug.stdio
Normal file
19
test/fixture/main-debug.stdio
Normal file
@ -0,0 +1,19 @@
|
||||
ACCPTST:STDIO_REPLACE_DATETIMES
|
||||
{datetime} UTC [35m[ debug][0m cli arg arg_f = () -> {tmpdir}/x
|
||||
{datetime} UTC [32m[ info][0m __file: {root}/main.sh
|
||||
{datetime} UTC [32m[ info][0m __dir: {root}
|
||||
{datetime} UTC [32m[ info][0m __base: main
|
||||
{datetime} UTC [32m[ info][0m OSTYPE: {OSTYPE}
|
||||
{datetime} UTC [32m[ info][0m arg_f: {tmpdir}/x
|
||||
{datetime} UTC [32m[ info][0m arg_d: 0
|
||||
{datetime} UTC [32m[ info][0m arg_v: 0
|
||||
{datetime} UTC [32m[ info][0m arg_h: 0
|
||||
{datetime} UTC [35m[ debug][0m Info useful to developers for debugging the application, not useful during operations.
|
||||
{datetime} UTC [32m[ info][0m Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required.
|
||||
{datetime} UTC [34m[ notice][0m Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required.
|
||||
{datetime} UTC [33m[ warning][0m Warning messages, not an error, but indication that an error will occur if action is not taken, e.g. file system 85% full - each item must be resolved within a given time. This is a debug message
|
||||
{datetime} UTC [31m[ error][0m Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time.
|
||||
{datetime} UTC [1;31m[ critical][0m Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection.
|
||||
{datetime} UTC [1;33;41m[ alert][0m Should be corrected immediately, therefore notify staff who can fix the problem. An example would be the loss of a primary ISP connection.
|
||||
{datetime} UTC [1;4;5;33;41m[emergency][0m A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
|
||||
{datetime} UTC [32m[ info][0m Cleaning up. Done
|
1
test/fixture/main-help.exitcode
Normal file
1
test/fixture/main-help.exitcode
Normal file
@ -0,0 +1 @@
|
||||
1
|
17
test/fixture/main-help.stdio
Normal file
17
test/fixture/main-help.stdio
Normal file
@ -0,0 +1,17 @@
|
||||
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
|
||||
|
||||
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 [32m[ info][0m Cleaning up. Done
|
1
test/fixture/main-longopt.exitcode
Normal file
1
test/fixture/main-longopt.exitcode
Normal file
@ -0,0 +1 @@
|
||||
0
|
4
test/fixture/main-longopt.stdio
Normal file
4
test/fixture/main-longopt.stdio
Normal file
@ -0,0 +1,4 @@
|
||||
ACCPTST:STDIO_REPLACE_DATETIMES
|
||||
{datetime} UTC [32m[ info][0m arg_f: {tmpdir}/x
|
||||
{datetime} UTC [32m[ info][0m arg_f: {tmpdir}/x
|
||||
{datetime} UTC [32m[ info][0m arg_f: {tmpdir}/x
|
1
test/fixture/main-nocolor.exitcode
Normal file
1
test/fixture/main-nocolor.exitcode
Normal file
@ -0,0 +1 @@
|
||||
1
|
19
test/fixture/main-nocolor.stdio
Normal file
19
test/fixture/main-nocolor.stdio
Normal file
@ -0,0 +1,19 @@
|
||||
ACCPTST:STDIO_REPLACE_DATETIMES
|
||||
{datetime} UTC [ debug] cli arg arg_f = () -> {tmpdir}/x
|
||||
{datetime} UTC [ info] __file: {root}/main.sh
|
||||
{datetime} UTC [ info] __dir: {root}
|
||||
{datetime} UTC [ info] __base: main
|
||||
{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 [ 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 [ 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
|
1
test/fixture/megamount.exitcode
Normal file
1
test/fixture/megamount.exitcode
Normal file
@ -0,0 +1 @@
|
||||
1
|
2
test/fixture/megamount.stdio
Normal file
2
test/fixture/megamount.stdio
Normal file
@ -0,0 +1,2 @@
|
||||
ERR: Unknown protocol: 'foobarfs://'
|
||||
ERR: Unknown protocol: 'foobarfs://'
|
1
test/fixture/parse_url.exitcode
Normal file
1
test/fixture/parse_url.exitcode
Normal file
@ -0,0 +1 @@
|
||||
0
|
24
test/fixture/parse_url.stdio
Normal file
24
test/fixture/parse_url.stdio
Normal 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
|
||||
|
1
test/fixture/templater.exitcode
Normal file
1
test/fixture/templater.exitcode
Normal file
@ -0,0 +1 @@
|
||||
1
|
14
test/fixture/templater.stdio
Normal file
14
test/fixture/templater.stdio
Normal 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
|
7
test/scenario/ini_val/data.ini
Normal file
7
test/scenario/ini_val/data.ini
Normal file
@ -0,0 +1,7 @@
|
||||
orphan = exists
|
||||
|
||||
[connection]
|
||||
host = 127.0.0.1
|
||||
|
||||
[software]
|
||||
packages = nginx, nodejs
|
43
test/scenario/ini_val/run.sh
Normal file
43
test/scenario/ini_val/run.sh
Normal file
@ -0,0 +1,43 @@
|
||||
#!/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 "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
|
||||
|
||||
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"
|
||||
cat dummy.ini
|
||||
rm -f dummy.ini
|
||||
|
||||
# Use as include:
|
||||
cp -f data.ini dummy.ini
|
||||
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
|
||||
|
||||
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"
|
||||
cat dummy.ini
|
||||
rm -f dummy.ini
|
15
test/scenario/main-debug/run.sh
Normal file
15
test/scenario/main-debug/run.sh
Normal file
@ -0,0 +1,15 @@
|
||||
#!/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 "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||
|
||||
env LOG_LEVEL=8 bash "${__root}/main.sh" -f /tmp/x
|
15
test/scenario/main-help/run.sh
Executable file
15
test/scenario/main-help/run.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/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 "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||
|
||||
bash "${__root}/main.sh" -h
|
17
test/scenario/main-longopt/run.sh
Normal file
17
test/scenario/main-longopt/run.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/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 "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
|
15
test/scenario/main-nocolor/run.sh
Normal file
15
test/scenario/main-nocolor/run.sh
Normal file
@ -0,0 +1,15 @@
|
||||
#!/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 "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||
|
||||
env LOG_LEVEL=8 NO_COLOR=true bash "${__root}/main.sh" -f /tmp/x
|
22
test/scenario/megamount/run.sh
Normal file
22
test/scenario/megamount/run.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/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)"
|
||||
|
||||
__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
|
||||
|
||||
source ${__root}/src/megamount.sh
|
||||
megamount 'foobarfs://janedoe:abc123@192.168.0.1/documents' "${__sysTmpDir}/mnt/documents"
|
18
test/scenario/parse_url/run.sh
Normal file
18
test/scenario/parse_url/run.sh
Normal file
@ -0,0 +1,18 @@
|
||||
#!/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)"
|
||||
|
||||
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'
|
||||
|
||||
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'
|
2
test/scenario/templater/app.template.cfg
Normal file
2
test/scenario/templater/app.template.cfg
Normal file
@ -0,0 +1,2 @@
|
||||
[connection]
|
||||
host = ${TARGET_HOST}
|
3
test/scenario/templater/break.template.cfg
Normal file
3
test/scenario/templater/break.template.cfg
Normal file
@ -0,0 +1,3 @@
|
||||
[connection]
|
||||
host = ${TARGET_HOST}
|
||||
port = ${I_DONT_EXIST}
|
33
test/scenario/templater/run.sh
Normal file
33
test/scenario/templater/run.sh
Normal file
@ -0,0 +1,33 @@
|
||||
#!/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 "--"
|
||||
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./app.template.cfg ./app.cfg
|
||||
cat app.cfg
|
||||
rm -f app.cfg
|
||||
|
||||
echo "--"
|
||||
export TARGET_HOST="127.0.0.1"
|
||||
source ${__root}/src/templater.sh
|
||||
templater ./app.template.cfg ./app.cfg
|
||||
cat app.cfg
|
||||
rm -f app.cfg
|
||||
|
||||
echo "--"
|
||||
env ALLOW_REMAINDERS="1" TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./break.template.cfg ./break.cfg
|
||||
cat break.cfg
|
||||
rm -f break.cfg
|
||||
|
||||
echo "--"
|
||||
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./break.template.cfg ./break.cfg
|
||||
cat break.cfg
|
||||
rm -f break.cfg
|
3
website/.bundle/config
Normal file
3
website/.bundle/config
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
BUNDLE_PATH: ./_vendor
|
||||
BUNDLE_DISABLE_SHARED_GEMS: '1'
|
1
website/.stylelintrc
Normal file
1
website/.stylelintrc
Normal file
@ -0,0 +1 @@
|
||||
{rules: {}}
|
1
website/CNAME
Normal file
1
website/CNAME
Normal file
@ -0,0 +1 @@
|
||||
bash3boilerplate.sh
|
4
website/Gemfile
Normal file
4
website/Gemfile
Normal file
@ -0,0 +1,4 @@
|
||||
source 'https://rubygems.org'
|
||||
gem 'github-pages', group: :jekyll_plugins
|
||||
gem 'stringex', '2.6.0'
|
||||
gem 'jekyll-redirect-from', '0.10.0'
|
131
website/Gemfile.lock
Normal file
131
website/Gemfile.lock
Normal file
@ -0,0 +1,131 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
activesupport (4.2.6)
|
||||
i18n (~> 0.7)
|
||||
json (~> 1.7, >= 1.7.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
addressable (2.4.0)
|
||||
coffee-script (2.4.1)
|
||||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.10.0)
|
||||
colorator (0.1)
|
||||
ethon (0.9.0)
|
||||
ffi (>= 1.3.0)
|
||||
execjs (2.7.0)
|
||||
faraday (0.9.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.9.10)
|
||||
gemoji (2.1.0)
|
||||
github-pages (83)
|
||||
github-pages-health-check (= 1.1.0)
|
||||
jekyll (= 3.1.6)
|
||||
jekyll-coffeescript (= 1.0.1)
|
||||
jekyll-feed (= 0.5.1)
|
||||
jekyll-gist (= 1.4.0)
|
||||
jekyll-github-metadata (= 2.0.0)
|
||||
jekyll-mentions (= 1.1.2)
|
||||
jekyll-paginate (= 1.1.0)
|
||||
jekyll-redirect-from (= 0.10.0)
|
||||
jekyll-sass-converter (= 1.3.0)
|
||||
jekyll-seo-tag (= 2.0.0)
|
||||
jekyll-sitemap (= 0.10.0)
|
||||
jemoji (= 0.6.2)
|
||||
kramdown (= 1.11.1)
|
||||
liquid (= 3.0.6)
|
||||
listen (= 3.0.6)
|
||||
mercenary (~> 0.3)
|
||||
rouge (= 1.10.1)
|
||||
terminal-table (~> 1.4)
|
||||
github-pages-health-check (1.1.0)
|
||||
addressable (~> 2.3)
|
||||
net-dns (~> 0.8)
|
||||
octokit (~> 4.0)
|
||||
public_suffix (~> 1.4)
|
||||
typhoeus (~> 0.7)
|
||||
html-pipeline (2.4.1)
|
||||
activesupport (>= 2, < 5)
|
||||
nokogiri (>= 1.4)
|
||||
i18n (0.7.0)
|
||||
jekyll (3.1.6)
|
||||
colorator (~> 0.1)
|
||||
jekyll-sass-converter (~> 1.0)
|
||||
jekyll-watch (~> 1.1)
|
||||
kramdown (~> 1.3)
|
||||
liquid (~> 3.0)
|
||||
mercenary (~> 0.3.3)
|
||||
rouge (~> 1.7)
|
||||
safe_yaml (~> 1.0)
|
||||
jekyll-coffeescript (1.0.1)
|
||||
coffee-script (~> 2.2)
|
||||
jekyll-feed (0.5.1)
|
||||
jekyll-gist (1.4.0)
|
||||
octokit (~> 4.2)
|
||||
jekyll-github-metadata (2.0.0)
|
||||
jekyll (~> 3.1)
|
||||
octokit (~> 4.0)
|
||||
jekyll-mentions (1.1.2)
|
||||
html-pipeline (~> 2.3)
|
||||
jekyll (~> 3.0)
|
||||
jekyll-paginate (1.1.0)
|
||||
jekyll-redirect-from (0.10.0)
|
||||
jekyll (>= 2.0)
|
||||
jekyll-sass-converter (1.3.0)
|
||||
sass (~> 3.2)
|
||||
jekyll-seo-tag (2.0.0)
|
||||
jekyll (~> 3.1)
|
||||
jekyll-sitemap (0.10.0)
|
||||
jekyll-watch (1.4.0)
|
||||
listen (~> 3.0, < 3.1)
|
||||
jemoji (0.6.2)
|
||||
gemoji (~> 2.0)
|
||||
html-pipeline (~> 2.2)
|
||||
jekyll (>= 3.0)
|
||||
json (1.8.3)
|
||||
kramdown (1.11.1)
|
||||
liquid (3.0.6)
|
||||
listen (3.0.6)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9.7)
|
||||
mercenary (0.3.6)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.9.0)
|
||||
multipart-post (2.0.0)
|
||||
net-dns (0.8.0)
|
||||
nokogiri (1.6.8)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
pkg-config (~> 1.1.7)
|
||||
octokit (4.3.0)
|
||||
sawyer (~> 0.7.0, >= 0.5.3)
|
||||
pkg-config (1.1.7)
|
||||
public_suffix (1.5.3)
|
||||
rb-fsevent (0.9.7)
|
||||
rb-inotify (0.9.7)
|
||||
ffi (>= 0.5.0)
|
||||
rouge (1.10.1)
|
||||
safe_yaml (1.0.4)
|
||||
sass (3.4.22)
|
||||
sawyer (0.7.0)
|
||||
addressable (>= 2.3.5, < 2.5)
|
||||
faraday (~> 0.8, < 0.10)
|
||||
stringex (2.6.0)
|
||||
terminal-table (1.6.0)
|
||||
thread_safe (0.3.5)
|
||||
typhoeus (0.8.0)
|
||||
ethon (>= 0.8.0)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
github-pages
|
||||
jekyll-redirect-from (= 0.10.0)
|
||||
stringex (= 2.6.0)
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.0
|
71
website/_bin/deploy.sh
Executable file
71
website/_bin/deploy.sh
Executable file
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
# This file:
|
||||
#
|
||||
# - Let's inject.sh inject markdown files into the ./website directory
|
||||
# - Syncs that to a temporary directory along with a git init
|
||||
# - (in case of Travis CI) assumes a Git bot identity, and uses an overriden GHPAGES_URL containing its token thanks to `travis encrypt`
|
||||
# - Force pushes that to the gh-pages branch
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# ./deploy.sh
|
||||
#
|
||||
# Based on a template by BASH3 Boilerplate v2.0.0
|
||||
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
||||
# http://bash3boilerplate.sh/#authors
|
||||
|
||||
# Exit on error. Append || true if you expect an error.
|
||||
set -o errexit
|
||||
# Exit on error inside any functions or subshells.
|
||||
set -o errtrace
|
||||
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
|
||||
set -o nounset
|
||||
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
|
||||
set -o pipefail
|
||||
# Turn on traces, useful while debugging but commented out by default
|
||||
# set -o xtrace
|
||||
|
||||
# Set magic variables for current file, directory, os, etc.
|
||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||
__base="$(basename ${__file} .sh)"
|
||||
|
||||
ghpages_repo=${GHPAGES_REPO:-"kvz/bash3boilerplate"}
|
||||
ghpages_branch=${GHPAGES_BRANCH:-"gh-pages"}
|
||||
ghpages_url=${GHPAGES_URL:-"git@github.com:${ghpages_repo}.git"}
|
||||
|
||||
echo "--> Deploying to GitHub pages.."
|
||||
|
||||
${__dir}/inject.sh
|
||||
|
||||
if [ "${TRAVIS:-}" = "true" ]; then
|
||||
git config --global user.name 'lekevbot'
|
||||
git config --global user.email 'bot@kvz.io'
|
||||
fi
|
||||
|
||||
mkdir -p /tmp/deploy-${ghpages_repo}
|
||||
|
||||
# Custom steps
|
||||
rsync \
|
||||
--archive \
|
||||
--delete \
|
||||
--exclude=.git* \
|
||||
--exclude=node_modules \
|
||||
--exclude=lib \
|
||||
--checksum \
|
||||
--no-times \
|
||||
--no-group \
|
||||
--no-motd \
|
||||
--no-owner \
|
||||
./website/ /tmp/deploy-${ghpages_repo} > /dev/null
|
||||
|
||||
echo 'This branch is just a deploy target. Do not edit. You changes will be lost.' \
|
||||
|tee /tmp/deploy-${ghpages_repo}/README.md
|
||||
|
||||
(cd /tmp/deploy-${ghpages_repo} \
|
||||
&& git init && git checkout -B ${ghpages_branch} && git add --all . \
|
||||
&& git commit -nm "Update ${ghpages_repo} website by ${USER}" \
|
||||
&& (git remote add origin ${ghpages_url}|| true) \
|
||||
&& git push origin ${ghpages_branch}:refs/heads/${ghpages_branch} --force) > /dev/null
|
||||
|
||||
rm -rf /tmp/deploy-${ghpages_repo}
|
67
website/_bin/inject.sh
Executable file
67
website/_bin/inject.sh
Executable file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
# This file:
|
||||
#
|
||||
# - Injects markdown files into the ./website directory
|
||||
# - Changes them a little to make them more suitable for Jekyll building
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# ./inject.sh
|
||||
#
|
||||
# Based on a template by BASH3 Boilerplate v2.0.0
|
||||
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
||||
# http://bash3boilerplate.sh/#authors
|
||||
|
||||
# Exit on error. Append || true if you expect an error.
|
||||
set -o errexit
|
||||
# Exit on error inside any functions or subshells.
|
||||
set -o errtrace
|
||||
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
|
||||
set -o nounset
|
||||
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
|
||||
set -o pipefail
|
||||
# Turn on traces, useful while debugging but commented out by default
|
||||
# set -o xtrace
|
||||
|
||||
# Set magic variables for current file, directory, os, etc.
|
||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||
__base="$(basename ${__file} .sh)"
|
||||
|
||||
# Offer the main template for download as http://bash3boilerplate.sh/main.sh
|
||||
cp -v main.sh website/
|
||||
|
||||
for doc in "README" "FAQ" "CHANGELOG"; do
|
||||
targetName="$(echo "${doc}" | awk '{print tolower($0)}')"
|
||||
permalink="/${targetName}/"
|
||||
subtitle="$(tr '[:lower:]' '[:upper:]' <<< ${targetName:0:1})${targetName:1} | "
|
||||
redirectFrom="/${doc}.md/"
|
||||
backLink="\n\n<a href=\"/\">« Home</a>"
|
||||
if [ "${doc}" = "README" ]; then
|
||||
targetName="index"
|
||||
permalink="/"
|
||||
subtitle=""
|
||||
redirectFrom="nothing"
|
||||
backLink=""
|
||||
fi
|
||||
|
||||
cat <<EOF > website/${targetName}.md
|
||||
---
|
||||
layout: default
|
||||
permalink: ${permalink}
|
||||
redirect_from: ${redirectFrom}
|
||||
title: ${subtitle}BASH3 Boilerplate – Template for writing better Bash scripts
|
||||
warning: This page is generated by ${__base}.sh based on ${doc}.md, please don't edit ${targetName}.md directly.
|
||||
---
|
||||
EOF
|
||||
# http://stackoverflow.com/a/7104422/151666
|
||||
if grep '<!--more-->' ${doc}.md; then
|
||||
cat ${doc}.md |sed -n -e '/<!--more-->/,$p' | tail -n +2 >> website/${targetName}.md
|
||||
else
|
||||
cat ${doc}.md >> website/${targetName}.md
|
||||
fi
|
||||
|
||||
echo -e $backLink >> website/${targetName}.md
|
||||
|
||||
echo "written website/${targetName}.md"
|
||||
done
|
2
website/_config.yml
Normal file
2
website/_config.yml
Normal file
@ -0,0 +1,2 @@
|
||||
gems:
|
||||
- jekyll-redirect-from
|
80
website/_layouts/default.html
Normal file
80
website/_layouts/default.html
Normal file
@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{page.title}}</title>
|
||||
<meta name="keywords" content="bash, template, scripting, command-line">
|
||||
<meta name="description" content="BASH3 Boilerplate">
|
||||
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/public/style.css" media="screen" charset="utf-8">
|
||||
<link rel="stylesheet" href="/public/syntax.css" media="screen" charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div id="header-overlay"></div>
|
||||
<a href="/">
|
||||
<span id="logo"></span>
|
||||
</a>
|
||||
<div id="menu">
|
||||
<i class="material-icons">menu</i>
|
||||
<ul id="menu-items">
|
||||
</ul>
|
||||
</div>
|
||||
<span id="more">
|
||||
<i class="material-icons">expand_more</i>
|
||||
</span>
|
||||
</header>
|
||||
<section id="content">
|
||||
{% if page.url == "/" %}
|
||||
<div class="Social">
|
||||
<iframe src="http://ghbtns.com/github-btn.html?user=kvz&repo=bash3boilerplate&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="100" height="20"></iframe>
|
||||
<a href="https://travis-ci.org/kvz/bash3boilerplate"><img src="https://travis-ci.org/kvz/bash3boilerplate.svg" alt="Build Status"></a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{{content}}
|
||||
|
||||
{% if page.url == "/" %}
|
||||
<h2 id="activity-feed">On GitHub</h2>
|
||||
<p>
|
||||
BASH3 Boilerplate is a friendly group of folks further developing our
|
||||
re-usable templates as we go.
|
||||
We'd love to hear what you think <a href="https://github.com/kvz/bash3boilerplate">on GitHub</a>.
|
||||
Here's what's been going on recently.
|
||||
</p>
|
||||
<div class="on-the-githubs" data-event-source="repos/kvz/bash3boilerplate">Loading...</div>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script src="//kvz.github.io/on-the-githubs/js/jquery.on-the-githubs.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$('.on-the-githubs').onthegithubs();
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
<div class="Social">
|
||||
<iframe src="http://ghbtns.com/github-btn.html?user=kvz&repo=bash3boilerplate&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="100" height="20"></iframe>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<small>
|
||||
<hr />
|
||||
Website design based on
|
||||
the wonderful <a href="http://apex.run">apex.run</a>
|
||||
with <a href="https://twitter.com/tjholowaychuk/status/744909762865696769">the author's consent</a>.
|
||||
</small>
|
||||
</p>
|
||||
</section>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/languages/bash.min.js"></script>
|
||||
<script src="/public/app.js"></script>
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-63083-13', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
55
website/public/app.js
Normal file
55
website/public/app.js
Normal file
@ -0,0 +1,55 @@
|
||||
// Backgrounds.
|
||||
// var backgrounds = [1,2,3,4,5,6]
|
||||
var backgrounds = [1]
|
||||
|
||||
// Highlighting.
|
||||
hljs.initHighlighting()
|
||||
|
||||
// Storage.
|
||||
var store = window.sessionStorage
|
||||
|
||||
// Background.
|
||||
var background = store.getItem('background')
|
||||
|
||||
if (!background) {
|
||||
var i = Math.random() * backgrounds.length | 0
|
||||
background = backgrounds[i]
|
||||
console.log('setting background to %s', background)
|
||||
store.setItem('background', background)
|
||||
}
|
||||
|
||||
// Body class for background.
|
||||
var el = document.getElementById('header-overlay')
|
||||
el.style.backgroundImage = 'url(/public/images/' + background + '.jpg)'
|
||||
|
||||
// Attach class to #menu element depending on page offset.
|
||||
document.addEventListener('DOMContentLoaded', chooseMenuColor)
|
||||
window.onscroll = chooseMenuColor
|
||||
|
||||
function chooseMenuColor() {
|
||||
var menuElement = document.getElementById('menu')
|
||||
var menuTopOffset = 45
|
||||
Math.floor(window.innerHeight * .20) < window.pageYOffset + menuTopOffset ?
|
||||
menuElement.classList.remove('over-header') :
|
||||
menuElement.classList.add('over-header')
|
||||
}
|
||||
|
||||
|
||||
function $get(selector) { return document.querySelector(selector) }
|
||||
function $all(selector) {
|
||||
return Array.prototype.slice.call(document.querySelectorAll(selector))
|
||||
}
|
||||
|
||||
var container = $get('#menu-items')
|
||||
|
||||
// if (location.pathname !== '/') {
|
||||
// var li = document.createElement('li');
|
||||
// li.innerHTML = '<a href="/">« Home</a>';
|
||||
// container.appendChild(li);
|
||||
// }
|
||||
|
||||
$all('#content h2').forEach(function(el) {
|
||||
var li = document.createElement('li');
|
||||
li.innerHTML = '<a href="#' + el.id + '">' + el.innerHTML + '</a>';
|
||||
container.appendChild(li);
|
||||
})
|
BIN
website/public/images/1.jpg
Executable file
BIN
website/public/images/1.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 114 KiB |
BIN
website/public/images/logo.png
Normal file
BIN
website/public/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
BIN
website/public/images/logo.pxm
Normal file
BIN
website/public/images/logo.pxm
Normal file
Binary file not shown.
344
website/public/style.css
Normal file
344
website/public/style.css
Normal file
@ -0,0 +1,344 @@
|
||||
|
||||
body {
|
||||
font: 16px/1.625 "Open Sans", "Helvetica Neue", "Helvetica", Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
text-rendering: optimizeLegibility;
|
||||
color: #656a71;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#header-overlay {
|
||||
background: #131313 50% 100% no-repeat;
|
||||
background-size: cover;
|
||||
height: 20vh;
|
||||
width: 100%;
|
||||
opacity: 0;
|
||||
-webkit-animation-name: overlay;
|
||||
animation-name: overlay;
|
||||
-webkit-animation-duration: 5s;
|
||||
animation-duration: 5s;
|
||||
-webkit-animation-delay: 1s;
|
||||
animation-delay: 1s;
|
||||
-webkit-animation-fill-mode: forwards;
|
||||
animation-fill-mode: forwards;
|
||||
}
|
||||
|
||||
@-webkit-keyframes overlay {
|
||||
0% {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: .25;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes overlay {
|
||||
0% {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: .25;
|
||||
}
|
||||
}
|
||||
|
||||
body.background-1 #header-overlay {
|
||||
background-image: url(images/1.jpg);
|
||||
}
|
||||
|
||||
body.background-4 #header-overlay {
|
||||
background-image: url(images/4.jpg);
|
||||
}
|
||||
|
||||
#logo {
|
||||
display: block;
|
||||
background: url(images/logo.png) center;
|
||||
background-size: contain;
|
||||
width: 200px;
|
||||
height: 120px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin-left: -100px;
|
||||
margin-top: -60px;
|
||||
-webkit-animation-name: logo;
|
||||
animation-name: logo;
|
||||
-webkit-animation-duration: 2s;
|
||||
animation-duration: 2s;
|
||||
-webkit-animation-fill-mode: forwards;
|
||||
animation-fill-mode: forwards;
|
||||
}
|
||||
|
||||
@-webkit-keyframes logo {
|
||||
0% {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes logo {
|
||||
0% {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
#more {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
left: 50%;
|
||||
margin-left: -6px;
|
||||
color: white;
|
||||
opacity: 0;
|
||||
-webkit-animation-name: move;
|
||||
animation-name: move;
|
||||
-webkit-animation-duration: 3s;
|
||||
animation-duration: 3s;
|
||||
-webkit-animation-delay: 3s;
|
||||
animation-delay: 3s;
|
||||
-webkit-animation-fill-mode: forwards;
|
||||
animation-fill-mode: forwards;
|
||||
-webkit-animation-timing-function: cubic-bezier(0.86, 0, 0.07, 1);
|
||||
animation-timing-function: cubic-bezier(0.86, 0, 0.07, 1);
|
||||
}
|
||||
|
||||
@-webkit-keyframes move {
|
||||
0% {
|
||||
opacity: 0;
|
||||
bottom: 300px;
|
||||
}
|
||||
|
||||
50% {
|
||||
opacity: 1;
|
||||
bottom: 10px;
|
||||
}
|
||||
|
||||
90% {
|
||||
opacity: 1;
|
||||
bottom: 10px;
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 0;
|
||||
bottom: -10px;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes move {
|
||||
0% {
|
||||
opacity: 0;
|
||||
bottom: 300px;
|
||||
}
|
||||
|
||||
50% {
|
||||
opacity: 1;
|
||||
bottom: 10px;
|
||||
}
|
||||
|
||||
90% {
|
||||
opacity: 1;
|
||||
bottom: 10px;
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 0;
|
||||
bottom: -10px;
|
||||
}
|
||||
}
|
||||
|
||||
#content {
|
||||
padding: 100px 0;
|
||||
max-width: 650px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: fixed;
|
||||
top: 35px;
|
||||
right: 35px;
|
||||
cursor: pointer;
|
||||
background: transparent;
|
||||
color: black;
|
||||
padding: 7px;
|
||||
border-radius: 1px;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
#menu.over-header {
|
||||
color: white;
|
||||
}
|
||||
|
||||
#menu i {
|
||||
font-size: 19px;
|
||||
}
|
||||
|
||||
#menu:hover #menu-items {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
#menu-items {
|
||||
line-height: 1.7;
|
||||
opacity: 0;
|
||||
position: fixed;
|
||||
visibility: hidden;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
font-size: 12px;
|
||||
background: white;
|
||||
color: #121212;
|
||||
top: 67px;
|
||||
right: 35px;
|
||||
border-radius: 1px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#menu-items li a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#menu-items li {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#menu-items li a {
|
||||
color: #4C4C4C;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
font-weight: 600;
|
||||
margin-bottom: 0px;
|
||||
color: #3b444f;
|
||||
}
|
||||
|
||||
h1 { font-size: 2em; /* 2*16 = 32 */ }
|
||||
h2 { font-size: 1.5em; /* 1.5*16 = 24 */ }
|
||||
h3 { font-size: 1.17em; /* 1.17*16 = 18.72 */ }
|
||||
h4 { font-size: 1em; /* 1*16 = 16 */ }
|
||||
h5 { font-size: 0.83em; /* 0.83*16 = 13.28 */ }
|
||||
h6 { font-size: 0.75em; /* 0.75*16 = 12 */ }
|
||||
|
||||
h1 {
|
||||
/*margin-top: 75px;*/
|
||||
}
|
||||
|
||||
h1::before {
|
||||
/*display: block;
|
||||
content: ' ';
|
||||
border-top: 1px dotted #eee;
|
||||
width: 35%;
|
||||
margin: 0 auto 75px auto;*/
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
p > code,
|
||||
li > code {
|
||||
border: 1px solid #eee;
|
||||
padding: 2px 10px;
|
||||
border-radius: 3px;
|
||||
font-size: .75rem;
|
||||
color: #555;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
header {
|
||||
background: #131313;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #55A1E1;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
hr {
|
||||
margin: 1px;
|
||||
border: none;
|
||||
height: 1px;
|
||||
/* Set the hr color */
|
||||
color: gainsboro; /* old IE */
|
||||
background-color: gainsboro; /* Modern Browsers */
|
||||
}
|
||||
|
||||
.Social {
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
}
|
||||
.Social > * {
|
||||
display: inline;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.on-the-githubs {
|
||||
-webkit-margin-before: 1em;
|
||||
-webkit-margin-after: 1em;
|
||||
}
|
||||
.on-the-githubs:after {
|
||||
content: '';
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
.on-the-githubs > li {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
/*height: 26px;*/
|
||||
position: relative;
|
||||
border-bottom: 1px solid rgba(gainsboro, 0.3);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.on-the-githubs > li:after {
|
||||
content: '';
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.on-the-githubs > li p {
|
||||
font-size: 15px;
|
||||
line-height: 16px;
|
||||
margin: 0 2px;
|
||||
padding: 0;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
overflow: hidden;
|
||||
max-width: 80%;
|
||||
}
|
||||
.on-the-githubs > li abbr {
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
float: left;
|
||||
text-align: right;
|
||||
/*display: none*/
|
||||
}
|
||||
.on-the-githubs > li a {
|
||||
font-weight: normal;
|
||||
/*text-decoration: underline;*/
|
||||
}
|
||||
.on-the-githubs > li img {
|
||||
float: left;
|
||||
margin: 0 2px 0 0;
|
||||
border-radius: 10px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
104
website/public/syntax.css
Normal file
104
website/public/syntax.css
Normal file
@ -0,0 +1,104 @@
|
||||
|
||||
pre {
|
||||
border-top-color: #ddd;
|
||||
border-radius: 3px;
|
||||
font-size: .75rem;
|
||||
overflow-x: auto;
|
||||
line-height: 1.3;
|
||||
padding: 1.5rem;
|
||||
background: #fff;
|
||||
color: #333;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #eee;
|
||||
border-bottom-color: #ddd;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
XCode style (c) Angel Garcia <angelgarcia.mail@gmail.com>
|
||||
|
||||
*/
|
||||
|
||||
.hljs {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: #006a00;
|
||||
}
|
||||
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag,
|
||||
.hljs-literal {
|
||||
color: #aa0d91;
|
||||
}
|
||||
|
||||
.hljs-name {
|
||||
color: #008;
|
||||
}
|
||||
|
||||
.hljs-variable,
|
||||
.hljs-template-variable {
|
||||
color: #660;
|
||||
}
|
||||
|
||||
.hljs-string {
|
||||
color: #c41a16;
|
||||
}
|
||||
|
||||
.hljs-regexp,
|
||||
.hljs-link {
|
||||
color: #080;
|
||||
}
|
||||
|
||||
.hljs-title,
|
||||
.hljs-tag,
|
||||
.hljs-symbol,
|
||||
.hljs-bullet,
|
||||
.hljs-number,
|
||||
.hljs-meta {
|
||||
color: #1c00cf;
|
||||
}
|
||||
|
||||
.hljs-section,
|
||||
.hljs-class .hljs-title,
|
||||
.hljs-type,
|
||||
.hljs-attr,
|
||||
.hljs-built_in,
|
||||
.hljs-builtin-name,
|
||||
.hljs-params {
|
||||
color: #5c2699;
|
||||
}
|
||||
|
||||
.hljs-attribute,
|
||||
.hljs-subst {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.hljs-formula {
|
||||
background-color: #eee;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-addition {
|
||||
background-color: #baeeba;
|
||||
}
|
||||
|
||||
.hljs-deletion {
|
||||
background-color: #ffc8bd;
|
||||
}
|
||||
|
||||
.hljs-selector-id,
|
||||
.hljs-selector-class {
|
||||
color: #9b703f;
|
||||
}
|
||||
|
||||
.hljs-doctag,
|
||||
.hljs-strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
Reference in New Issue
Block a user