utils(dep_tree2sql): Update to valid syntax, address shellcheck warnings #3547
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.
I incrementally updated the utils/dep_tree2sql.sh script first to address some easy shellcheck suggestions, but it ended up being a bit more touchy, so I made this a PR by itself.
The initial state of this script was that it wasn't completely working anymore in modern shells (bash in Ubuntu 22.04).
The way I proceeded: I made a single change, dumped the database to a SQL script (
pg_dump grass > dumpfile.sql
), checked the diff, and continued to a further change. I also explored the various example queries in the file at first, plus exploring the tables (since I was surprised some were empty tables, 16 in this case (see below)).Hence, it might be easier to review by checking each commit one by one instead of understanding the complete diff all at once.
The couple first commits didn't change the resulting database, as the first three find commands were erroring out because of the long deprecated find test
-perm +111
. Once I transformed it to the equivalent-perm /a+x
("any file that has the executable bit set for anybody"), the resulting SQL dump grew from 4.93 MB to 7.27 MB, since more deps were found. The number of empty tables is now 11.There is only one commit that effectively makes a small difference in the results outputted: replacing
find *
withfind ./*
. This makes all the paths for the.a
,.o
, and.so
found withfind
start with./
instead of nothing. I found the difference betweenfind .
andfind *
, but couldn't find the reason why 20 years ago (the furthest I could go back with the grass-legacy repo https://github.com/OSGeo/grass-legacy/blob/66914c9eb661b32031f493845c6694819cd41f89/tools/sql.sh) the author chosefind .
for the first 3, andfind *
for the others.find .
looks for hidden files, whilefind *
looks for visible contents. So I kept the*
.A remaining change that I intentionally left out, is the subshell surrounding the first three finds. I assume it was there since the LD_LIBRARY_PATH was assigned to, so to prevent affecting the current shell. But it has been commented out
The last commit of all is uniformizing the shell formatting with
My couple last shell contributions were made with that too, and some other PR is coming too.
In the end of this PR, I get the following output
Before this PR, I get the following: