-
Notifications
You must be signed in to change notification settings - Fork 994
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
install.sh: Remove bashisms and fix all other shellcheck warnings #851
Open
andersk
wants to merge
1
commit into
yarnpkg:master
Choose a base branch
from
andersk:shellcheck
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Deploy preview for yarnpkg ready! Built with commit bfd0fbc |
5635c77
to
bfd0fbc
Compare
ShellCheck (https://www.shellcheck.net/) 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 (info): 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 (info): Double quote to prevent globbing and word splitting. Did you mean: if echo "$version" | grep -qE "^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$"; then In install.sh line 24: printf "$red> Version number must match MAJOR.MINOR.PATCH.$reset\n" ^-- SC2059 (info): 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 (style): Use $(...) notation instead of legacy backticks `...`. Did you mean: tarball_tmp=$(mktemp -t yarn.tar.gz.XXXXXXXXXX) In install.sh line 33: yarn_verify_integrity $tarball_tmp ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: yarn_verify_integrity "$tarball_tmp" In install.sh line 35: printf "$cyan> Extracting to ~/.yarn...$reset\n" ^-- SC2059 (info): 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 (info): Double quote to prevent globbing and word splitting. Did you mean: tar zxf "$tarball_tmp" -C "$temp" In install.sh line 42: rm $tarball_tmp* ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: rm "$tarball_tmp"* In install.sh line 44: printf "$red> Failed to download $url.$reset\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 52: if [[ -z "$(command -v gpg)" ]]; then ^--------------------------^ SC3010 (warning): 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 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 57: if [ "$YARN_GPG" == "no" ]; then ^-- SC3014 (warning): In POSIX sh, == in place of = is undefined. In install.sh line 58: printf "$cyan> WARNING: Skipping GPG integrity check!$reset\n" ^-- SC2059 (info): 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 (info): 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 (info): 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 (info): Double quote to prevent globbing and word splitting. Did you mean: if gpg --verify "$1.asc" "$1"; then In install.sh line 74: printf "$green> GPG signature looks good$reset\n" ^-- SC2059 (info): 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 (info): 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 (info): 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 (info): 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 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 95: if [[ $YARN_PROFILE == *"fish"* ]]; then ^-----------------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined. In install.sh line 96: command fish -c 'set -U fish_user_paths $fish_user_paths ~/.yarn/bin' ^-- SC2016 (info): Expressions don't expand in single quotes, use double quotes for that. In install.sh line 97: printf "$cyan> We've added ~/.yarn/bin to your fish_user_paths universal variable\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 100: printf "$cyan> We've added the following to your $YARN_PROFILE\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 104: printf " $SOURCE_STR$reset\n" ^----------------------^ SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 107: version=`$HOME/.yarn/bin/yarn --version` || ( ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`. ^---^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: version=$("$HOME"/.yarn/bin/yarn --version) || ( In install.sh line 108: printf "$red> Yarn was installed, but doesn't seem to be working :(.$reset\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 112: printf "$green> Successfully installed Yarn $version! Please open another terminal where the \`yarn\` command will now be available.$reset\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 122: local DETECTED_PROFILE ^--------------------^ SC3043 (warning): In POSIX sh, 'local' is undefined. In install.sh line 124: local SHELLTYPE ^-------------^ SC3043 (warning): In POSIX sh, 'local' is undefined. In install.sh line 153: if [ ! -z "$DETECTED_PROFILE" ]; then ^-- SC2236 (style): Use -n instead of ! -z. In install.sh line 163: printf "${white}Installing Yarn!$reset\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 167: local latest_url ^--------------^ SC3043 (warning): In POSIX sh, 'local' is undefined. In install.sh line 168: local specified_version ^---------------------^ SC3043 (warning): In POSIX sh, 'local' is undefined. In install.sh line 169: local version_type ^----------------^ SC3043 (warning): In POSIX sh, 'local' is undefined. In install.sh line 172: specified_version=`curl -sS $latest_url` ^--------------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`. Did you mean: specified_version=$(curl -sS $latest_url) In install.sh line 179: specified_version=`curl -sS $latest_url` ^--------------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`. Did you mean: specified_version=$(curl -sS $latest_url) In install.sh line 183: specified_version=`curl -sS $latest_url` ^--------------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`. Did you mean: specified_version=$(curl -sS $latest_url) In install.sh line 184: version_type='latest' ^----------^ SC2034 (warning): version_type appears unused. Verify use (or export if used externally). In install.sh line 186: yarn_version=`yarn -V` ^-------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`. Did you mean: yarn_version=$(yarn -V) In install.sh line 187: yarn_alt_version=`yarn --version` ^--------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`. Did you mean: yarn_alt_version=$(yarn --version) In install.sh line 189: if [ "$specified_version" = "$yarn_version" -o "$specified_version" = "$yarn_alt_version" ]; then ^-- SC2166 (warning): Prefer [ p ] || [ q ] as [ p -o q ] is not well defined. In install.sh line 190: printf "$green> Yarn is already at the $specified_version version.$reset\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 193: printf "$yellow> $yarn_alt_version is already installed, Specified version: $specified_version.$reset\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 197: printf "$red> $HOME/.yarn already exists, possibly from a past Yarn install.$reset\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 198: printf "$red> Remove it (rm -rf $HOME/.yarn) and run this script again.$reset\n" ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 203: yarn_get_tarball $1 $2 ^-- SC2086 (info): Double quote to prevent globbing and word splitting. ^-- SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: yarn_get_tarball "$1" "$2" In install.sh line 209: read -p "$1 [y/N] " -n 1 -r ^-- SC3045 (warning): In POSIX sh, read -p is undefined. In install.sh line 211: if [[ ! $REPLY =~ ^[Yy]$ ]] ^----------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined. In install.sh line 213: printf "$red> Aborting$reset\n" ^----------------------^ SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo". In install.sh line 219: yarn_install $1 $2 ^-- SC2086 (info): Double quote to prevent globbing and word splitting. ^-- SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: yarn_install "$1" "$2" For more information: https://www.shellcheck.net/wiki/SC2034 -- version_type appears unused. Veri... https://www.shellcheck.net/wiki/SC2166 -- Prefer [ p ] || [ q ] as [ p -o q... https://www.shellcheck.net/wiki/SC3010 -- In POSIX sh, [[ ]] is undefined. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: