website icon indicating copy to clipboard operation
website copied to clipboard

install.sh: Remove bashisms and fix all other shellcheck warnings

Open andersk opened this issue 5 years ago • 1 comments

ShellCheck is very good at finding shell script quality issues. In this script it detects, among other things, several bash-specific constructs that actually fail on Debian and Ubuntu systems, which have /bin/sh symlinked to dash instead of bash.

Before this commit:

$ ./install.sh
…
./install.sh: 52: ./install.sh: [[: not found
./install.sh: 57: [: unexpected operator
…
./install.sh: 95: ./install.sh: [[: not found
…

$ shellcheck install.sh

In install.sh line 13:
  printf "$cyan> Downloading tarball...$reset\n"
         ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 21:
    if echo $version | grep -qE "^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$"; then
            ^------^ SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 24:
      printf "$red> Version number must match MAJOR.MINOR.PATCH.$reset\n"
             ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 31:
  tarball_tmp=`mktemp -t yarn.tar.gz.XXXXXXXXXX`
              ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.

In install.sh line 33:
    yarn_verify_integrity $tarball_tmp
                          ^----------^ SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 35:
    printf "$cyan> Extracting to ~/.yarn...$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 38:
    tar zxf $tarball_tmp -C "$temp"
            ^----------^ SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 42:
    rm $tarball_tmp*
       ^----------^ SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 44:
    printf "$red> Failed to download $url.$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 52:
  if [[ -z "$(command -v gpg)" ]]; then
     ^--------------------------^ SC2039: In POSIX sh, [[ ]] is undefined.

In install.sh line 53:
    printf "$yellow> WARNING: GPG is not installed, integrity can not be verified!$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 57:
  if [ "$YARN_GPG" == "no" ]; then
                   ^-- SC2039: In POSIX sh, == in place of = is undefined.

In install.sh line 58:
    printf "$cyan> WARNING: Skipping GPG integrity check!$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 62:
  printf "$cyan> Verifying integrity...$reset\n"
         ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 67:
    printf "$red> Could not download GPG signature for this Yarn release. This means the release can not be verified!$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 73:
  if gpg --verify "$1.asc" $1; then
                           ^-- SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 74:
    printf "$green> GPG signature looks good$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 76:
    printf "$red> GPG signature for this Yarn release is invalid! This is BAD and may mean the release has been tampered with. It is strongly recommended that you report this to the Yarn developers.$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 82:
  printf "$cyan> Adding to \$PATH...$reset\n"
         ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 87:
    printf "$red> Profile not found. Tried ${YARN_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 91:
    printf "> Append the following lines to the correct file yourself:$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 95:
      if [[ $YARN_PROFILE == *"fish"* ]]; then
         ^-----------------------------^ SC2039: In POSIX sh, [[ ]] is undefined.

In install.sh line 96:
        command fish -c 'set -U fish_user_paths $fish_user_paths ~/.yarn/bin'
                        ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

In install.sh line 102:
    printf "$cyan> We've added the following to your $YARN_PROFILE\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 104:
    printf "   $SOURCE_STR$reset\n"
           ^----------------------^ SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 106:
    version=`$HOME/.yarn/bin/yarn --version` || (
            ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
             ^---^ SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 107:
      printf "$red> Yarn was installed, but doesn't seem to be working :(.$reset\n"
             ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 111:
    printf "$green> Successfully installed Yarn $version! Please open another terminal where the \`yarn\` command will now be available.$reset\n"
           ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 121:
  local DETECTED_PROFILE
  ^--------------------^ SC2039: In POSIX sh, 'local' is undefined.

In install.sh line 123:
  local SHELLTYPE
  ^-------------^ SC2039: In POSIX sh, 'local' is undefined.

In install.sh line 162:
  printf "${white}Installing Yarn!$reset\n"
         ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 165:
    if which yarn; then
       ^---^ SC2230: which is non-standard. Use builtin 'command -v' instead.

In install.sh line 166:
      local latest_url
      ^--------------^ SC2039: In POSIX sh, 'local' is undefined.

In install.sh line 167:
      local specified_version
      ^---------------------^ SC2039: In POSIX sh, 'local' is undefined.

In install.sh line 168:
      local version_type
      ^----------------^ SC2039: In POSIX sh, 'local' is undefined.

In install.sh line 171:
        specified_version=`curl -sS $latest_url`
                          ^--------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.

In install.sh line 178:
        specified_version=`curl -sS $latest_url`
                          ^--------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.

In install.sh line 182:
        specified_version=`curl -sS $latest_url`
                          ^--------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.

In install.sh line 183:
        version_type='latest'
        ^----------^ SC2034: version_type appears unused. Verify use (or export if used externally).

In install.sh line 185:
      yarn_version=`yarn -V`
                   ^-------^ SC2006: Use $(...) notation instead of legacy backticked `...`.

In install.sh line 186:
      yarn_alt_version=`yarn --version`
                       ^--------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.

In install.sh line 188:
      if [ "$specified_version" = "$yarn_version" -o "$specified_version" = "$yarn_alt_version" ]; then
                                                  ^-- SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

In install.sh line 189:
        printf "$green> Yarn is already at the $specified_version version.$reset\n"
               ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 192:
      	printf "$yellow> $yarn_alt_version is already installed, Specified version: $specified_version.$reset\n"
               ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 196:
      printf "$red> $HOME/.yarn already exists, possibly from a past Yarn install.$reset\n"
             ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 197:
      printf "$red> Remove it (rm -rf $HOME/.yarn) and run this script again.$reset\n"
             ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 202:
  yarn_get_tarball $1 $2
                   ^-- SC2086: Double quote to prevent globbing and word splitting.
                      ^-- SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 208:
  read -p "$1 [y/N] " -n 1 -r
       ^-- SC2039: In POSIX sh, read -p is undefined.

In install.sh line 210:
  if [[ ! $REPLY =~ ^[Yy]$ ]]
     ^----------------------^ SC2039: In POSIX sh, [[ ]] is undefined.

In install.sh line 212:
    printf "$red> Aborting$reset\n"
           ^----------------------^ SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In install.sh line 218:
yarn_install $1 $2
             ^-- SC2086: Double quote to prevent globbing and word splitting.
                ^-- SC2086: Double quote to prevent globbing and word splitting.

andersk avatar Aug 03 '18 02:08 andersk

Deploy preview for yarnpkg ready!

Built with commit bfd0fbc2d8ec7f159f6d08c8eafe71bd1b8702d1

https://deploy-preview-851--yarnpkg.netlify.com

Haroenv avatar Aug 03 '18 02:08 Haroenv