Alpine: Executables

Various helper executables for providing standard output and simplifying common tasks.

Output

bf-debug

Echoes "$1: $2" to stdout in grey with prefix (see bf-e) - but only if environment variable BF_DEBUG is set to "1".

Arguments

  1. Text to output

  2. [Optional] Script / executable name

Usage

$ bf-debug "Hi"
[bf] 2021-09-19 18:00:00 | Hi # (in grey)

$ bf-debug "Hi" "alpine-s6/docs"
[bf] 2021-09-19 18:00:00 | alpine-s6/docs: Hi # (in grey)

bf-done

Echoes 'done.' to stdout in green with prefix (see bf-ok).

Arguments

  1. [Optional] Script / executable name

Usage

bf-e

Echoes $3 to stdout in colour $2 with prefix: "[$1] %Y-%m-%d %H:%M:%S".

Arguments

  1. Namespace (default value for other output helper executables is 'bf')

  2. ANSI colour code (see e.g. here)

  3. Text to output

  4. [Optional] Script / executable name

Usage

bf-echo

Echoes "$1: $2" to stdout in default colour with prefix (see bf-e).

Arguments

  1. Text to output

  2. [Optional] Script / executable name

Usage

bf-error

Echoes "$1: $2" to stdout in red with prefix (see bf-e), and returns 1. This will end execution of the calling script if you use, e.g. set -euo pipefail at the top of your scripts (recommended).

Arguments

  1. Text to output

  2. [Optional] Script / executable name

Usage

bf-notok

Like bf-error echoes "$1: $2" to stdout in red with prefix, but doesn't end execution of calling script.

Arguments

  1. Text to output

  2. [Optional] Script / executable name

Usage

bf-ok

Echoes "$1: $2" to stdout in green with prefix.

Arguments

  1. Text to output

  2. [Optional] Script / executable name

Usage

Helpers

bf-adduser

Create user with id $2, group with id $3, both with name $1, and no password.

Arguments

  1. User and group name

  2. [Optional] User ID (default: 1000)

  3. [Optional] Group ID (default: UID)

Usage

bf-ch

Changes ownership and/or permissions of file / directory glob.

Arguments

Required (one or both):

  • -o X use chown to set ownership to "X"

  • -m Y use chmod to set permissions to "Y"

Optional:

  • -t f|d apply only to files ("f") or directories ("d")

  • -rif -t is not specified, applies action recursively to all files and directories

Usage

bf-clear

Clears contents of /tmp and apk cache.

Usage

bf-esh

Calls esh in a consistent manner.

Arguments

  1. Path to input (template) file

  2. Path to output (generated) file

Usage

bf-image

Display name and version of the current image, and a link to the GitHub repository.

Usage

bf-install

Run install /tmp/install and then perform cleanup (see bf-clear). Within the ecosystem this would normally be used in a Dockerfile

Usage

This is the basic structure of Dockerfiles based on the Alpine S6 image, copying overlay and then running the standard installation.

bf-rmrf

Runs rm -rf $1 safely: doing nothing if $1 is empty. This is handy if the path you are deleting is contained in a variable (it effectively stops rm -rf /!).

Arguments

  1. Folder path / file glob to delete.

Usage

bf-rnd

Generates a string of random letters and numbers of length $1.

Arguments

  1. [Optional] Number of characters to return

Usage

bf-test-url

Uses wget to test URL $1.

Arguments

  1. URL to test

Usage

bf-tz

Sets the container's timezone to $1. (Installs tzdata package, changes timezone and then removes tzdata).

Arguments

  1. Valid timezone (e.g. Europe/London)

Usage

Note the change in time on line 12.

Last updated