Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add shellcheck to validate shell script #1437

Closed

Conversation

allencloud
Copy link
Collaborator

@allencloud allencloud commented May 30, 2018

Signed-off-by: Allen Sun [email protected]

Ⅰ. Describe what this PR did

use ShellCheck (https://github.com/koalaman/shellcheck) to check the validateness of shell scripts in pouch repo

Ⅱ. Does this pull request fix one issue?

none, this pr enhances the validation of project files.

Ⅲ. Describe how you did it

use ShellCheck (https://github.com/koalaman/shellcheck) to check the validateness
I installed the shellcheck via apt-get install shellcheck.
Also, we add a dockerfile for the image pouchlint:v0.1.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@allencloud
Copy link
Collaborator Author

This PR fails to pass the shellcheck since there are so many incorrect format in shell script files. Could you help to finish this? @ZouRui89

#!/bin/bash -eo pipefail
find ./ -name "*.sh" | grep -v vendor | grep -v extra | xargs shellcheck

In ./hack/make.sh line 9:
cd $DIR/
   ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 22:
	[ ! -d $POUCHTOPDIR ] && mkdir -p $POUCHTOPDIR
               ^-- SC2086: Double quote to prevent globbing and word splitting.
                                          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 23:
	ln -sf $DIR/ $SOURCEDIR
               ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 63:
			https://github.com/containerd/containerd/releases/download/v1.0.3/containerd-1.0.3.linux-amd64.tar.gz -P $TMP
                                                                                                                                 ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 64:
		tar xf $TMP/containerd-1.0.3.linux-amd64.tar.gz -C $TMP &&
                       ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 65:
			cp -f $TMP/bin/* /usr/local/bin/
                              ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 95:
		sh -x $DIR/hack/install_lxcfs_on_centos.sh
                      ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 123:
				https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.1.tar.gz -P $TMP
                                                                                                                    ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 124:
			tar xf $TMP/util-linux-2.24.1.tar.gz -C $TMP && 
                               ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 125:
				cd $TMP/util-linux-2.24.1
                                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 130:
			cd $DIR/
                           ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 160:
	cp -f $DIR/pouch $DIR/pouchd /usr/local/bin/
              ^-- SC2086: Double quote to prevent globbing and word splitting.
                         ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 169:
		docker run --rm -v $(pwd):$SOURCEDIR $IMAGE bash -c "make check"
                                   ^-- SC2046: Quote this to prevent word splitting.


In ./hack/make.sh line 172:
		docker run --rm -v $(pwd):$SOURCEDIR $IMAGE \
                                   ^-- SC2046: Quote this to prevent word splitting.


In ./hack/make.sh line 173:
			bash -c "make build"  >$TMP/build.log ||
                                               ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 174:
			{ echo "make build log:"; cat $TMP/build.log; return 1; }
                                                      ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 175:
		install_pouch  >$TMP/install.log ||
                                ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 176:
			{ echo "install pouch log:"; cat $TMP/install.log; return 1; }
                                                         ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 179:
		docker run --rm -v $(pwd):$SOURCEDIR $IMAGE \
                                   ^-- SC2046: Quote this to prevent word splitting.


In ./hack/make.sh line 184:
		env PATH=$GOROOT/bin:$PATH $SOURCEDIR/hack/cri-test/test-cri.sh
                         ^-- SC2086: Double quote to prevent globbing and word splitting.
                                     ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 191:
		docker run --rm -v $(pwd):$SOURCEDIR \
                                   ^-- SC2046: Quote this to prevent word splitting.


In ./hack/make.sh line 200:
				--lxcfs=/usr/bin/lxcfs > $TMP/log 2>&1 &
                                                         ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 202:
			pouchd --debug > $TMP/log 2>&1 &
                                         ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 215:
				cat $TMP/log 
                                    ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 226:
		cp -rf $DIR/test/tls /tmp/
                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 229:
		$DIR/test/integration-test -test.v -check.v ||
                ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 230:
			{ echo "pouch daemon log:"; cat $TMP/log; return 1; } 
                                                        ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/make.sh line 248:
	if [[ $# < 1 ]]; then
                 ^-- SC2071: < is for string comparisons. Use -lt instead.


In ./hack/make.sh line 254:
	for target in ${targets[@]}; do
                      ^-- SC2068: Double quote array expansions, otherwise they're like $* and break on spaces.


In ./hack/make.sh line 255:
		target $target
                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-utils.sh line 18:
. ${ROOT}/versions
  ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-utils.sh line 24:
POUCH_SOCK=/var/run/pouchcri.sock
^-- SC2034: POUCH_SOCK appears unused. Verify it or export it.


In ./hack/cri-test/test-utils.sh line 38:
  containerd_pid_command=`pgrep containerd`
                         ^-- SC2006: Use $(..) instead of legacy `..`.


In ./hack/cri-test/test-utils.sh line 41:
    keepalive "/usr/local/bin/containerd" ${RESTART_WAIT_PERIOD} &> ${report_dir}/containerd.log &
                                          ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                    ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-utils.sh line 49:
  pouch_pid_command=`pgrep pouchd`
                    ^-- SC2006: Use $(..) instead of legacy `..`.


In ./hack/cri-test/test-utils.sh line 53:
	  ${RESTART_WAIT_PERIOD} &> ${report_dir}/pouch.log &
          ^-- SC2086: Double quote to prevent globbing and word splitting.
                                    ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-utils.sh line 74:
  echo ${command}
       ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-utils.sh line 78:
    sleep ${wait_period}
          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 20:
source $(dirname "${BASH_SOURCE[0]}")/test-utils.sh
       ^-- SC2046: Quote this to prevent word splitting.


In ./hack/cri-test/test-cri.sh line 45:
git clone https://github.com/containernetworking/plugins $GOPATH/src/github.com/containernetworking/plugins
                                                         ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 46:
cd $GOPATH/src/github.com/containernetworking/plugins
   ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 90:
if [ ! -x "$(command -v ${CRITEST})" ]; then
                        ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 92:
  cd ${GOPATH}/src/${CRITOOL_PKG}
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 94:
  git checkout ${CRITOOL_VERSION}
               ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 97:
which ${CRITEST}
      ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 99:
mkdir -p ${REPORT_DIR}
         ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 100:
test_setup ${REPORT_DIR}
           ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/cri-test/test-cri.sh line 103:
sudo env PATH=${PATH} GOPATH=${GOPATH} ${CRITEST} --runtime-endpoint=${POUCH_SOCK} --focus="${CRI_FOCUS}" --ginkgo-flags="--skip=\"${CRI_SKIP}\"" validation
              ^-- SC2086: Double quote to prevent globbing and word splitting.
                             ^-- SC2086: Double quote to prevent globbing and word splitting.
                                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/vagrant/bootstrap.sh line 34:
    echo 'export GOENV_ROOT="$HOME/.goenv"' >> $PROFILE
    ^-- SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects.
         ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.
                                               ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/vagrant/bootstrap.sh line 35:
    echo 'export PATH="$GOENV_ROOT/bin:$PATH"' >> $PROFILE
         ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.
                                                  ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/vagrant/bootstrap.sh line 36:
    echo 'eval "$(goenv init -)"' >> $PROFILE
         ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.
                                     ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/vagrant/bootstrap.sh line 37:
    echo 'export GOPATH="/go"' >> $PROFILE
                                  ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/vagrant/bootstrap.sh line 39:
    $HOME/.goenv/bin/goenv install $GOVERSION
    ^-- SC2086: Double quote to prevent globbing and word splitting.
                                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/vagrant/bootstrap.sh line 40:
    $HOME/.goenv/bin/goenv global $GOVERSION
    ^-- SC2086: Double quote to prevent globbing and word splitting.
                                  ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/generate-swagger-models.sh line 10:
swagger generate model -f $DIR/../apis/swagger.yml -t $DIR/../apis -m types
                          ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                      ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/package.sh line 27:
pushd $DIR
      ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/package.sh line 35:
	docker build --network host -t pouch:rpm -f $DIR/hack/package/rpm/centos-7/Dockerfile.x86_64 .
                                                    ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/package.sh line 41:
		-v $KEYDIR:/root/rpm \
                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/package.sh line 48:
	docker build --network host -t pouch:deb -f $DIR/hack/package/deb/ubuntu-xenial/Dockerfile.x86_64 .
                                                    ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/package.sh line 53:
		-v $KEYDIR/:/root/deb \
                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/deb/build.sh line 5:
TMP=$(mktemp -d /tmp/pouch.XXXXXX)
^-- SC2034: TMP appears unused. Verify it or export it.


In ./hack/package/deb/build.sh line 45:
gpg -abs --default-key $DEFAULT_GPG_KEY -o Release.gpg Release
                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/deb/build.sh line 46:
gpg --clearsign --default-key $DEFAULT_GPG_KEY -o InRelease Release
                              ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 16:
[ -d $POUCHDIR ] || mkdir -p $POUCHDIR
     ^-- SC2086: Double quote to prevent globbing and word splitting.
                             ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 18:
[ -d $BINDIR ] || mkdir -p $BINDIR
     ^-- SC2086: Double quote to prevent globbing and word splitting.
                           ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 20:
[ -d $LXC_DIR ] || mkdir -p $LXC_DIR
     ^-- SC2086: Double quote to prevent globbing and word splitting.
                            ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 27:
LICENSE='Apache License 2.0'
^-- SC2034: LICENSE appears unused. Verify it or export it.


In ./hack/package/rpm/build.sh line 29:
CATEGORY='Tools/Pouch'
^-- SC2034: CATEGORY appears unused. Verify it or export it.


In ./hack/package/rpm/build.sh line 31:
MAINTAINER='Pouch [email protected]'
^-- SC2034: MAINTAINER appears unused. Verify it or export it.


In ./hack/package/rpm/build.sh line 32:
VENDOR='Pouch'
^-- SC2034: VENDOR appears unused. Verify it or export it.


In ./hack/package/rpm/build.sh line 33:
SUMMARY='The open-source reliable application container engine.'
^-- SC2034: SUMMARY appears unused. Verify it or export it.


In ./hack/package/rpm/build.sh line 36:
function build_lxcfs ()
^-- SC2112: 'function' keyword is non-standard. Delete it.


In ./hack/package/rpm/build.sh line 38:
    pushd $LXC_DIR
    ^-- SC2039: In POSIX sh, 'pushd' is not supported.
          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 42:
    make install DESTDIR=$LXC_DIR > /dev/null 2>&1
                         ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 43:
    popd
    ^-- SC2039: In POSIX sh, 'popd' is not supported.


In ./hack/package/rpm/build.sh line 47:
function build_pouch()
^-- SC2112: 'function' keyword is non-standard. Delete it.


In ./hack/package/rpm/build.sh line 51:
    wget --quiet https://github.com/containerd/containerd/releases/download/v1.0.3/containerd-1.0.3.linux-amd64.tar.gz -P $TMP
                                                                                                                          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 52:
    tar xf $TMP/containerd-1.0.3.linux-amd64.tar.gz -C $TMP && cp -f $TMP/bin/* $BINDIR/
           ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                       ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                     ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                                ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 56:
    wget --quiet https://github.com/alibaba/runc/releases/download/v1.0.0-rc4-1/runc.amd64 -P $BINDIR/
                                                                                              ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 57:
    chmod +x $BINDIR/runc.amd64
             ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 58:
    mv $BINDIR/runc.amd64 $BINDIR/runc
       ^-- SC2086: Double quote to prevent globbing and word splitting.
                          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 62:
    pushd $BASEDIR/pouch
    ^-- SC2039: In POSIX sh, 'pushd' is not supported.


In ./hack/package/rpm/build.sh line 63:
    make install DESTDIR=$POUCHDIR
                         ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 64:
    popd
    ^-- SC2039: In POSIX sh, 'popd' is not supported.


In ./hack/package/rpm/build.sh line 67:
function build_rpm ()
^-- SC2112: 'function' keyword is non-standard. Delete it.


In ./hack/package/rpm/build.sh line 69:
    pushd $MOUNTDIR
    ^-- SC2039: In POSIX sh, 'pushd' is not supported.


In ./hack/package/rpm/build.sh line 74:
    popd
    ^-- SC2039: In POSIX sh, 'popd' is not supported.


In ./hack/package/rpm/build.sh line 82:
          -v $VERSION \
             ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 83:
          --iteration $ITERATION \
                      ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 84:
          -a $ARCHITECTURE \
             ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 107:
          $BINDIR/=/usr/local/bin/ \
          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 109:
          $LXC_DIR/usr/local/bin/lxcfs=/usr/bin/lxcfs \
          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 110:
          $LXC_DIR/usr/local/lib/lxcfs/liblxcfs.so=/usr/lib64/liblxcfs.so \
          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 111:
          $LXC_DIR/usr/local/share/=/usr/share
          ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/build.sh line 115:
function main()
^-- SC2112: 'function' keyword is non-standard. Delete it.


In ./hack/package/rpm/scripts/after-remove.sh line 1:
systemctl daemon-reload > /dev/null 2>&1
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.


In ./hack/package/rpm/scripts/after-remove.sh line 2:
if [ $1 -ge 1 ] ; then
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/scripts/before-install.sh line 1:
if [ "$1" -gt 0 ] ; then
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.


In ./hack/package/rpm/scripts/after-install.sh line 1:
if [ $1 -eq 1 ] ; then
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/scripts/before-remove.sh line 1:
if [ $1 -eq 0 ] ; then
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/package/rpm/scripts/after-trans.sh line 1:
if [ $1 -ge 0 ] ; then
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In ./hack/install_lxcfs_on_centos.sh line 8:
yes | yum install fuse-devel.$(uname -p)
                             ^-- SC2046: Quote this to prevent word splitting.


In ./hack/install_lxcfs_on_centos.sh line 9:
yes | yum install pam-devel.$(uname -p)
                            ^-- SC2046: Quote this to prevent word splitting.


In ./hack/install_lxcfs_on_centos.sh line 10:
yes | yum install fuse.$(uname -p)
                       ^-- SC2046: Quote this to prevent word splitting.


In ./hack/install_lxcfs_on_centos.sh line 13:
trap "rm -rf $TMP" EXIT
             ^-- SC2064: Use single quotes, otherwise this expands now rather than when signalled.


In ./hack/install_lxcfs_on_centos.sh line 15:
cd $TMP &&
   ^-- SC2086: Double quote to prevent globbing and word splitting.

@zhuangqh
Copy link
Contributor

Let me help pouch to pass the shellcheck. 😄 @allencloud @ZouRui89

@allencloud
Copy link
Collaborator Author

Let me help pouch to pass the shellcheck.

That is so good for you to help. Maybe @ZouRui89 could help provide some guidance if there is more issues happen.

@allencloud
Copy link
Collaborator Author

allencloud commented May 31, 2018

You can do this to base on my commit, @zhuangqh :

git fetch upstream pull/1437/head:add-shellcheck
git checkout add-shellcheck
(update the shell script to fix issues)
git commit -s -m "fix: correct shel script format via shell check reports"
git push -f origin add-shellcheck
(create a brand-new pr and I will close this one)

@allencloud
Copy link
Collaborator Author

I think this part has already been covered in #1447. So I am closing it.

@allencloud allencloud closed this May 31, 2018
@allencloud allencloud deleted the add-shellcheck branch June 5, 2018 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants