Blob Blame History Raw
From aa5d5860146e6b5c76da4746f18b64313cc848e9 Mon Sep 17 00:00:00 2001
From: Link Dupont <subpop@users.noreply.github.com>
Date: Fri, 1 May 2020 13:20:52 -0400
Subject: [PATCH] Fix shellcheck warnings (#117)

* Explicitly invoke bash as the interpreter
* Allow shellcheck to follow external sources
* Test cgconfig check directly - Fixes SC2181
* Remove unncessary variable prefix - Fixes SC2004
* Quote test for ENABLE_CHECK_RESULTS - Fixes SC2070
* Quote $0 properly inside $() context - Fixes SC2086
* Quote the arguments before execing insights-client - Fixes SC2068
* Fix shellcheck errors in autogen.sh
* Update the cgroup check to be more explicit
---
 data/cron/insights-client.cron | 12 ++++++------
 src/redhat-access-insights.in  |  4 ++--
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/data/cron/insights-client.cron b/data/cron/insights-client.cron
index aa5cff6..82add66 100644
--- a/data/cron/insights-client.cron
+++ b/data/cron/insights-client.cron
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # This file is part of insights-client.
 #
@@ -13,13 +13,13 @@ RANDOM_DELAY_SEC=14400
 ENABLE_CHECK_RESULTS="yes"
 
 if [ -f /etc/sysconfig/insights-client ]; then
+    # shellcheck source=insights-client
     . /etc/sysconfig/insights-client
 fi
 
-DELAY=$((1 + RANDOM % ${RANDOM_DELAY_SEC}))
+DELAY=$((1 + RANDOM % RANDOM_DELAY_SEC))
 /bin/sleep ${DELAY}
-/sbin/service cgconfig status > /dev/null 2>&1
-if [ $? == 0 ];
+if [ "$(/sbin/service cgconfig status)" == "Running" ];
 then
     /bin/cgcreate -g memory,cpu,blkio:insights
     /bin/cgset -r memory.limit_in_bytes=2147483648 insights
@@ -29,13 +29,13 @@ then
     /bin/cgset -r blkio.weight=100 insights
     /bin/cgexec -g memory,cpu,blkio:insights /usr/bin/timeout 10m ${path} --retry 3 --quiet
     /bin/cgdelete memory,cpu,blkio:insights
-    if [ -n ${ENABLE_CHECK_RESULTS} ]; then
+    if [[ -n ${ENABLE_CHECK_RESULTS} ]]; then
         /bin/sleep 120
         ${path} --check-results
     fi
 else
     /usr/bin/timeout 10m ${path} --quiet
-    if [ -n ${ENABLE_CHECK_RESULTS} ]; then
+    if [[ -n ${ENABLE_CHECK_RESULTS} ]]; then
         /bin/sleep 120
         /usr/bin/timeout 10m ${path} --check-results
     fi
diff --git a/src/redhat-access-insights.in b/src/redhat-access-insights.in
index dfa016b..62f7bfe 100644
--- a/src/redhat-access-insights.in
+++ b/src/redhat-access-insights.in
@@ -1,5 +1,5 @@
 #!/bin/sh
 
-echo "WARNING: $(basename $0) is deprecated and will be removed in a future release; use 'insights-client' instead."
+echo "WARNING: $(basename "$0") is deprecated and will be removed in a future release; use 'insights-client' instead."
 sleep 3
-exec @bindir@/insights-client $@
+exec @bindir@/insights-client "$@"