@cryptotaxi247 / netdata-1 / commits / 0426209ea

[cleanup crusade] linting shell scripts for docker, tests and python (#4162)

* shell linting various scripts * remove python-modules-installer.sh.in

Paweł Krupa committed Sep 12, 2018 at 23:18 UTC 0426209eadb5ea4a8ad473b811b0366b7c0d8c80
7 files changed +17 -177
coverity-scan.sh
+4 -4
@@ -1,10 +1,10 @@
1 #!/usr/bin/env bash
2
3 -cpus=$(grep ^processor </proc/cpuinfo| wc -l)
3 +cpus=$(grep -c ^processor </proc/cpuinfo)
4 [ -z "${cpus}" ] && cpus=1
5
6 token="${COVERITY_SCAN_TOKEN}"
7 -[ -z "${token}" -a -f .coverity-token ] && token="$(<.coverity-token)"
7 +([ -z "${token}" ] && [ -f .coverity-token ]) && token="$(<.coverity-token)"
8 [ -z "${token}" ] && \
9 echo >&2 "Save the coverity token to .coverity-token or export it as COVERITY_SCAN_TOKEN." && \
10 exit 1
@@ -12,7 +12,7 @@ token="${COVERITY_SCAN_TOKEN}"
12 # echo >&2 "Coverity token: ${token}"
13
14 covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
15 -[ -z "${covbuild}" -a -f .coverity-build ] && covbuild="$(<.coverity-build)"
15 +([ -z "${covbuild}" ] && [ -f .coverity-build ]) && covbuild="$(<.coverity-build)"
16 [ -z "${covbuild}" ] && \
17 echo "Save command the full filename of cov-build in .coverity-build" && \
18 exit 1
@@ -21,7 +21,7 @@ covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
21 echo "The command ${covbuild} is not executable. Save command the full filename of cov-build in .coverity-build" && \
22 exit 1
23
24 -version="$(cat config.h | grep "^#define PACKAGE_VERSION" | cut -d '"' -f 2)"
24 +version="$(grep "^#define PACKAGE_VERSION" config.h | cut -d '"' -f 2)"
25 echo >&2 "Working on netdata version: ${version}"
26
27 echo >&2 "Cleaning up old builds..."
cppcheck.sh
+1 -1
@@ -17,7 +17,7 @@ cd "${base}/src" || exit 1
17
18 file="${1}"
19 shift
20 -[ "${file}" = "${base}" -o -z "${file}" ] && file="${base}/src"
20 +([ "${file}" = "${base}" ] || [ -z "${file}" ]) && file="${base}/src"
21
22 "${cppcheck}" \
23 -j ${processors} \
docker/build.sh
+1 -1
@@ -14,7 +14,7 @@ fi
14 docker run --rm --privileged multiarch/qemu-user-static:register --reset
15
16 if [ -f Dockerfile ]; then
17 - cd ../
17 + cd ../ || exit 1
18 fi
19
20 for ARCH in i386 armhf aarch64 amd64; do
packaging/tar-compare
-1
@@ -59,7 +59,6 @@ diff -r "$1" $MYTMP/unpack/* | grep "^Only" | sed \
59 -e '/: .*\.o$/d' \
60 -e '/: CMakeLists.txt/d' \
61 -e '/: tests$/d' \
62 - -e '/python.d: python-modules-installer\.sh\.in$/d' \
62 -e '/: .travis.yml/d' > $MYTMP/out
63
64 cat $MYTMP/out
python.d/Makefile.am
-2
@@ -1,7 +1,6 @@
1 # SPDX-License-Identifier: GPL-3.0+
2 MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
3 CLEANFILES = \
4 - python-modules-installer.sh \
4 $(NULL)
5
6 include $(top_srcdir)/build/subst.inc
@@ -9,7 +8,6 @@ include $(top_srcdir)/build/subst.inc
8 SUFFIXES = .in
9
10 dist_python_SCRIPTS = \
12 - python-modules-installer.sh \
11 $(NULL)
12
13 dist_python_DATA = \
python.d/python-modules-installer.sh.in deleted
-159
@@ -1,159 +0,0 @@
1 -#!/usr/bin/env bash
2 -# SPDX-License-Identifier: GPL-3.0+
3 -
4 -umask 022
5 -
6 -dir="@pythondir_POST@"
7 -target="${dir}/python_modules"
8 -pv="$(python -V 2>&1)"
9 -
10 -# parse parameters
11 -while [ ! -z "${1}" ]
12 -do
13 - case "${1}" in
14 - -p|--python)
15 - pv="Python ${2}"
16 - shift 2
17 - ;;
18 -
19 - -d|--dir)
20 - dir="${2}"
21 - target="${dir}/python_modules"
22 - echo >&2 "Will install python modules in: '${target}'"
23 - shift 2
24 - ;;
25 -
26 - -s|--system)
27 - target=
28 - echo >&2 "Will install python modules system-wide"
29 - shift
30 - ;;
31 -
32 - -h|--help)
33 - echo "${0} [--dir netdata-python.d-path] [--system]"
34 - echo "Please make sure you have installed packages: python-pip (or python3-pip) python-dev libyaml-dev libmysqlclient-dev"
35 - exit 0
36 - ;;
37 -
38 - *)
39 - echo >&2 "Cannot understand parameter: ${1}"
40 - exit 1
41 - ;;
42 - esac
43 -done
44 -
45 -
46 -if [ ! -z "${target}" -a ! -d "${target}" ]
47 -then
48 - echo >&2 "Cannot find directory: '${target}'"
49 - exit 1
50 -fi
51 -
52 -if [[ "${pv}" =~ ^Python\ 2.* ]]
53 -then
54 - pv=2
55 - pip="$(which pip2 2>/dev/null)"
56 -elif [[ "${pv}" =~ ^Python\ 3.* ]]
57 -then
58 - pv=3
59 - pip="$(which pip3 2>/dev/null)"
60 -else
61 - echo >&2 "Cannot detect python version. Is python installed?"
62 - exit 1
63 -fi
64 -
65 -[ -z "${pip}" ] && pip="$(which pip 2>/dev/null)"
66 -if [ -z "${pip}" ]
67 -then
68 - echo >&2 "pip command is required to install python v${pv} modules."
69 - [ "${pv}" = "2" ] && echo >&2 "Please install python-pip."
70 - [ "${pv}" = "3" ] && echo >&2 "Please install python3-pip."
71 - exit 1
72 -fi
73 -
74 -echo >&2 "Working for python version ${pv} (pip command: '${pip}')"
75 -echo >&2 "Installing netdata python modules in: '${target}'"
76 -
77 -run() {
78 - printf "Running command:\n# "
79 - printf "%q " "${@}"
80 - printf "\n"
81 - "${@}"
82 -}
83 -
84 -# try to install all the python modules given as parameters
85 -# until the first that succeeds
86 -failed=""
87 -installed=""
88 -errors=0
89 -pip_install() {
90 - local ret x msg="${1}"
91 - shift
92 -
93 - echo >&2
94 - echo >&2
95 - echo >&2 "Installing one of: ${*}"
96 -
97 - for x in "${@}"
98 - do
99 - echo >&2
100 - echo >&2 "attempting to install: ${x}"
101 - if [ ! -z "${target}" ]
102 - then
103 - run "${pip}" install --target "${target}" "${x}"
104 - ret=$?
105 - else
106 - run "${pip}" install "${x}"
107 - ret=$?
108 - fi
109 - [ ${ret} -eq 0 ] && break
110 - echo >&2 "failed to install: ${x}. ${msg}"
111 - done
112 -
113 - if [ ${ret} -ne 0 ]
114 - then
115 - echo >&2
116 - echo >&2
117 - echo >&2 "FAILED: could not install any of: ${*}. ${msg}"
118 - echo >&2
119 - echo >&2
120 - errors=$(( errors + 1 ))
121 - failed="${failed}|${*}"
122 - else
123 - echo >&2
124 - echo >&2
125 - echo >&2 "SUCCESS: we have: ${x}"
126 - echo >&2
127 - echo >&2
128 - installed="${installed} ${x}"
129 - fi
130 - return ${ret}
131 -}
132 -
133 -if [ "${pv}" = "2" ]
134 -then
135 - pip_install "is libyaml-dev and python-dev installed?" pyyaml
136 - pip_install "is libmysqlclient-dev and python-dev installed?" mysqlclient mysql-python pymysql
137 -else
138 - pip_install "is libyaml-dev and python-dev installed?" pyyaml
139 - pip_install "is libmysqlclient-dev and python-dev installed?" mysql-python mysqlclient pymysql
140 -fi
141 -
142 -echo >&2
143 -echo >&2
144 -if [ ${errors} -ne 0 ]
145 -then
146 - echo >&2 "Failed to install ${errors} modules: ${failed}"
147 - if [ ! -z "${target}" ]
148 - then
149 - echo >&2
150 - echo >&2 "If you are getting errors during cleanup from pip, there is a known bug"
151 - echo >&2 "in certain versions of pip that prevents installing packages local to an"
152 - echo >&2 "application. To install them system-wide please run:"
153 - echo >&2 "$0 --system"
154 - fi
155 - exit 1
156 -else
157 - echo >&2 "All done. We have: ${installed}"
158 - exit 0
159 -fi
tests/stress.sh
+11 -9
@@ -3,16 +3,17 @@
3
4 # set the host to connect to
5 if [ ! -z "$1" ]
6 - then
6 +then
7 host="$1"
8 else
9 host="http://127.0.0.1:19999"
10 fi
11 echo "using netdata server at: $host"
12
13 +# shellcheck disable=SC2207 disable=SC1117
14 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))
15 if [ "${#charts[@]}" -eq 0 ]
15 - then
16 +then
17 echo "Cannot download charts from server: $host"
18 exit 1
19 fi
@@ -27,7 +28,7 @@ entries="$(curl "$host/netdata.conf" 2>/dev/null | grep "history = " | head -n 1
28 [ $entries -gt 3600 ] && entries=3600
29
30 if [ $entries -ne 3600 ]
30 - then
31 +then
32 echo >&2 "You are running a test for a history of $entries entries."
33 fi
34
@@ -42,19 +43,20 @@ duration=$((now - first))
43 file="$(mktemp /tmp/netdata-stress-XXXXXXXX)"
44 cleanup() {
45 echo "cleanup"
45 - [ -f $file ] && rm $file
46 + [ -f "$file" ] && rm "$file"
47 }
48 trap cleanup EXIT
49
49 -while [ 1 = 1 ]
50 +while true
51 do
51 - echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >$file
52 + echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >"$file"
53 + # shellcheck disable=SC2034
54 for x in {1..100}
55 do
56 dt=$((RANDOM * duration / 32767))
57 st=$((RANDOM * duration / 32767))
58 et=$(( st + dt ))
57 - [ $et -gt $now ] && st=$(( now - dt ))
59 + [ $et -gt "$now" ] && st=$(( now - dt ))
60
61 points=$((RANDOM * 2000 / 32767 + 2))
62 st=$((first + st))
@@ -70,6 +72,6 @@ do
72 format="${formats[$format]}"
73
74 echo "--url \"$host/api/v1/data?chart=$chart&mode=$mode&format=$format&options=$options&after=$st&before=$et&points=$points\" \\"
73 - done >>$file
74 - bash $file >/dev/null
75 + done >>"$file"
76 + bash "$file" >/dev/null
77 done