Skip to content

Commit

Permalink
ShellCheck: Enable and fix syntax checking rules (istio#7648)
Browse files Browse the repository at this point in the history
* Only check files with shebang on first line

* Fix if...then in install_prereqs_*.sh

* Enable syntax checking rules (1009, 1020, 1072, 1073)

* Fix SC2006 errors in install_prereqs_*.sh
  • Loading branch information
Tahler authored and istio-testing committed Aug 6, 2018
1 parent d7b1584 commit 772812a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/local/minikube/install_prereqs_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ fi
# Install minikube.
echo "Checking and Installing Minikube version 0.27.0 as required"
minikube --help > /dev/null
if [[ $? -ne 0 || (`minikube version` != *"minikube version: v0.27.0"*) ]]; then
if [ $? -eq 0]; then
if [[ $? -ne 0 || ($(minikube version) != *"minikube version: v0.27.0"*) ]]; then
if [ $? -eq 0 ]; then
echo "Deleting previous minikube cluster and updating minikube to v0.27.0"
minikube delete
rm -rf ~/.minikube
Expand Down
38 changes: 13 additions & 25 deletions tests/e2e/local/minikube/install_prereqs_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ sudo chown -R $USER:admin /usr/local/bin

echo "Checking curl"
curl --help > /dev/null
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "curl is not installed. Install it from homebrew."
brew install curl
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "Installation of curl from brew fails. Please install it manually."
exit 1
else
Expand All @@ -31,12 +29,10 @@ fi

echo "Checking docker..."
docker --help > /dev/null
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "docker is not installed. Install it from homebrew cask."
brew cask install docker
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "Installation of docker from brew fails. Please install it manually."
exit 1
else
Expand All @@ -48,13 +44,11 @@ fi

echo "Checking docker-machine..."
docker-machine --help > /dev/null
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "docker-machine is not installed. Downloading and Installing it using curl."
base=https://github.com/docker/machine/releases/download/v0.14.0 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/usr/local/bin/docker-machine && chmod +x /usr/local/bin/docker-machine
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "Installation of docker-machine failed. Please install it manually."
exit 1
else
Expand All @@ -66,17 +60,15 @@ else
fi

function fail_hyperkit_installation() {
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "Installation of hyperkit driver failed. Please install it manually."
exit 1
fi
}

echo "Checking hyperkit..."
hyperkit -h > /dev/null
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "hyperkit is not installed. Downloading and installing using curl."
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit
fail_hyperkit_installation
Expand All @@ -95,16 +87,14 @@ fi

echo "Checking and Installing Minikube version 0.27.0 as required..."
minikube --help > /dev/null
if [[ $? -ne 0 || (`minikube version` != *"minikube version: v0.27.0"*) ]];
then
if [ $? -eq 0]; then
if [[ $? -ne 0 || ($(minikube version) != *"minikube version: v0.27.0"*) ]]; then
if [ $? -eq 0 ]; then
echo "Deleting previous minikube cluster and updating minikube to v0.27.0"
minikube delete
fi
echo "Minikube version 0.27.0 is not installed. Installing it using curl."
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.27.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "Installation of Minikube version 0.27.0 failed. Please install it manually."
exit 1
else
Expand All @@ -114,12 +104,10 @@ fi

echo "Checking kubectl..."
kubectl --help > /dev/null
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "kubectl is not installed. Installing the lastest stable release..."
brew install kubectl
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "Installation of kubectl from brew fails. Please install it manually."
exit 1
else
Expand Down
14 changes: 6 additions & 8 deletions tools/run_shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ ISTIO_ROOT="$(cd "$(dirname "${TOOLS_DIR}")" && pwd -P)"

# See https://github.com/koalaman/shellcheck/wiki for details on each code's
# corresponding rule.
EXCLUDES="1009,"
EXCLUDES="${EXCLUDES}1020,"
EXCLUDES="${EXCLUDES}1054,"
EXCLUDES="1054,"
EXCLUDES="${EXCLUDES}1056,"
EXCLUDES="${EXCLUDES}1072,"
EXCLUDES="${EXCLUDES}1073,"
EXCLUDES="${EXCLUDES}1083,"
EXCLUDES="${EXCLUDES}1090,"
EXCLUDES="${EXCLUDES}1091,"
Expand Down Expand Up @@ -68,13 +64,15 @@ SH_FILES=$( \
-name '*.sh' -type f \
-not -path '*/vendor/*' \
-not -path '*/.git/*')
# All files not ending in .sh but containing a shebang.
# All files not ending in .sh but starting with a shebang.
SHEBANG_FILES=$( \
find "${ISTIO_ROOT}" \
-not -name '*.sh' -type f \
-not -path '*/vendor/*' \
-not -path '*/.git/*' -print0 \
| xargs -0 grep -l '^#!.*sh')
-not -path '*/.git/*' | \
while read f; do
head -n 1 "$f" | grep -q '^#!.*sh' && echo "$f";
done)
echo "${SH_FILES}" "${SHEBANG_FILES}" \
| xargs shellcheck --exclude="${EXCLUDES}"

0 comments on commit 772812a

Please sign in to comment.