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
Fixed bugs found by the ShellCheck linter #1457
Conversation
Very good work overall. Lots of minor shell ambiguities and spelling issues rectified. |
3d57010
to
93fe6bf
Compare
Good changes. I think the only nitpick left is the |
Hey. So, this is still too big for me to review. I'm also hesitant to spend time making changes that aren't (actual) bugs or new functionality. Every change has the potential to create new problem.... |
There are plenty of "actual" bugs here. For example, I quoted all occurrences of the You can see the ShellCheck output here (lines 1374-2490), which describes the most of the bugs in more detail. |
We really should fix this: For now it looks like this:
|
Thanks, I agree. I created this PR over 5 years ago now, but I would be happy to rebase and update it if there is a chance it could ever be merged. In addition to those issues in the Bash scripts, there are also many bugs in the Python code, which can be found with the Pylint and Ruff linters among others. I could create a separate PR for this, if there is any interest in fixing these bugs... For example, here are the counts of the potential issues identified by Ruff (almost half of these are autofixable):
|
My comment from 2018 still holds. It's hard for me to dedicate time to things that have no impact on functionality. The way to get the changes merged is to create smaller commits with one type of change per commit so that it's easy for me to understand what the changes are. Also if you call something a bug but then don't demonstrate how Mail-in-a-Box operates incorrectly, it's a show-stopper for review, because I'm not going to do the work to investigate a "bug" that turns out to be a code style preference. |
Thanks Josh for your response. I can try to break this up into more commits, but note that many of the issues can now be fixed automatically by just running a single command like: The term "bug" was used by ShellCheck to describe the type of issues that their linter detects, but I would be happy to use any alternative term that you prefer instead. For example, the term "error" is commonly used by other linters. As I explained above back in 2018, I would consider almost all of the issues detected to be actual bugs, as either they address cases where the scripts would currently fail or they replace depreciated syntax/commands that could be removed and thus break at any time. Removing the depreciated syntax and commands should help significantly in preparation for the next Ubuntu LTS upgrade, as this most likely when it would otherwise break. A few of the changes removed unnecessary/useless commands to simply the script and improve readability/performance. If you consider this to be a "code style preference", I could remove these changes in the update/rebase. I also manually fixed a few typos I noticed in the script documentation, which I can remove as well, as they are obviously the least important of these fixes. I am not sure your definition of "code style preference", but I purposely did not include anything in this PR that I thought could be considered opinionated, although I would be happy to remove any of the individual changes if you feel differently. I would want to further hold up fixing the many critical issues this PR addresses. I would highly encourage you to run ShellCheck yourself, as it explains each issue in more detail than I can in this PR. It also includes links to their Wiki, which explains each issue in even more detail, usually with examples and citations. For reference, here are the commands to run on Ubuntu and Debian: sudo apt update
sudo apt install shellcheck
shopt -s globstar
shellcheck -s bash **/*.sh (Note that this will miss a couple of scripts without the |
This file passes shellcheck now without errors. This paritally fixes mail-in-a-box#1457 - the former errors where: $ shellcheck setup/preflight.sh In setup/preflight.sh line 1: ^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. In setup/preflight.sh line 29: if [ $TOTAL_PHYSICAL_MEM -lt 490000 ]; then ^-----------------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: if [ "$TOTAL_PHYSICAL_MEM" -lt 490000 ]; then In setup/preflight.sh line 31: TOTAL_PHYSICAL_MEM=$(expr \( \( $TOTAL_PHYSICAL_MEM \* 1024 \) / 1000 \) / 1000) ^--^ SC2003 (style): expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]]. ^-----------------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: TOTAL_PHYSICAL_MEM=$(expr \( \( "$TOTAL_PHYSICAL_MEM" \* 1024 \) / 1000 \) / 1000) In setup/preflight.sh line 38: if [ $TOTAL_PHYSICAL_MEM -lt 750000 ]; then ^-----------------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: if [ "$TOTAL_PHYSICAL_MEM" -lt 750000 ]; then For more information: https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y... https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ... https://www.shellcheck.net/wiki/SC2003 -- expr is antiquated. Consider rewr...
This is just a starter - the question is, if this format |
ed72a0f
to
0c82b0f
Compare
@JoshData - As requested, I redid this PR, doing only a single type of fix per commit. Two of the fixes are each broken up into two separate commits, so there are a total of 17 fixes and 19 commits. Most of the commits only modify a few lines or less. Please let me know if you have any questions or if there is anything else you need me to do for this to be merged. |
This file passes shellcheck now without errors. This paritally fixes #1457 - the former errors where: $ shellcheck setup/preflight.sh In setup/preflight.sh line 1: ^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. In setup/preflight.sh line 29: if [ $TOTAL_PHYSICAL_MEM -lt 490000 ]; then ^-----------------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: if [ "$TOTAL_PHYSICAL_MEM" -lt 490000 ]; then In setup/preflight.sh line 31: TOTAL_PHYSICAL_MEM=$(expr \( \( $TOTAL_PHYSICAL_MEM \* 1024 \) / 1000 \) / 1000) ^--^ SC2003 (style): expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]]. ^-----------------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: TOTAL_PHYSICAL_MEM=$(expr \( \( "$TOTAL_PHYSICAL_MEM" \* 1024 \) / 1000 \) / 1000) In setup/preflight.sh line 38: if [ $TOTAL_PHYSICAL_MEM -lt 750000 ]; then ^-----------------^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: if [ "$TOTAL_PHYSICAL_MEM" -lt 750000 ]; then For more information: https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y... https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ... https://www.shellcheck.net/wiki/SC2003 -- expr is antiquated. Consider rewr...
Ooops. Thanks. But this PR now has some conflicts with the main branch. Can you resolve those? |
No problem. Yes, I will rebase this PR from the main branch. |
Thanks! I'm force-pushing to your branch to drop a few commits:
I also squashed a few while I was here. After I push I'll merge. Thanks for your patience! |
1012730
to
c7faccf
Compare
May I also suggest standardizing on a code formatter? And I propose using the standard one found in VSCode. |
Edit: This PR is now very outdated, but I would be happy to update it if there is ever interest in fixing these bugs.$[..]
and`..`
) and commands (such astempfile
).Outputs error messages to stderr.(Removed)cat
andecho
commands.pwd
command with Bash's$PWD
variable.Fixed minor spelling/capitalization errors in script documentation.(Removed)This pull request was originally part of #1435.
Closes #2342