From 0247a2da4471cf346125b45c5af5124b26909c7a Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Fri, 9 Apr 2021 15:07:18 +0300 Subject: [PATCH] Pull request: all: imp shell code Merge in DNS/adguard-home from imp-sh to master Squashed commit of the following: commit 212f03f3d6e0824428c28ffd79cac8f5ea271d9c Author: Ainar Garipov Date: Fri Apr 9 14:51:59 2021 +0300 all: imp shell code --- HACKING.md | 11 +++++++++++ bamboo-specs/release.yaml | 2 +- scripts/make/build-docker.sh | 2 +- scripts/make/build-release.sh | 19 +++++++------------ scripts/make/go-build.sh | 3 +-- scripts/make/go-lint.sh | 3 +-- scripts/make/go-test.sh | 3 +-- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/HACKING.md b/HACKING.md index 07308745..c0c35abd 100644 --- a/HACKING.md +++ b/HACKING.md @@ -289,6 +289,9 @@ on GitHub and most other Markdown renderers. --> * Put utility flags in the ASCII order and **don't** group them together. For example, `ls -1 -A -q`. + * Script code lines should not be longer than one hundred (**100**) columns. + For comments, see the text section below. + * `snake_case`, not `camelCase` for variables. `kebab-case` for filenames. * UPPERCASE names for external exported variables, lowercase for local, @@ -319,6 +322,14 @@ 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. + + 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 + ## Text, Including Comments * End sentences with appropriate punctuation. diff --git a/bamboo-specs/release.yaml b/bamboo-specs/release.yaml index 675bde40..85f09578 100644 --- a/bamboo-specs/release.yaml +++ b/bamboo-specs/release.yaml @@ -200,7 +200,7 @@ set -e -f -u -x export CHANNEL="${bamboo.channel}" - if [ "$CHANNEL" != 'release' -a "${CHANNEL}" != 'beta' ] + if [ "$CHANNEL" != 'release' ] && [ "${CHANNEL}" != 'beta' ] then echo "don't publish to Github Releases for this channel" diff --git a/scripts/make/build-docker.sh b/scripts/make/build-docker.sh index 92adb4fb..19efcbed 100644 --- a/scripts/make/build-docker.sh +++ b/scripts/make/build-docker.sh @@ -18,7 +18,7 @@ readonly channel="$CHANNEL" readonly commit="$COMMIT" readonly dist_dir="$DIST_DIR" -if [ "${VERSION:-}" = 'v0.0.0' -o "${VERSION:-}" = '' ] +if [ "${VERSION:-}" = 'v0.0.0' ] || [ "${VERSION:-}" = '' ] then readonly version="$(sh ./scripts/make/version.sh)" else diff --git a/scripts/make/build-release.sh b/scripts/make/build-release.sh index 104385b6..8454ff0c 100644 --- a/scripts/make/build-release.sh +++ b/scripts/make/build-release.sh @@ -48,7 +48,7 @@ readonly channel="$CHANNEL" # Check VERSION against the default value from the Makefile. If it is # that, use the version calculation script. -if [ "${VERSION:-}" = 'v0.0.0' -o "${VERSION:-}" = '' ] +if [ "${VERSION:-}" = 'v0.0.0' ] || [ "${VERSION:-}" = '' ] then readonly version="$(sh ./scripts/make/version.sh)" else @@ -103,8 +103,8 @@ log "checking tools" # Make sure we fail gracefully if one of the tools we need is missing. for tool in gpg gzip sed sha256sum snapcraft tar zip do - which "$tool" >/dev/null ||\ - { log "pieces don't fit, '$tool' not found"; exit 1; } + which "$tool" >/dev/null\ + || { log "pieces don't fit, '$tool' not found"; exit 1; } done # Data section. Arrange data into space-separated tables for read -r to @@ -219,7 +219,7 @@ build() { log "$build_archive" - if [ "$build_snap" = '0' -o "$snap_enabled" = '0' ] + if [ "$build_snap" = '0' ] || [ "$snap_enabled" = '0' ] then return fi @@ -262,8 +262,7 @@ build() { # output, but only show it when snapcraft actually fails. set +e build_snapcraft_output="$( - snapcraft pack "$build_snap_dir"\ - --output "$build_snap_output" 2>&1 + snapcraft pack "$build_snap_dir" --output "$build_snap_output" 2>&1 )" build_snapcraft_exit_code="$?" set -e @@ -334,10 +333,7 @@ log "calculating checksums" ( cd "./${dist}" - files="$( \ - find . ! -name . -prune\ - \( -name '*.tar.gz' -o -name '*.zip' \) - )" + files="$( find . ! -name . -prune \( -name '*.tar.gz' -o -name '*.zip' \) )" # Don't use quotes to get word splitting. sha256sum $files > ./checksums.txt @@ -385,8 +381,7 @@ echo " # Same as with checksums above, don't use ls, because files matching one # of the patterns may be absent. readonly ar_files="$( \ - find "./${dist}/" ! -name "${dist}" -prune\ - \( -name '*.tar.gz' -o -name '*.zip' \) + find "./${dist}/" ! -name "${dist}" -prune \( -name '*.tar.gz' -o -name '*.zip' \) )" readonly ar_files_len="$(echo "$ar_files" | wc -l)" diff --git a/scripts/make/go-build.sh b/scripts/make/go-build.sh index aad1ab8a..610e9ab0 100644 --- a/scripts/make/go-build.sh +++ b/scripts/make/go-build.sh @@ -106,8 +106,7 @@ fi export CGO_ENABLED="$cgo_enabled" export GO111MODULE='on' -readonly build_flags="${BUILD_FLAGS:-$race_flags $out_flags $par_flags\ - $v_flags $x_flags}" +readonly build_flags="${BUILD_FLAGS:-$race_flags $out_flags $par_flags $v_flags $x_flags}" # Don't use quotes with flag variables to get word splitting. "$go" generate $v_flags $x_flags ./main.go diff --git a/scripts/make/go-lint.sh b/scripts/make/go-lint.sh index 661edbe8..4ba752aa 100644 --- a/scripts/make/go-lint.sh +++ b/scripts/make/go-lint.sh @@ -157,8 +157,7 @@ ineffassign ./... unparam ./... -git ls-files -- '*.go' '*.md' '*.mod' '*.sh' '*.yaml' '*.yml'\ - 'Makefile'\ +git ls-files -- '*.go' '*.md' '*.mod' '*.sh' '*.yaml' '*.yml' 'Makefile'\ | xargs misspell --error looppointer ./... diff --git a/scripts/make/go-test.sh b/scripts/make/go-test.sh index 0654157e..68368aa0 100644 --- a/scripts/make/go-test.sh +++ b/scripts/make/go-test.sh @@ -39,5 +39,4 @@ readonly count_flags='--count 1' # Don't use quotes with flag variables because we want an empty space if # those aren't set. -"$go" test $count_flags $cover_flags $race_flags $timeout_flags\ - $x_flags $v_flags ./... +"$go" test $count_flags $cover_flags $race_flags $timeout_flags $x_flags $v_flags ./...