Pull request: all: imp scripts

Merge in DNS/adguard-home from imp-sh to master

Squashed commit of the following:

commit 477832e11eca2ef7ac0071b5da938dacb2ed617d
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 20:24:34 2021 +0300

    scripts: rm dbg

commit dbb4b8c783f607781b980dcd57d78085c9022e72
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 20:21:20 2021 +0300

    all: imp code, compat, docs

commit e6e4375d67ad1c213efb04411e3ba0bc6293f936
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 19:33:48 2021 +0300

    all: imp scripts
This commit is contained in:
Ainar Garipov
2021-05-19 20:31:20 +03:00
parent b3d28408cd
commit 6f7fd33afd
17 changed files with 473 additions and 321 deletions

View File

@@ -1,9 +1,9 @@
# AdGuard Home Developer Guidelines
As of **March 2021**, following this document is obligatory for all new code.
Some of the rules aren't enforced as thoroughly or remain broken in old code,
but this is still the place to find out about what we **want** our code to look
like and how to improve it.
Following this document is obligatory for all new code. Some of the rules
aren't enforced as thoroughly or remain broken in old code, but this is still
the place to find out about what we **want** our code to look like and how to
improve it.
The rules are mostly sorted in the alphabetical order.
@@ -21,6 +21,7 @@ The rules are mostly sorted in the alphabetical order.
* [Recommended Reading](#recommended-reading)
* [Markdown](#markdown)
* [Shell Scripting](#shell-scripting)
* [Shell Conditionals](#shell-cond)
* [Text, Including Comments](#text-including-comments)
* [YAML](#yaml)
@@ -315,6 +316,26 @@ on GitHub and most other Markdown renderers. -->
* Avoid spaces between patterns of the same `case` condition.
* `export` and `readonly` should be used separately from variable assignment,
because otherwise failures in command substitutions won't stop the script.
That is, do this:
```sh
X="$( echo 42 )"
export X
```
And **not** this:
```sh
# Bad!
export X="$( echo 42 )"
```
* If a binary value is needed, use `0` for `false`, and `1` for `true`.
* Mark every variable that shouldn't change later as `readonly`.
* Prefer `'raw strings'` to `"double quoted strings"` whenever possible.
* Put spaces within `$( cmd )`, `$(( expr ))`, and `{ cmd; }`.
@@ -330,8 +351,6 @@ on GitHub and most other Markdown renderers. -->
* UPPERCASE names for external exported variables, lowercase for local,
unexported ones.
* Use `readonly` liberally.
* Use `set -e -f -u` and also `set -x` in verbose mode.
* Use the `"$var"` form instead of the `$var` form, unless word splitting is
@@ -355,14 +374,23 @@ on GitHub and most other Markdown renderers. -->
dir="${TOP_DIR}"/sub
```
* When using `test` (aka `[`), spell compound conditions with `&&`, `||`, and
`!` **outside** of `test` instead of `-a`, `-o`, and `!` inside of `test`
correspondingly. The latter ones are pretty much deprecated in POSIX.
Also, prefer `!= ''` form instead of `-n` to check if string is empty.
### <a id="shell-cond" href="#shell-cond">Shell Conditionals</a>
Guidelines and agreements for using command `test`, also known as `[`:
* Prefer the `!= ''` form instead of using `-n` to check if string is empty.
* Spell compound conditions with `&&`, `||`, and `!` **outside** of `test`
instead of `-a`, `-o`, and `!` **inside** of `test` correspondingly. The
latter ones are pretty much deprecated in POSIX.
See also: “[Problems With the `test` Builtin: What Does `-a` Mean?][test]”.
* Use `=` for strings and `-eq` for numbers to catch typing errors.
[test]: https://www.oilshell.org/blog/2017/08/31.html
See also: “[Problems With the `test` Builtin: What Does `-a` Mean?]”.
[Problems With the `test` Builtin: What Does `-a` Mean?]: https://www.oilshell.org/blog/2017/08/31.html
## <a id="text-including-comments" href="#text-including-comments">Text, Including Comments</a>
@@ -400,6 +428,8 @@ on GitHub and most other Markdown renderers. -->
// TODO(usr1, usr2): Fix the frobulation issue.
```
## <a id="yaml" href="#yaml">YAML</a>
* **TODO(a.garipov):** Define naming conventions for schema names in our