Assorted shellcheck cleanup. (#14524)
* Add shellcheck config file to globally disable dead code checks. These checks have an extremely high false positive rate and even when they’re correctly flagging code the impact is generally very low. * Fix assorted shellcheck errors in installer code. This should make reviewing PRs relating to this code much easier. * Make shellcheck quit complaining about shellcheckrc formatting.
Austin S. Hemmelgarn committed
Feb 16, 2023 at 07:31 UTC
5c7bd2c6488cd19fa4a0eb435221223ea5e7de81
8 files changed
+37
-12
.shellcheckrc
new
+3
@@ -0,0 +1,3 @@
1
+#!/bin/sh
2
+# shellcheck disable=SC2034
3
+disable=SC2317
netdata-installer.sh
+6
-6
@@ -788,7 +788,7 @@ copy_libbpf() {
788
}
789
790
bundle_libbpf() {
791
- if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 1 ]; } || [ "$(uname -s)" != Linux ]; then
791
+ if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
792
return 0
793
fi
794
@@ -822,14 +822,14 @@ bundle_libbpf() {
822
rm -rf "${tmp}"; then
823
run_ok "libbpf built and prepared."
824
else
825
- if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
825
+ if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
826
fatal "failed to build libbpf." I0005
827
else
828
run_failed "Failed to build libbpf. eBPF support will be disabled"
829
fi
830
fi
831
else
832
- if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
832
+ if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
833
fatal "Failed to fetch sources for libbpf." I0006
834
else
835
run_failed "Unable to fetch sources for libbpf. eBPF support will be disabled"
@@ -846,7 +846,7 @@ copy_co_re() {
846
}
847
848
bundle_ebpf_co_re() {
849
- if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 1 ]; } || [ "$(uname -s)" != Linux ]; then
849
+ if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
850
return 0
851
fi
852
@@ -869,7 +869,7 @@ bundle_ebpf_co_re() {
869
rm -rf "${tmp}"; then
870
run_ok "libbpf built and prepared."
871
else
872
- if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
872
+ if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
873
fatal "Failed to get eBPF CO-RE files." I0007
874
else
875
run_failed "Failed to get eBPF CO-RE files. eBPF support will be disabled"
@@ -878,7 +878,7 @@ bundle_ebpf_co_re() {
878
fi
879
fi
880
else
881
- if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
881
+ if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
882
fatal "Failed to fetch eBPF CO-RE files." I0008
883
else
884
run_failed "Failed to fetch eBPF CO-RE files. eBPF support will be disabled"
packaging/installer/dependencies/centos.sh
+1
-1
@@ -96,7 +96,7 @@ check_flags() {
96
97
validate_tree_centos() {
98
local opts=
99
- export local package_manager=
99
+ package_manager=
100
if [[ "${NON_INTERACTIVE}" == "1" ]]; then
101
echo >&2 "Running in non-interactive mode"
102
opts="-y"
packaging/installer/functions.sh
+2
-2
@@ -411,7 +411,7 @@ get_group(){
411
if command -v getent > /dev/null 2>&1; then
412
getent group "${1:-""}"
413
else
414
- cat /etc/group | grep "^${1}:"
414
+ grep "^${1}:" /etc/group
415
fi
416
}
417
@@ -600,7 +600,7 @@ install_netdata_service() {
600
echo >&2 "Note: To explicitly enable netdata automatic start, set 'netdata_enable' to 'YES' in /etc/rc.conf"
601
echo >&2 ""
602
603
- return ${myret}
603
+ return "${myret}"
604
605
elif issystemd; then
606
# systemd is running on this system
packaging/installer/install-required-packages.sh
+11
-1
@@ -1376,6 +1376,7 @@ validate_tree_freebsd() {
1376
echo >&2 " > Checking for gmake ..."
1377
if ! pkg query %n-%v | grep -q gmake; then
1378
if prompt "gmake is required to build on FreeBSD and is not installed. Shall I install it?"; then
1379
+ # shellcheck disable=2086
1380
run ${sudo} pkg install ${opts} gmake
1381
fi
1382
fi
@@ -1425,13 +1426,16 @@ validate_tree_centos() {
1426
echo >&2 " > Checking for config-manager ..."
1427
if ! run ${sudo} dnf config-manager --help; then
1428
if prompt "config-manager not found, shall I install it?"; then
1429
+ # shellcheck disable=2086
1430
run ${sudo} dnf ${opts} install 'dnf-command(config-manager)'
1431
fi
1432
fi
1433
1434
echo >&2 " > Checking for CRB ..."
1435
+ # shellcheck disable=2086
1436
if ! run dnf ${sudo} repolist | grep CRB; then
1437
if prompt "CRB not found, shall I install it?"; then
1438
+ # shellcheck disable=2086
1439
run ${sudo} dnf ${opts} config-manager --set-enabled crb
1440
fi
1441
fi
@@ -1439,24 +1443,29 @@ validate_tree_centos() {
1443
echo >&2 " > Checking for config-manager ..."
1444
if ! run ${sudo} yum config-manager --help; then
1445
if prompt "config-manager not found, shall I install it?"; then
1446
+ # shellcheck disable=2086
1447
run ${sudo} yum ${opts} install 'dnf-command(config-manager)'
1448
fi
1449
fi
1450
1451
echo >&2 " > Checking for PowerTools ..."
1452
+ # shellcheck disable=2086
1453
if ! run yum ${sudo} repolist | grep PowerTools; then
1454
if prompt "PowerTools not found, shall I install it?"; then
1455
+ # shellcheck disable=2086
1456
run ${sudo} yum ${opts} config-manager --set-enabled powertools
1457
fi
1458
fi
1459
1460
echo >&2 " > Updating libarchive ..."
1461
+ # shellcheck disable=2086
1462
run ${sudo} yum ${opts} install libarchive
1463
1464
elif [[ "${version}" =~ ^7(\..*)?$ ]]; then
1465
echo >&2 " > Checking for EPEL ..."
1466
if ! rpm -qa | grep epel-release > /dev/null; then
1467
if prompt "EPEL not found, shall I install it?"; then
1468
+ # shellcheck disable=2086
1469
run ${sudo} yum ${opts} install epel-release
1470
fi
1471
fi
@@ -1465,6 +1474,7 @@ validate_tree_centos() {
1474
echo >&2 " > Checking for Okay ..."
1475
if ! rpm -qa | grep okay > /dev/null; then
1476
if prompt "okay not found, shall I install it?"; then
1477
+ # shellcheck disable=2086
1478
run ${sudo} yum ${opts} install http://repo.okay.com.mx/centos/6/x86_64/release/okay-release-1-3.el6.noarch.rpm
1479
fi
1480
fi
@@ -1627,7 +1637,7 @@ install_equo() {
1637
PACMAN_DB_SYNCED=0
1638
validate_install_pacman() {
1639
1630
- if [ ${PACMAN_DB_SYNCED} -eq 0 ]; then
1640
+ if [ "${PACMAN_DB_SYNCED}" -eq 0 ]; then
1641
echo >&2 " > Running pacman -Sy to sync the database"
1642
local x
1643
x=$(pacman -Sy)
packaging/installer/netdata-uninstaller.sh
+12
@@ -239,15 +239,18 @@ if [ -x "$(command -v apt-get)" ] && [ "${INSTALL_TYPE}" = "binpkg-deb" ]; then
239
if dpkg -s netdata > /dev/null; then
240
echo "Found netdata native installation"
241
if user_input "Do you want to remove netdata? "; then
242
+ # shellcheck disable=SC2086
243
apt-get remove netdata ${FLAG}
244
fi
245
if dpkg -s netdata-repo-edge > /dev/null; then
246
if user_input "Do you want to remove netdata-repo-edge? "; then
247
+ # shellcheck disable=SC2086
248
apt-get remove netdata-repo-edge ${FLAG}
249
fi
250
fi
251
if dpkg -s netdata-repo > /dev/null; then
252
if user_input "Do you want to remove netdata-repo? "; then
253
+ # shellcheck disable=SC2086
254
apt-get remove netdata-repo ${FLAG}
255
fi
256
fi
@@ -257,15 +260,18 @@ elif [ -x "$(command -v dnf)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
260
if rpm -q netdata > /dev/null; then
261
echo "Found netdata native installation."
262
if user_input "Do you want to remove netdata? "; then
263
+ # shellcheck disable=SC2086
264
dnf remove netdata ${FLAG}
265
fi
266
if rpm -q netdata-repo-edge > /dev/null; then
267
if user_input "Do you want to remove netdata-repo-edge? "; then
268
+ # shellcheck disable=SC2086
269
dnf remove netdata-repo-edge ${FLAG}
270
fi
271
fi
272
if rpm -q netdata-repo > /dev/null; then
273
if user_input "Do you want to remove netdata-repo? "; then
274
+ # shellcheck disable=SC2086
275
dnf remove netdata-repo ${FLAG}
276
fi
277
fi
@@ -275,15 +281,18 @@ elif [ -x "$(command -v yum)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
281
if rpm -q netdata > /dev/null; then
282
echo "Found netdata native installation."
283
if user_input "Do you want to remove netdata? "; then
284
+ # shellcheck disable=SC2086
285
yum remove netdata ${FLAG}
286
fi
287
if rpm -q netdata-repo-edge > /dev/null; then
288
if user_input "Do you want to remove netdata-repo-edge? "; then
289
+ # shellcheck disable=SC2086
290
yum remove netdata-repo-edge ${FLAG}
291
fi
292
fi
293
if rpm -q netdata-repo > /dev/null; then
294
if user_input "Do you want to remove netdata-repo? "; then
295
+ # shellcheck disable=SC2086
296
yum remove netdata-repo ${FLAG}
297
fi
298
fi
@@ -296,15 +305,18 @@ elif [ -x "$(command -v zypper)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
305
if zypper search -i netdata > /dev/null; then
306
echo "Found netdata native installation."
307
if user_input "Do you want to remove netdata? "; then
308
+ # shellcheck disable=SC2086
309
zypper ${FLAG} remove netdata
310
fi
311
if zypper search -i netdata-repo-edge > /dev/null; then
312
if user_input "Do you want to remove netdata-repo-edge? "; then
313
+ # shellcheck disable=SC2086
314
zypper ${FLAG} remove netdata-repo-edge
315
fi
316
fi
317
if zypper search -i netdata-repo > /dev/null; then
318
if user_input "Do you want to remove netdata-repo? "; then
319
+ # shellcheck disable=SC2086
320
zypper ${FLAG} remove netdata-repo
321
fi
322
fi
packaging/makeself/install-or-update.sh
+1
-1
@@ -179,7 +179,7 @@ dir_should_be_link() {
179
fi
180
181
run ln -s "${t}" "${d}"
182
- cd "${old}"
182
+ cd "${old}" || true
183
}
184
185
dir_should_be_link . bin sbin
system/install-service.sh.in
+1
-1
@@ -265,7 +265,7 @@ install_systemd_service() {
265
warning "Failed to reload systemd unit files."
266
fi
267
268
- if ! systemctl ${ENABLE} netdata; then
268
+ if ! systemctl "${ENABLE}" netdata; then
269
warning "Failed to ${ENABLE} Netdata service."
270
fi
271
fi