Shellcheck


#1

Would it be possible to add ShellCheck to the default build?

Or Cabal to make it easier to install.

I’m using the new Trusty 14.04 container image.


#2

:+1: I’d appreciate shellcheck pre-installed. I haven’t figured out how to get cabal to cache it properly.


#3

Right now I’m trying https://github.com/Originate/git-town/blob/c6708385bbfe8b890c8ddb9e09ff0c991a9f3129/bin/circleci-install-shellcheck

in a file called bin/setup_ci that runs like https://github.com/Originate/git-town/blob/c6708385bbfe8b890c8ddb9e09ff0c991a9f3129/circle.yml

machine:
  environment:
    PATH: $HOME/.cabal/bin/:$PATH
dependencies:
  # Cache ShellCheck for subsequent builds
  cache_directories:
    - "~/.cabal"
  post:
    - bin/setup_ci
test:
  override:
    - bin/test
#!/usr/bin/env bash
set -e

#
# Installs ShellCheck on CircleCI if necessary.
#


# the version of shellcheck to be installed
VERSION=0.4.1

# path to the cached ShellCheck binary
BIN_PATH=~/.cabal/bin/shellcheck


# Installs the current version of ShellCheck
function install_shellcheck {
  echo "Installing ShellCheck $VERSION"
  cabal update --verbose=0
  cabal install --verbose=0 shellcheck-$VERSION
}


function currently_installed_shellcheck_version {
  $BIN_PATH -V | grep version: | cut -d: -f2 | awk '{print $1}'
}


if [ ! -f $BIN_PATH ]; then
  echo "No ShellCheck found"
  install_shellcheck
else
  EXISTING_VERSION=$(currently_installed_shellcheck_version)
  if [ "$VERSION" != "$EXISTING_VERSION" ]; then
    echo "The latest version of ShellCheck is $VERSION, CircleCI has $EXISTING_VERSION. Upgrading..."
    rm -rf $BIN_PATH
    install_shellcheck
  else
    echo "Using cached ShellCheck $EXISTING_VERSION"
  fi
fi

#4

Shellcheck is in Trusty backports, so I’m fetching it from there because that involves fewer moving parts and fits my use-cases more - ymmv!

sudo apt-add-repository deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe
sudo apt-get update
sudo apt-get install shellcheck

(I’m sure I could do something fancy with apt pinning so I only pick up shellcheck from backports, but this is the core of what you need)


#5

I had trouble getting that to work but this worked for me

- sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe"
- sudo apt-get update
- sudo apt-get install -t trusty-backports shellcheck

The apt-add-repository failed as the full path needs to be quoted.
Installing needed a way to designate using a backport.


#6