-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Validate shell scripts with Shellcheck #418
base: master
Are you sure you want to change the base?
Conversation
Shellcheck says: ``` In eos-live-boot-overlayfs-setup line 17: if [ $? != 0 ]; then ^-- SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. In eos-live-boot-overlayfs-setup line 47: if [ $? == 0 ]; then ^-- SC2181 (style): Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. ```
Shellcheck says: ``` In eos-live-boot-overlayfs-setup line 24: echo ${persistent_loop} ^----------------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo "${persistent_loop}" ``` We know this will not be a problem in practice but it's not hard to placate shellcheck.
Tried to build it on OBS. The shellcheck alarms much more syntax issues. |
Interesting – it should be the same version of shellcheck and I added some logic to make the shellcheck check not fatal for certain files. |
Previously, shellcheck would warn: In eos-firstboot line 9: > /var/lib/eos-firstboot ^----------------------^ SC2188 (warning): This redirection doesn't have a command. Move to its command (or use 'true' as no-op). For more information: https://www.shellcheck.net/wiki/SC2188 -- This redirection doesn't have a c... This is intended to catch cases where the redirect was meant to apply to the command on the line before. In this case the usage is correct. Use `:`, which means the same as the `true` builtin: do nothing, successfully, with no output.
In eos-enable-zram line 5: if [ $# -lt 1 -o "$1" -lt 0 -o "$1" -gt 1 ]; then ^-- SC2166 (warning): Prefer [ p ] || [ q ] as [ p -o q ] is not well defined. ^-- SC2166 (warning): Prefer [ p ] || [ q ] as [ p -o q ] is not well defined. In eos-enable-zram line 17: echo $(($ram_size_kb * 3 / 2))K > /sys/block/zram0/disksize ^----------^ SC2004 (style): $/${} is unnecessary on arithmetic variables. For more information: https://www.shellcheck.net/wiki/SC2166 -- Prefer [ p ] || [ q ] as [ p -o q... https://www.shellcheck.net/wiki/SC2004 -- $/${} is unnecessary on arithmeti...
Thanks for the OBS test. I don't understand why the offending scripts are not being skipped in OBS. I think for now I'll pause this and occasionally nudge it forwards by fixing the warnings so that the list of scripts that are expected to fail can be removed. |
Currently all shell scripts found in the tree are at least syntax-checked by
bash -n
ordash -n
based on their shebang.But as I reviewed #417 I was suddenly gripped with the desire to run them all through
shellcheck
. This devolved into over-engineering the runner emitting TAP-formatted output and wiring up a TAP parser in Automake.Having done all this, I think it may be unnecessary, but here's the PR anyway.