From b39937bd14fb681f1d37a151beb8cd2d5abd2a4d Mon Sep 17 00:00:00 2001 From: Andrew Hsu Date: Tue, 11 Jul 2017 00:04:22 +0000 Subject: [PATCH 1/5] add shellcheck make target Shell linter: https://github.com/koalaman/shellcheck Signed-off-by: Andrew Hsu --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 3dbc3e1..7b361a9 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ VERIFY_INSTALL_DISTROS:=$(addprefix verify-install-,centos-7 fedora-24 fedora-25 CHANNEL_TO_TEST?=test EXPECTED_VERSION?= EXPECTED_GITCOMMIT?= +SHELLCHECK=shellcheck .PHONY: needs_version needs_version: @@ -16,6 +17,10 @@ ifndef EXPECTED_GITCOMMIT $(error EXPECTED_GITCOMMIT is undefined) endif +.PHONY: shellcheck +shellcheck: + $(SHELLCHECK) install.sh + .PHONY: check check: $(VERIFY_INSTALL_DISTROS) From cffd6ad6a9eae9768685ed933d0e7fe72871c023 Mon Sep 17 00:00:00 2001 From: Andrew Hsu Date: Tue, 11 Jul 2017 00:29:59 +0000 Subject: [PATCH 2/5] SC2002 useless cat Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. https://github.com/koalaman/shellcheck/wiki/SC2002 Signed-off-by: Andrew Hsu --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 8bf5396..a1369b2 100644 --- a/install.sh +++ b/install.sh @@ -183,7 +183,7 @@ check_forked() { if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then # We're Debian and don't even know it! lsb_dist=debian - dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" + dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')" case "$dist_version" in 9) dist_version="stretch" @@ -388,7 +388,7 @@ do_install() { ;; debian|raspbian) - dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" + dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')" case "$dist_version" in 9) dist_version="stretch" From 89506142087eddd3a3dee44a2d7d611ecf7b64b0 Mon Sep 17 00:00:00 2001 From: Andrew Hsu Date: Tue, 11 Jul 2017 00:33:28 +0000 Subject: [PATCH 3/5] SC2021 don't use [] around ranges in tr Don't use [] around ranges in tr, it replaces literal square brackets. https://github.com/koalaman/shellcheck/wiki/SC2021 Signed-off-by: Andrew Hsu --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index a1369b2..247d351 100644 --- a/install.sh +++ b/install.sh @@ -172,8 +172,8 @@ check_forked() { EOF # Get the upstream release info - lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]') - dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]') + lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]') + dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]') # Print info about upstream distro cat <<-EOF From dda857ecfa018d22cb1071f4dfa1711fd2182df9 Mon Sep 17 00:00:00 2001 From: Andrew Hsu Date: Tue, 11 Jul 2017 00:35:28 +0000 Subject: [PATCH 4/5] SC2086 double quote Double quote to prevent globbing and word splitting. https://github.com/koalaman/shellcheck/wiki/SC2086 Signed-off-by: Andrew Hsu --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 247d351..a5d0e68 100644 --- a/install.sh +++ b/install.sh @@ -262,14 +262,14 @@ do_install() { MAJOR_W=1 MINOR_W=10 - semverParse $version + semverParse "$version" shouldWarn=0 - if [ $major -lt $MAJOR_W ]; then + if [ "$major" -lt "$MAJOR_W" ]; then shouldWarn=1 fi - if [ $major -le $MAJOR_W ] && [ $minor -lt $MINOR_W ]; then + if [ "$major" -le "$MAJOR_W" ] && [ "$minor" -lt "$MINOR_W" ]; then shouldWarn=1 fi From 08feb536f3a8ee98b1e303abdb39aca03efae774 Mon Sep 17 00:00:00 2001 From: Andrew Hsu Date: Tue, 11 Jul 2017 02:54:06 +0000 Subject: [PATCH 5/5] SC2034 unused variable yum_url appears unused. Verify it or export it. https://github.com/koalaman/shellcheck/wiki/SC2034 Signed-off-by: Andrew Hsu --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index a5d0e68..eaf4e36 100644 --- a/install.sh +++ b/install.sh @@ -27,7 +27,7 @@ fi # HERE ========================================================= url="https://test.docker.com/" apt_url="https://apt.dockerproject.org" -yum_url="https://yum.dockerproject.org" +#yum_url="https://yum.dockerproject.org" docker_key="-----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1 @@ -112,11 +112,11 @@ done case "$mirror" in AzureChinaCloud) apt_url="https://mirror.azure.cn/docker-engine/apt" - yum_url="https://mirror.azure.cn/docker-engine/yum" + #yum_url="https://mirror.azure.cn/docker-engine/yum" ;; Aliyun) apt_url="https://mirrors.aliyun.com/docker-engine/apt" - yum_url="https://mirrors.aliyun.com/docker-engine/yum" + #yum_url="https://mirrors.aliyun.com/docker-engine/yum" ;; esac # HERE =========================================================