summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaweł Krupa <pawel@krupa.net.pl>2018-09-12 23:18:19 +0200
committerCosta Tsaousis <costa@tsaousis.gr>2018-09-13 00:18:19 +0300
commit0426209eadb5ea4a8ad473b811b0366b7c0d8c80 (patch)
tree906f9ac8e454cd48e073f18389e281f63bae7913
parent98300601b3dd408364afa0fe06ff24e8b3d23d55 (diff)
[cleanup crusade] linting shell scripts for docker, tests and python (#4162)
* shell linting various scripts * remove python-modules-installer.sh.in
-rwxr-xr-xcoverity-scan.sh8
-rwxr-xr-xcppcheck.sh2
-rwxr-xr-xdocker/build.sh2
-rwxr-xr-xpackaging/tar-compare1
-rw-r--r--python.d/Makefile.am2
-rw-r--r--python.d/python-modules-installer.sh.in159
-rwxr-xr-xtests/stress.sh20
7 files changed, 17 insertions, 177 deletions
diff --git a/coverity-scan.sh b/coverity-scan.sh
index 107690bc06..d39f9b246a 100755
--- a/coverity-scan.sh
+++ b/coverity-scan.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
-cpus=$(grep ^processor </proc/cpuinfo| wc -l)
+cpus=$(grep -c ^processor </proc/cpuinfo)
[ -z "${cpus}" ] && cpus=1
token="${COVERITY_SCAN_TOKEN}"
-[ -z "${token}" -a -f .coverity-token ] && token="$(<.coverity-token)"
+([ -z "${token}" ] && [ -f .coverity-token ]) && token="$(<.coverity-token)"
[ -z "${token}" ] && \
echo >&2 "Save the coverity token to .coverity-token or export it as COVERITY_SCAN_TOKEN." && \
exit 1
@@ -12,7 +12,7 @@ token="${COVERITY_SCAN_TOKEN}"
# echo >&2 "Coverity token: ${token}"
covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
-[ -z "${covbuild}" -a -f .coverity-build ] && covbuild="$(<.coverity-build)"
+([ -z "${covbuild}" ] && [ -f .coverity-build ]) && covbuild="$(<.coverity-build)"
[ -z "${covbuild}" ] && \
echo "Save command the full filename of cov-build in .coverity-build" && \
exit 1
@@ -21,7 +21,7 @@ covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
echo "The command ${covbuild} is not executable. Save command the full filename of cov-build in .coverity-build" && \
exit 1
-version="$(cat config.h | grep "^#define PACKAGE_VERSION" | cut -d '"' -f 2)"
+version="$(grep "^#define PACKAGE_VERSION" config.h | cut -d '"' -f 2)"
echo >&2 "Working on netdata version: ${version}"
echo >&2 "Cleaning up old builds..."
diff --git a/cppcheck.sh b/cppcheck.sh
index 08f24dc364..152baf37a2 100755
--- a/cppcheck.sh
+++ b/cppcheck.sh
@@ -17,7 +17,7 @@ cd "${base}/src" || exit 1
file="${1}"
shift
-[ "${file}" = "${base}" -o -z "${file}" ] && file="${base}/src"
+([ "${file}" = "${base}" ] || [ -z "${file}" ]) && file="${base}/src"
"${cppcheck}" \
-j ${processors} \
diff --git a/docker/build.sh b/docker/build.sh
index 6b62b6ce48..b0789783bf 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -14,7 +14,7 @@ fi
docker run --rm --privileged multiarch/qemu-user-static:register --reset
if [ -f Dockerfile ]; then
- cd ../
+ cd ../ || exit 1
fi
for ARCH in i386 armhf aarch64 amd64; do
diff --git a/packaging/tar-compare b/packaging/tar-compare
index 374765ba11..88f638681d 100755
--- a/packaging/tar-compare
+++ b/packaging/tar-compare
@@ -59,7 +59,6 @@ diff -r "$1" $MYTMP/unpack/* | grep "^Only" | sed \
-e '/: .*\.o$/d' \
-e '/: CMakeLists.txt/d' \
-e '/: tests$/d' \
- -e '/python.d: python-modules-installer\.sh\.in$/d' \
-e '/: .travis.yml/d' > $MYTMP/out
cat $MYTMP/out
diff --git a/python.d/Makefile.am b/python.d/Makefile.am
index 2c620b6455..c04bd5a1af 100644
--- a/python.d/Makefile.am
+++ b/python.d/Makefile.am
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: GPL-3.0+
MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
CLEANFILES = \
- python-modules-installer.sh \
$(NULL)
include $(top_srcdir)/build/subst.inc
@@ -9,7 +8,6 @@ include $(top_srcdir)/build/subst.inc
SUFFIXES = .in
dist_python_SCRIPTS = \
- python-modules-installer.sh \
$(NULL)
dist_python_DATA = \
diff --git a/python.d/python-modules-installer.sh.in b/python.d/python-modules-installer.sh.in
deleted file mode 100644
index 74b99d72da..0000000000
--- a/python.d/python-modules-installer.sh.in
+++ /dev/null
@@ -1,159 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: GPL-3.0+
-
-umask 022
-
-dir="@pythondir_POST@"
-target="${dir}/python_modules"
-pv="$(python -V 2>&1)"
-
-# parse parameters
-while [ ! -z "${1}" ]
-do
- case "${1}" in
- -p|--python)
- pv="Python ${2}"
- shift 2
- ;;
-
- -d|--dir)
- dir="${2}"
- target="${dir}/python_modules"
- echo >&2 "Will install python modules in: '${target}'"
- shift 2
- ;;
-
- -s|--system)
- target=
- echo >&2 "Will install python modules system-wide"
- shift
- ;;
-
- -h|--help)
- echo "${0} [--dir netdata-python.d-path] [--system]"
- echo "Please make sure you have installed packages: python-pip (or python3-pip) python-dev libyaml-dev libmysqlclient-dev"
- exit 0
- ;;
-
- *)
- echo >&2 "Cannot understand parameter: ${1}"
- exit 1
- ;;
- esac
-done
-
-
-if [ ! -z "${target}" -a ! -d "${target}" ]
-then
- echo >&2 "Cannot find directory: '${target}'"
- exit 1
-fi
-
-if [[ "${pv}" =~ ^Python\ 2.* ]]
-then
- pv=2
- pip="$(which pip2 2>/dev/null)"
-elif [[ "${pv}" =~ ^Python\ 3.* ]]
-then
- pv=3
- pip="$(which pip3 2>/dev/null)"
-else
- echo >&2 "Cannot detect python version. Is python installed?"
- exit 1
-fi
-
-[ -z "${pip}" ] && pip="$(which pip 2>/dev/null)"
-if [ -z "${pip}" ]
-then
- echo >&2 "pip command is required to install python v${pv} modules."
- [ "${pv}" = "2" ] && echo >&2 "Please install python-pip."
- [ "${pv}" = "3" ] && echo >&2 "Please install python3-pip."
- exit 1
-fi
-
-echo >&2 "Working for python version ${pv} (pip command: '${pip}')"
-echo >&2 "Installing netdata python modules in: '${target}'"
-
-run() {
- printf "Running command:\n# "
- printf "%q " "${@}"
- printf "\n"
- "${@}"
-}
-
-# try to install all the python modules given as parameters
-# until the first that succeeds
-failed=""
-installed=""
-errors=0
-pip_install() {
- local ret x msg="${1}"
- shift
-
- echo >&2
- echo >&2
- echo >&2 "Installing one of: ${*}"
-
- for x in "${@}"
- do
- echo >&2
- echo >&2 "attempting to install: ${x}"
- if [ ! -z "${target}" ]
- then
- run "${pip}" install --target "${target}" "${x}"
- ret=$?
- else
- run "${pip}" install "${x}"
- ret=$?
- fi
- [ ${ret} -eq 0 ] && break
- echo >&2 "failed to install: ${x}. ${msg}"
- done
-
- if [ ${ret} -ne 0 ]
- then
- echo >&2
- echo >&2
- echo >&2 "FAILED: could not install any of: ${*}. ${msg}"
- echo >&2
- echo >&2
- errors=$(( errors + 1 ))
- failed="${failed}|${*}"
- else
- echo >&2
- echo >&2
- echo >&2 "SUCCESS: we have: ${x}"
- echo >&2
- echo >&2
- installed="${installed} ${x}"
- fi
- return ${ret}
-}
-
-if [ "${pv}" = "2" ]
-then
- pip_install "is libyaml-dev and python-dev installed?" pyyaml
- pip_install "is libmysqlclient-dev and python-dev installed?" mysqlclient mysql-python pymysql
-else
- pip_install "is libyaml-dev and python-dev installed?" pyyaml
- pip_install "is libmysqlclient-dev and python-dev installed?" mysql-python mysqlclient pymysql
-fi
-
-echo >&2
-echo >&2
-if [ ${errors} -ne 0 ]
-then
- echo >&2 "Failed to install ${errors} modules: ${failed}"
- if [ ! -z "${target}" ]
- then
- echo >&2
- echo >&2 "If you are getting errors during cleanup from pip, there is a known bug"
- echo >&2 "in certain versions of pip that prevents installing packages local to an"
- echo >&2 "application. To install them system-wide please run:"
- echo >&2 "$0 --system"
- fi
- exit 1
-else
- echo >&2 "All done. We have: ${installed}"
- exit 0
-fi
diff --git a/tests/stress.sh b/tests/stress.sh
index 186dd47e8f..b9af86b07a 100755
--- a/tests/stress.sh
+++ b/tests/stress.sh
@@ -3,16 +3,17 @@
# set the host to connect to
if [ ! -z "$1" ]
- then
+then
host="$1"
else
host="http://127.0.0.1:19999"
fi
echo "using netdata server at: $host"
+# shellcheck disable=SC2207 disable=SC1117
charts=($(curl "$host/netdata.conf" 2>/dev/null | grep "^\[" | cut -d '[' -f 2 | cut -d ']' -f 1 | grep -v ^global$ | grep -v "^plugin" | sort -u))
if [ "${#charts[@]}" -eq 0 ]
- then
+then
echo "Cannot download charts from server: $host"
exit 1
fi
@@ -27,7 +28,7 @@ entries="$(curl "$host/netdata.conf" 2>/dev/null | grep "history = " | head -n 1
[ $entries -gt 3600 ] && entries=3600
if [ $entries -ne 3600 ]
- then
+then
echo >&2 "You are running a test for a history of $entries entries."
fi
@@ -42,19 +43,20 @@ duration=$((now - first))
file="$(mktemp /tmp/netdata-stress-XXXXXXXX)"
cleanup() {
echo "cleanup"
- [ -f $file ] && rm $file
+ [ -f "$file" ] && rm "$file"
}
trap cleanup EXIT
-while [ 1 = 1 ]
+while true
do
- echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >$file
+ echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >"$file"
+ # shellcheck disable=SC2034
for x in {1..100}
do
dt=$((RANDOM * duration / 32767))
st=$((RANDOM * duration / 32767))
et=$(( st + dt ))
- [ $et -gt $now ] && st=$(( now - dt ))
+ [ $et -gt "$now" ] && st=$(( now - dt ))
points=$((RANDOM * 2000 / 32767 + 2))
st=$((first + st))
@@ -70,6 +72,6 @@ do
format="${formats[$format]}"
echo "--url \"$host/api/v1/data?chart=$chart&mode=$mode&format=$format&options=$options&after=$st&before=$et&points=$points\" \\"
- done >>$file
- bash $file >/dev/null
+ done >>"$file"
+ bash "$file" >/dev/null
done