mirror of
https://github.com/vel21ripn/nDPI.git
synced 2026-05-05 19:15:12 +00:00
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.
64 lines
2.1 KiB
Bash
Executable file
64 lines
2.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(realpath "$(dirname "${0}")")"
|
|
NDPI_LIB="${1:-${SCRIPT_DIR}/../src/lib/libndpi.a}"
|
|
|
|
if [ ! -r "${NDPI_LIB}" ]; then
|
|
printf '%s\n' "${0}: nDPI static library '$(realpath "${NDPI_LIB}")' not found."
|
|
exit 1
|
|
fi
|
|
|
|
FAIL_COUNT=0
|
|
CURRENT_OBJECT=''
|
|
for line in $(nm -P -u "${NDPI_LIB}"); do
|
|
OBJECT="$(printf '%s' "${line}" | grep -E "^${NDPI_LIB}\[.*\.o\]:" | grep -oE "\[.*\.o\]" || true)"
|
|
if [ ! -z "${OBJECT}" ]; then
|
|
CURRENT_OBJECT="${OBJECT}"
|
|
fi
|
|
|
|
#printf '%s\n' "${line}"
|
|
FOUND_SYMBOL="$(printf '%s' "${line}" | grep '^\(malloc\|calloc\|realloc\|free\|printf\|fprintf\|isdigit\|isalpha\|isalnum\|isspace\|isprint\|ispunct\)$' || true)"
|
|
|
|
if [ ! -z "${FOUND_SYMBOL}" ]; then
|
|
SKIP=0
|
|
case "${CURRENT_OBJECT}" in
|
|
'[ndpi_main.o]')
|
|
case "${FOUND_SYMBOL}" in
|
|
'printf'|'fprintf') SKIP=1 ;;
|
|
esac
|
|
;;
|
|
'[ahocorasick.o]')
|
|
case "${FOUND_SYMBOL}" in
|
|
'fprintf') SKIP=1 ;;
|
|
esac
|
|
;;
|
|
'[roaring.o]')
|
|
case "${FOUND_SYMBOL}" in
|
|
'malloc'|'calloc'|'realloc'|'free') SKIP=1 ;;
|
|
esac
|
|
;;
|
|
'[ndpi_utils.o]'|'[ndpi_memory.o]')
|
|
case "${FOUND_SYMBOL}" in
|
|
'malloc'|'calloc'|'free') SKIP=1 ;;
|
|
esac
|
|
;;
|
|
'[gcrypt_light.o]')
|
|
case "${FOUND_SYMBOL}" in
|
|
'free') SKIP=1 ;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
if [ ${SKIP} -eq 0 ]; then
|
|
FAIL_COUNT="$((FAIL_COUNT + 1))"
|
|
printf '%s: %s\n' "${CURRENT_OBJECT}" "${FOUND_SYMBOL}"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
printf 'Unwanted symbols found: %s\n' "${FAIL_COUNT}"
|
|
if [ ${FAIL_COUNT} -gt 0 ]; then
|
|
printf '%s\n' 'Please make sure to use only ndpi_malloc/ndpi_calloc/ndpi_realloc/ndpi_free/ndpi_isdigit/ndpi_isalpha/ndpi_isalnum/ndpi_isspace/ndpi_isprint/ndpi_ispunct wrapper instead of malloc/calloc/realloc/free/isdigit/isalpha/isalnum/isspace/isprint/ispunct'
|
|
fi
|
|
exit ${FAIL_COUNT}
|