webi-installers icon indicating copy to clipboard operation
webi-installers copied to clipboard

Fix simple `shellcheck` complaints (adding quotes to variables, etc)

Open coolaj86 opened this issue 4 years ago • 5 comments

How to see which files have warnings:

shellcheck -W 100 -e SC2034,SC2129,SC2069,SC2154,SC2164,SC2016,SC2001 */*.sh

Example output

In _webi/bootstrap.sh line 12:
    printf "Thanks for using webi to install '\e[32m${WEBI_PKG:-}\e[0m' on '\e[31m$(uname -s)/$(uname -m)\e[0m'.\n"
           ^-- SC2059 (info): Don't use variables in the printf format string. Use printf '..%s..' "$foo".


In _webi/example_install_safe_copy.sh line 6:
    if [ -n "$(command -v rsync 2> /dev/null | grep rsync)" ]; then
         ^-- SC2143 (style): Use grep -q instead of comparing output with [ -n .. ].


In arc/install.sh line 24:
        mkdir -p "$(dirname $pkg_src_cmd)"
                            ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Example correction

In _webi/bootstrap.sh line 12:
    printf "Thanks for using webi to install '\e[32m%s\e[0m' on '\e[31m%s/%s\e[0m'.\n" \
        "${WEBI_PKG:-}" "$(uname -s)" "$(uname -m)"

In _webi/example_install_safe_copy.sh line 6:
    if command -v rsync 2> /dev/null | grep -q rsync; then

In arc/install.sh line 24:
        mkdir -p "$(dirname "${pkg_src_cmd}")"

Level of Expertise Needed

Anyone with beginner bash experience could pick one (or more) of these warnings to fix across the many files in which they exist.

Warnings that need fixing:

  • [ ] SC2046 -- Quote this to prevent word splitt...
  • [ ] SC2059 -- Don't use variables in the printf...
  • [ ] SC2086 -- Double quote to prevent globbing ...
  • [ ] SC2001 -- See if you can use ${variable//se...
  • [ ] SC2005 -- Useless echo? Instead of 'echo $(...
    • [x] #460
    • [ ] #466
  • [ ] SC2143 -- Use ! grep -q instead of comparin...

coolaj86 avatar Jan 26 '22 09:01 coolaj86

Hey, @coolaj86, I'm a first-time contributor to open source. Can you please assign me this issue?

saikmusunuri avatar Jan 26 '22 21:01 saikmusunuri

@saikmusunuri Yes.

Are you familiar with bash? Do you understand what needs to be done?

coolaj86 avatar Jan 26 '22 21:01 coolaj86

Thank you I'm not entirely familiar with bash, but I have a guide who will support me on this issue.

saikmusunuri avatar Jan 26 '22 22:01 saikmusunuri

Hello!

I added the https://github.com/webinstall/webi-installers/pull/421. I added the shellcheck disable=SC2154 and I replaced echo $(cmd) with cmd and done some stuff ;) .

I tested of the docker instance with Ubuntu and some of my prod mac ;)

I did not test:

  • Gitea
  • vps-addswap
  • vps-utilsc

Command:

export PACK=ffmpeg; npm install; node _webi/test.js ./$PACK; rm -rf ~/.local/bin/$PACK* ~/.local/opt/$PACK*; chmod +x ./install-$PACK.sh ; ./install-$PACK.sh; rm -rf ./install-$PACK.*

Thank you! y0rune (Marcin)

y0rune avatar Mar 10 '22 21:03 y0rune

Thanks for this. Sorry it's been getting stale.

1. Could you make the commits more atomic?


* removing all of the `echo`s is one commit


2. We don't need exports, and we don't want bash-isms

3. Change `/bin/bash` to `/bin/sh` and remove `function` as its own commit
  • [x] removing all of the echos is one commit - https://github.com/webinstall/webi-installers/pull/460

y0rune avatar Aug 08 '22 21:08 y0rune

SC2059,SC2143,SC2112,SC3010,SC3014,SC3028,SC3037,SC3044

Bash-isms that need to be addressed:

SC2112: 'function' keyword is non-standard. Delete it.
SC3010: In POSIX sh, [[ ]] is undefined.
SC3014: In POSIX sh, == in place of = is undefined.
SC3037: In POSIX sh, echo flags are undefined.
SC3044: In POSIX sh, 'pushd'/'popd' is undefined.

Bash-isms that we can perhaps work around:

# In vps-addswap we need to figure out if we need to sudo or not
SC3028: In POSIX sh, EUID/UID is undefined.

# not sure what to do here...
# https://stackoverflow.com/a/38557313/151312
SC3045: In POSIX sh, read -s is undefined.

Optimizations we can apply later:

SC2059: Don't use variables in the printf format string. Use printf '..%s..' "$foo".
SC2143: Use ! grep -q / grep -q instead of comparing output with [ -n/-z .. ].

coolaj86 avatar Aug 15 '22 21:08 coolaj86

I'm going to close this out for now and open a new issue for the remaining warnings and style fixes.

coolaj86 avatar Aug 21 '22 08:08 coolaj86