From 0c2827e1308df7cb703391a20cc01b0e92795632 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 24 Jun 2017 15:49:16 -0700 Subject: [PATCH 1/3] Test exclusion for sourced files SC1090. Signed-off-by: Dan Schaper --- test/test_shellcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_shellcheck.py b/test/test_shellcheck.py index fa342027..9c4f141b 100644 --- a/test/test_shellcheck.py +++ b/test/test_shellcheck.py @@ -7,7 +7,7 @@ run_local = testinfra.get_backend( def test_scripts_pass_shellcheck(): ''' Make sure shellcheck does not find anything wrong with our shell scripts ''' - shellcheck = "find . -type f \( -name 'update.sh' -o -name 'piholeDebug.sh' \) | while read file; do shellcheck \"$file\"; done;" + shellcheck = "find . -type f \( -name 'update.sh' -o -name 'piholeDebug.sh' \) | while read file; do shellcheck \"$file\" -e SC1090; done;" results = run_local(shellcheck) print results.stdout assert '' == results.stdout From 07fc047dd8ce195bd5216e6a52d32348b9a70561 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 25 Jun 2017 12:26:16 -0700 Subject: [PATCH 2/3] Remove testing for `debug` as this is getting a re-write by Jacob. Signed-off-by: Dan Schaper --- test/test_shellcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_shellcheck.py b/test/test_shellcheck.py index 9c4f141b..1b6b35a7 100644 --- a/test/test_shellcheck.py +++ b/test/test_shellcheck.py @@ -7,7 +7,7 @@ run_local = testinfra.get_backend( def test_scripts_pass_shellcheck(): ''' Make sure shellcheck does not find anything wrong with our shell scripts ''' - shellcheck = "find . -type f \( -name 'update.sh' -o -name 'piholeDebug.sh' \) | while read file; do shellcheck \"$file\" -e SC1090; done;" + shellcheck = "find . -type f -name 'update.sh' | while read file; do shellcheck \"$file\" -e SC1090; done;" results = run_local(shellcheck) print results.stdout assert '' == results.stdout From c29c4ceb0f179f6e0ba0775edd265bdd7029987a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 25 Jun 2017 14:21:41 -0700 Subject: [PATCH 3/3] Integrate DL's update.sh fixes. `shellcheck -x` for following files. Do not test for included files SC1091 Signed-off-by: Dan Schaper --- advanced/Scripts/update.sh | 25 +++++++++++++++---------- test/test_shellcheck.py | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index e8155f1a..779f6c8d 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -19,12 +19,14 @@ readonly ADMIN_INTERFACE_DIR="/var/www/html/admin" readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" readonly PI_HOLE_FILES_DIR="/etc/.pihole" +# shellcheck disable=SC2034 PH_TEST=true -source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh -colfile="/opt/pihole/COL_TABLE" -source ${colfile} +# Have to ignore the following rule as spaces in paths are not supported by ShellCheck +#shellcheck disable=SC1090 +source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" +source "/opt/pihole/COL_TABLE" # is_repo() sourced from basic-install.sh # make_repo() sourced from basic-install.sh @@ -34,14 +36,14 @@ source ${colfile} GitCheckUpdateAvail() { local directory="${1}" curdir=$PWD - cd "${directory}" + cd "${directory}" || return # Fetch latest changes in this repo git fetch --quiet origin # @ alone is a shortcut for HEAD. Older versions of git # need @{0} - LOCAL="$(git rev-parse @{0})" + LOCAL="$("git rev-parse @{0}")" # The suffix @{upstream} to a branchname # (short form @{u}) refers @@ -50,7 +52,7 @@ GitCheckUpdateAvail() { # (configured with branch..remote and # branch..merge). A missing branchname # defaults to the current one. - REMOTE="$(git rev-parse @{upstream})" + REMOTE="$("git rev-parse @{upstream}")" if [[ ${#LOCAL} == 0 ]]; then echo -e " ${COL_LIGHT_RED}Error: Local revision could not be obtained, ask Pi-hole support." @@ -66,7 +68,7 @@ GitCheckUpdateAvail() { fi # Change back to original directory - cd "${curdir}" + cd "${curdir}" || exit if [[ "${LOCAL}" != "${REMOTE}" ]]; then # Local branch is behind remote branch -> Update @@ -81,8 +83,10 @@ GitCheckUpdateAvail() { FTLcheckUpdate() { - local FTLversion=$(/usr/bin/pihole-FTL tag) - local FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n') + local FTLversion + FTLversion=$(/usr/bin/pihole-FTL tag) + local FTLlatesttag + FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n') if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then return 0 @@ -94,6 +98,7 @@ FTLcheckUpdate() { main() { local pihole_version_current local web_version_current + #shellcheck disable=1090,2154 source "${setupVars}" #This is unlikely @@ -120,7 +125,7 @@ main() { FTL_update=false echo -e " ${INFO} FTL:\t\t${COL_LIGHT_GREEN}up to date${COL_NC}" fi - + # Logic: Don't update FTL when there is a core update available # since the core update will run the installer which will itself # re-install (i.e. update) FTL diff --git a/test/test_shellcheck.py b/test/test_shellcheck.py index 1b6b35a7..5b1a8961 100644 --- a/test/test_shellcheck.py +++ b/test/test_shellcheck.py @@ -7,7 +7,7 @@ run_local = testinfra.get_backend( def test_scripts_pass_shellcheck(): ''' Make sure shellcheck does not find anything wrong with our shell scripts ''' - shellcheck = "find . -type f -name 'update.sh' | while read file; do shellcheck \"$file\" -e SC1090; done;" + shellcheck = "find . -type f -name 'update.sh' | while read file; do shellcheck -x \"$file\" -e SC1090,SC1091; done;" results = run_local(shellcheck) print results.stdout assert '' == results.stdout