aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorPetr <30545094+pasabanov@users.noreply.github.com>2024-07-18 18:32:49 +0300
committerGitHub <noreply@github.com>2024-07-18 17:32:49 +0200
commitc35a5ca087bdace26d454dd73337a63f04f23e20 (patch)
treee92f4bf6e1524c97f2f6c757fa33cbbe1bd3e428 /packages
parentca429669ac5b8f0101d0933ff20ee5f152c518b1 (diff)
shell: reformatted, fixed inspections, typos (#2506)
Reformatted shell scripts according to [ShellCheck](https://github.com/koalaman/shellcheck/). I. Most common changes: 1. https://github.com/koalaman/shellcheck/wiki/SC2086 `$var` → `"$var"` Note: this isn't always necessary and I've been careful not to substitute where it wasn't necessary in meaning. 2. https://github.com/koalaman/shellcheck/wiki/SC2006 `` `command` `` → `$(command)` 3. https://github.com/koalaman/shellcheck/wiki/SC2004 `$(( $a + $b ))` → `$(( a + b ))` 4. https://github.com/koalaman/shellcheck/wiki/SC2164 `cd "$dir"` → `cd "$dir" || exit 1` 5. https://github.com/koalaman/shellcheck/wiki/SC2166 `[ check1 -o check2 ]` → `[ check1 ] || [ check2 ]` 6. https://github.com/koalaman/shellcheck/wiki/SC2002 `cat "${file}" | wc -c` → `< "${file}" wc -c` Note: this looks a bit uglier but works faster. II. Some special changes: 1. In file `utils/common.sh`: https://github.com/koalaman/shellcheck/wiki/SC2112 This script is interpreted by `sh`, not by `bash`, but uses the keyword `function`. So I replaced `#!/usr/bin/env sh` to `#!/usr/bin/env bash`. 2. After that I thought of replacing all shebangs to `#!/usr/bin/env bash` for consistency and cross-platform compatibility, especially since most of the files already use bash. 3. But in cases when it was `#!/bin/sh -e` or `#!/bin/bash -eu` another problem appears: https://github.com/koalaman/shellcheck/wiki/SC2096 So I decided to make all shebangs look uniform: ``` #!/usr/bin/env bash set -e (or set -eu) (if needed) ``` 4. In file `tests/ossfuzz.sh`: https://github.com/koalaman/shellcheck/wiki/SC2162 `read i` → `read -r i` Note: I think that there is no need in special treatment for backslashes, but I could be wrong. 5. In file `tests/do.sh.in`: https://github.com/koalaman/shellcheck/wiki/SC2035 `ls *.*cap*` → `ls -- *.*cap*` 6. In file `utils/verify_dist_tarball.sh`: https://github.com/koalaman/shellcheck/wiki/SC2268 `[ "x${TARBALL}" = x ]` → `[ -z "${TARBALL}" ]` 7. In file `utils/check_symbols.sh`: https://github.com/koalaman/shellcheck/wiki/SC2221 `'[ndpi_utils.o]'|'[ndpi_memory.o]'|'[roaring.o]')` → `'[ndpi_utils.o]'|'[ndpi_memory.o]')` 8. In file `autogen.sh`: https://github.com/koalaman/shellcheck/wiki/SC2145 `echo "./configure $@"` → `echo "./configure $*"` https://github.com/koalaman/shellcheck/wiki/SC2068 `./configure $@` → `./configure "$@"` III. `LIST6_MERGED` and `LIST_MERGED6` There were typos with this variables in files `utils/aws_ip_addresses_download.sh`, `utils/aws_ip_addresses_download.sh` and `utils/microsoft_ip_addresses_download.sh` where variable `LIST6_MERGED` was defined, but `LIST_MERGED6` was removed by `rm`. I changed all `LIST_MERGED6` to `LIST6_MERGED`. Not all changes are absolutely necessary, but some may save you from future bugs.
Diffstat (limited to 'packages')
-rwxr-xr-xpackages/ubuntu/debian/postinst3
-rw-r--r--packages/ubuntu/debian/postrm3
-rw-r--r--packages/ubuntu/debian/preinst5
-rwxr-xr-xpackages/ubuntu/debian/prerm3
-rwxr-xr-xpackages/version.sh10
5 files changed, 12 insertions, 12 deletions
diff --git a/packages/ubuntu/debian/postinst b/packages/ubuntu/debian/postinst
index 202f79aa8..fe7f3995c 100755
--- a/packages/ubuntu/debian/postinst
+++ b/packages/ubuntu/debian/postinst
@@ -1,4 +1,5 @@
-#!/bin/sh -e
+#!/usr/bin/env sh
+set -e
case "$1" in
configure)
diff --git a/packages/ubuntu/debian/postrm b/packages/ubuntu/debian/postrm
index 3347514a1..7a4b65e62 100644
--- a/packages/ubuntu/debian/postrm
+++ b/packages/ubuntu/debian/postrm
@@ -1,5 +1,4 @@
-#!/bin/sh -e
-
+#!/usr/bin/env sh
set -e
/sbin/ldconfig
diff --git a/packages/ubuntu/debian/preinst b/packages/ubuntu/debian/preinst
index 89699e385..3dd495a35 100644
--- a/packages/ubuntu/debian/preinst
+++ b/packages/ubuntu/debian/preinst
@@ -1,10 +1,9 @@
-#! /bin/sh
+#!/usr/bin/env sh
+set -e
# preinst script
#
# see: dh_installdeb(1)
-set -e
-
# summary of how this script can be called:
# * <new-preinst> `install'
# * <new-preinst> `install' <old-version>
diff --git a/packages/ubuntu/debian/prerm b/packages/ubuntu/debian/prerm
index 8f91692e0..20a3b0e2a 100755
--- a/packages/ubuntu/debian/prerm
+++ b/packages/ubuntu/debian/prerm
@@ -1,4 +1,5 @@
-#!/bin/sh -e
+#!/usr/bin/env sh
+set -e
case "$1" in
upgrade)
diff --git a/packages/version.sh b/packages/version.sh
index 1563c7787..957795573 100755
--- a/packages/version.sh
+++ b/packages/version.sh
@@ -1,9 +1,9 @@
-#!/bin/bash
+#!/usr/bin/env sh
-SCRIPTPATH="$(cd "$(dirname "$0")"; pwd -P)"
-RELEASE="$(cd ${SCRIPTPATH}; cat ../configure.ac|grep C_INIT|cut -c 20-|rev|cut -c 3-|rev)"
-MAJOR_RELEASE="$(cd ${SCRIPTPATH}; cat ../configure.ac|grep C_INIT|cut -c 20-|rev|cut -c 3-|rev|cut -d. -f1)"
-REVISION="$(cd ${SCRIPTPATH}; git rev-list --all |wc -l | tr -d '[[:space:]]')"
+SCRIPTPATH="$(cd "$(dirname "$0")" || exit 1; pwd -P)"
+RELEASE="$(cd "${SCRIPTPATH}" || exit 1; < ../configure.ac grep C_INIT | cut -c 20- | rev | cut -c 3- | rev)"
+MAJOR_RELEASE="$(cd "${SCRIPTPATH}" || exit 1; < ../configure.ac grep C_INIT | cut -c 20- | rev | cut -c 3- | rev | cut -d. -f1)"
+REVISION="$(cd "${SCRIPTPATH}" || exit 1; git rev-list --all | wc -l | tr -d '[[:space:]]')"
get_release() {
echo "${RELEASE}"