Skip to content

Latest commit

 

History

History
103 lines (72 loc) · 2.7 KB

CONTRIBUTING.adoc

File metadata and controls

103 lines (72 loc) · 2.7 KB

Care and feeding of your initramfs generator

1. Bash v. POSIX

Never use POSIX syntax if Bash offers a construct of its own, even if the two are effectively identical. This means always using double braces over the inferior [ and test.

2. Variable usage and naming conventions

There are three classifications of variables in mkinitcpio.

2.1. Local variables

All lower case, and scoped within functions. Use freely, as they are well contained. Unless you are introducing a new option, this is what you want to use.

local foo="$1"

2.2. Global variables

These are known to mkinitcpio internally, but are global in scope. They carry runtime configuration and data collected during the image generation process. These are always lower case, but carry a leading underscore to denote that they are global. It is helpful to prefix these variables instead with a f or d if they refer to a file or directory, respectively.

define -i _optcolor=1
_d_hookdir='/etc/foo.d'
_f_config='/etc/foo.conf'

2.3. "API" variables

Also global in scope, but exist "outside" of mkinitcpio - either drawn in from the configuration file, or "exported" to the install hooks. These are always all upper case. When introducing new variables, extreme care must be taken to pick names that will not conflict with the environment inherited by mkinitcpio.

3. Function naming

Use all lower case with underscores where appropriate, for easy readability. Adhere to POSIX variable naming requirements for the contents of the name, that is: only alphanumerics, underscores, and the identifier must not start with a number.

4. Quoting

Overquoting is preferred to underquoting. Prefer single quotes to double quotes if possible. Remember to quote, quote and quote some more.

When quoting variables, use brace expansion if the variable is part of a larger string.

a='/test'
b="/some/path${a}"
c="$b"

5. Functions and block statements

Always use "top-right, lower left" for blocks of code and functions.

do_glob() {
    local g fn="$1"; shift

    for g in "$@"; do
        "$fn" "$g"
    done
}

6. Bash Automated Testing System

mkinitcpio uses bats (Bash Automated Testing System). The tests are found in the test directory.

Each newly added function should also have an accompanying test.

7. ShellCheck

All shell scripts must be validated with ShellCheck. Use make shellcheck and ensure it successfully passes.

8. EditorConfig

A .editorconfig file is provided to ensure consistency (indenting, newlines, trailing whitespace) between text editors.