Skip to content
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

Shellcheck and various other oddities #15

Merged
merged 34 commits into from
Mar 19, 2024
Merged

Conversation

StaticRocket
Copy link
Contributor

@StaticRocket StaticRocket commented Mar 10, 2024

Waste a Saturday fixing shellcheck warnings.

I've got another series in progress that reworks the patch logic since the application process is the same no matter what path is taken. Unfortunately I got distracted trying to simplify the current argument parsing as that's a little odd.

Eventually I'll see if I can integrate my common entrypoint script to cut out the image generation segment in kp_common.

Argument to -z is always false due to literal strings.

Signed-off-by: Randolph Sapp <[email protected]>
Using "$@" will prevent unnecessary splitting of quoted parameters. For
instance, if the following parameter was passed previously: "-a 'hello
world'" it would be split into "-a" "hello" "world" which could break
things later in processing.

The kernel_patch_verify script will have to be reworked to deal with
this independently as a lot of functions inherently rely on splitting
for handling arrays.

Signed-off-by: Randolph Sapp <[email protected]>
Paths mentioned in the `PATH` env variable should not end with `/`.

Signed-off-by: Randolph Sapp <[email protected]>
Fix shellcheck warning about word splitting by making the split
explicit.

Signed-off-by: Randolph Sapp <[email protected]>
Use $(...) notation instead of legacy backticks `...`.

Signed-off-by: Randolph Sapp <[email protected]>
Split the current `download_and_install_armgcc` function into a
`download_and_install_armgcc_64` and `download_and_install_armgcc_32`.

Signed-off-by: Randolph Sapp <[email protected]>
Standardize all functions on the use of FILE and URL variables.

Signed-off-by: Randolph Sapp <[email protected]>
Paths mentioned in the `PATH` env variable should not end with `/`.

Signed-off-by: Randolph Sapp <[email protected]>
Use $(...) notation instead of legacy backticks `...`.

Signed-off-by: Randolph Sapp <[email protected]>
Fix word splitting issues that may arrise from docker mount parameters
and other variables.

Signed-off-by: Randolph Sapp <[email protected]>
Split the common code out into a file both scripts source.

Signed-off-by: Randolph Sapp <[email protected]>
Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Signed-off-by: Randolph Sapp <[email protected]>
Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

Signed-off-by: Randolph Sapp <[email protected]>
Use $(...) notation instead of legacy backticks `...`.

Also fix the arithmetic sections.

Signed-off-by: Randolph Sapp <[email protected]>
Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.

Signed-off-by: Randolph Sapp <[email protected]>
Use printf and some short templates to remove some redundant sections.

Signed-off-by: Randolph Sapp <[email protected]>
Use static strings for the grep expressions not using variables. Make
sure some reserved characters are escaped properly.

Signed-off-by: Randolph Sapp <[email protected]>
These instances of subshell execution have ((, which is the starting
parameter for arithmetic operations. Make sure everything's padded well
enough to prevent misinterpretation.

Shells disambiguate (( differently or not at all. For subshell, add
spaces around ( . For ((, fix parsing errors.

Signed-off-by: Randolph Sapp <[email protected]>
Use glob instead of ls and print the files we get from that instead of
attempting to reindexing them.

Signed-off-by: Randolph Sapp <[email protected]>
I know right now docker ignores "-v : " but I do not want to see what
happens if this ever changes. Besides, we can't do anything if we're not
working in a git directory anyway.

Signed-off-by: Randolph Sapp <[email protected]>
This just pruned stopped containers and dangling images before removing
the built container. Use the official commands for these operations.

Signed-off-by: Randolph Sapp <[email protected]>
Quote everything currently not relying on word splitting.

Signed-off-by: Randolph Sapp <[email protected]>
Implied that the script exits 0 by default. With this shellcheck
considers some of the code unreachable. Drop it so we can check on
things.

Signed-off-by: Randolph Sapp <[email protected]>
Replace all of the loose parameter passing with strict array packing and
unpacking.

Signed-off-by: Randolph Sapp <[email protected]>
To redirect stdout+stderr, 2>&1 must be last

Signed-off-by: Randolph Sapp <[email protected]>
Cat is really only good for concatenating files. If we only want to read
files we can use bash and printf directly. More keystrokes but faster at
runtime than cat.

Signed-off-by: Randolph Sapp <[email protected]>
Use -print0 and -0 when piping from find into xargs.

Signed-off-by: Randolph Sapp <[email protected]>
Avoid x-prefix in comparisons as it no longer serves a purpose.

Signed-off-by: Randolph Sapp <[email protected]>
egrep is non-standard and deprecated. Use grep -E instead.

Signed-off-by: Randolph Sapp <[email protected]>
Reduce the number of redirects with subshell execution.

Signed-off-by: Randolph Sapp <[email protected]>
Read without -r will mangle backslashes. We don't have to let wc count
characters in a variable.

Signed-off-by: Randolph Sapp <[email protected]>
@StaticRocket
Copy link
Contributor Author

I'd like to thank the Ballmer Peak for this hellish PR. Have fun!

@StaticRocket
Copy link
Contributor Author

Got 3 more planned reworks for this tool after this series:

  1. Use my auto id remap entrypoint that's podman compliant as well as docker compliant. Scrap the current logic for creating and deleting that new tag that's currently used to achieve the same thing.
  2. Tweak the compose file to mitigate committed files for each step
  3. Move the tool building logic into the Dockerfile directly, or use a bind mount to prevent the build scripts from being committed

@nmenon nmenon merged commit 39bdedb into nmenon:master Mar 19, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants