@cryptotaxi247 / netdata-1 / commits / fef1d0c06

more linting of bash modules (#4183)

Paweł Krupa committed Sep 13, 2018 at 10:24 UTC fef1d0c06ed0ecc9da2f27655f885027315fc91e
4 files changed +32 -23
charts.d/cpufreq.chart.sh
+15 -14
@@ -20,7 +20,7 @@ cpufreq_update_every=
20 cpufreq_priority=10000
21
22 cpufreq_find_all_files() {
23 - find $1 -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null
23 + find "$1" -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null
24 }
25
26 # _check is called once, to find out if this chart should be enabled or not
@@ -30,30 +30,30 @@ cpufreq_check() {
30 # - 0 to enable the chart
31 # - 1 to disable the chart
32
33 - [ -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 1
33 + [ -z "$( cpufreq_find_all_files "$cpufreq_sys_dir" )" ] && return 1
34 return 0
35 }
36
37 # _create is called once, to create the charts
38 cpufreq_create() {
39 - local dir= file= id= i=
39 + local dir file id i
40
41 # we create a script with the source of the
42 # cpufreq_update() function
43 # - the highest speed we can achieve -
44 - [ $cpufreq_source_update -eq 1 ] && echo >$TMP_DIR/cpufreq.sh "cpufreq_update() {"
44 + [ $cpufreq_source_update -eq 1 ] && echo >"$TMP_DIR/cpufreq.sh" "cpufreq_update() {"
45
46 echo "CHART cpu.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line $((cpufreq_priority + 1)) $cpufreq_update_every"
47 - echo >>$TMP_DIR/cpufreq.sh "echo \"BEGIN cpu.cpufreq \$1\""
47 + echo >>"$TMP_DIR/cpufreq.sh" "echo \"BEGIN cpu.cpufreq \$1\""
48
49 i=0
50 - for file in $( cpufreq_find_all_files $cpufreq_sys_dir | sort -u )
50 + for file in $( cpufreq_find_all_files "$cpufreq_sys_dir" | sort -u )
51 do
52 i=$(( i + 1 ))
53 - dir=$( dirname $file )
53 + dir=$( dirname "$file" )
54 cpu=
55
56 - [ -f $dir/affected_cpus ] && cpu=$( cat $dir/affected_cpus )
56 + [ -f "$dir/affected_cpus" ] && cpu=$( cat "$dir/affected_cpus" )
57 [ -z "$cpu" ] && cpu="$i.a"
58
59 id="$( fixid "cpu$cpu" )"
@@ -61,14 +61,15 @@ cpufreq_create() {
61 debug "file='$file', dir='$dir', cpu='$cpu', id='$id'"
62
63 echo "DIMENSION $id '$id' absolute 1 1000"
64 - echo >>$TMP_DIR/cpufreq.sh "echo \"SET $id = \"\$(< $file )"
64 + echo >>"$TMP_DIR/cpufreq.sh" "echo \"SET $id = \"\$(< $file )"
65 done
66 - echo >>$TMP_DIR/cpufreq.sh "echo END"
66 + echo >>"$TMP_DIR/cpufreq.sh" "echo END"
67
68 - [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/cpufreq.sh "}"
68 + [ $cpufreq_source_update -eq 1 ] && echo >>"$TMP_DIR/cpufreq.sh" "}"
69
70 # ok, load the function cpufreq_update() we created
71 - [ $cpufreq_source_update -eq 1 ] && . $TMP_DIR/cpufreq.sh
71 + # shellcheck disable=SC1090
72 + [ $cpufreq_source_update -eq 1 ] && . "$TMP_DIR/cpufreq.sh"
73
74 return 0
75 }
@@ -81,8 +82,8 @@ cpufreq_update() {
82 # do all the work to collect / calculate the values
83 # for each dimension
84 # remember: KEEP IT SIMPLE AND SHORT
84 -
85 - [ $cpufreq_source_update -eq 0 ] && . $TMP_DIR/cpufreq.sh $1
85 + # shellcheck disable=SC1090
86 + [ $cpufreq_source_update -eq 0 ] && . "$TMP_DIR/cpufreq.sh" "$1"
87
88 return 0
89 }
charts.d/example.chart.sh
+9 -3
@@ -47,7 +47,7 @@ example_get() {
47 example_value4=$((8192 + (RANDOM * 16383 / 32767) ))
48
49 if [ $example_count -gt 0 ]
50 - then
50 + then
51 example_count=$((example_count - 1))
52
53 [ $example_last -gt 16383 ] && example_value4=$((example_last + (RANDOM * ( (32767 - example_last) / 2) / 32767)))
@@ -55,8 +55,14 @@ example_get() {
55 else
56 example_count=$((1 + (RANDOM * 5 / 32767) ))
57
58 - [ $example_last -gt 16383 -a $example_value4 -gt 16383 ] && example_value4=$((example_value4 - 16383))
59 - [ $example_last -le 16383 -a $example_value4 -lt 16383 ] && example_value4=$((example_value4 + 16383))
58 + if [ $example_last -gt 16383 ] && [ $example_value4 -gt 16383 ]
59 + then
60 + example_value4=$((example_value4 - 16383))
61 + fi
62 + if [ $example_last -le 16383 ] && [ $example_value4 -lt 16383 ]
63 + then
64 + example_value4=$((example_value4 + 16383))
65 + fi
66 fi
67 example_last=$example_value4
68
charts.d/exim.chart.sh
+2 -2
@@ -23,7 +23,7 @@ exim_check() {
23 exim_command="${EXIM_CMD}"
24 fi
25
26 - if [ $(${exim_command} -bpc 2>&1 | grep -c denied) -ne 0 ]
26 + if [ "$(${exim_command} -bpc 2>&1 | grep -c denied)" -ne 0 ]
27 then
28 error "permission denied - please set 'queue_list_requires_admin = false' in your exim options file"
29 return 1
@@ -42,7 +42,7 @@ EOF
42
43 exim_update() {
44 echo "BEGIN exim_local.qemails $1"
45 - echo "SET emails = " $(run ${exim_command} -bpc)
45 + echo "SET emails = $(run "${exim_command}" -bpc)"
46 echo "END"
47 return 0
48 }
charts.d/hddtemp.chart.sh
+6 -4
@@ -31,13 +31,14 @@ hddtemp_create() {
31 local all
32 all=$(nc $hddtemp_host $hddtemp_port )
33 unset hddtemp_disks
34 - hddtemp_disks=( `grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-` )
34 + # shellcheck disable=SC2190,SC2207
35 + hddtemp_disks=( $(grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-) )
36 fi
37 # local disk_names
38 # disk_names=(`sed -e 's/||/\n/g;s/^|//' <<< "$all" | cut -d '|' -f2 | tr ' ' '_'`)
39
40 echo "CHART hddtemp.temperature 'disks_temp' 'temperature' 'Celsius' 'Disks temperature' 'hddtemp.temp' line $((hddtemp_priority)) $hddtemp_update_every"
40 - for i in `seq 0 $((${#hddtemp_disks[@]}-1))`; do
41 + for i in $(seq 0 $((${#hddtemp_disks[@]}-1))); do
42 # echo "DIMENSION ${hddtemp_disks[i]} ${disk_names[i]} absolute 1 1"
43 echo "DIMENSION ${hddtemp_disks[$i]} '' absolute 1 1"
44 done
@@ -45,13 +46,14 @@ hddtemp_create() {
46 }
47
48 # _update is called continuously, to collect the values
48 -hddtemp_last=0
49 -hddtemp_count=0
49 +#hddtemp_last=0
50 +#hddtemp_count=0
51 hddtemp_update() {
52 # local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` )
53 # local all=( `nc $hddtemp_host $hddtemp_port | awk 'BEGIN { FS="|" };{i=4; while (i <= NF) {print $i+0;i+=5;};}'` )
54 OLD_IFS=$IFS
55 set -f
56 + # shellcheck disable=SC2207
57 IFS="|" all=( $(nc $hddtemp_host $hddtemp_port 2>/dev/null) )
58 set +f
59 IFS=$OLD_IFS