-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
refactoring: split helper functions into smaller scripts #2420
Conversation
The SSL configuration function is rather large. Outsourcing it provides the opportunity to run the function itself without sourcing the whole `setup-stack.sh`.
Some difficulties on the way when it comes to changing the certiicate files led to another approach. The file is briefly changed on the host to see whether the changes are picked up.
Due to the changes in #2401 and the chages introduced here, `check-for-changes.sh` needs just a little bit longer.
The function now only computes what it ought to, and not more. This makes it a bit more efficient and less prone to problems.
The functions concerned with SSL/TLS setup were moved to `target/scripts/helpers/ssl.sh` because they actaully belong there. This is a non-issue as they are properly sourced by `index.sh` in `target/scripts/helpers/` anyway. This is a proper seperation of concerns.
This commit reverts a change previously introduced (that may got us some false positives). Furthermore, a link was added for a "TODO" that can be solved more easily in the future once these changes are resolved. And the line splitting is now less aggressive.
The function was revised again for better maintainability and readability. A second "staging" array was introduced which does a bit of the heavy lifting when it comes to adding the correct files for detecting changes. A missing `+` was added.
The `helper-functions.sh` script shall be splitted in the future. These changes take the first step in splitting the file for SSL related functions.
`source` can be used like `.`, but is idiomatic to Bash. I think it offers better readability though, and one instantly recognizes that a script is sourced here.
Maybe put it as draft then 😄 |
Just mark it as draft, until finished 😉 That way it's easier for the other maintainer to know, when to start reviewing. Edit: @wernerfred was faster 😆 |
I was just heading for lunch, the PR itself is finished and ready for review (I just didn't have enough time to write a proper description) 😆😆😆 That's why I did not mark it as a draft :) |
Additionally added more concrete names to scripts references.
Also fixed a global renaming issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
I was under the impression that you usually want a blank line at the end of a file? EDIT: There's a few examples here for why you might want to keep empty line at end of files. Similar reason covered here noting many editors with feature to ensure the empty line on file save. And another citing roughly the same thing in a python community, but uses I don't quite get the benefit of dropping them, but keen to know if there's a reason beyond preference 😅 FWIW, our own lint rules seem to prefer the empty line at end of file: docker-mailserver/.editorconfig Line 12 in 358df6a
In files I've worked on, I also have a habit of adding a double blank to better separate context/bounds visually, such as big functions which have their own single blank lines in the function body. That's just a personal preference thing so I don't mind that it was stripped, consistency is all good 👍 I tend to do similar for tests too, such as in the letsencrypt one I think I used it to group related functions and tests, although a recent PR may have also stripped that away. |
I think you mixed things up. There is a difference between a final new line, which as you stated is best-practice. But there is no good reason for an empty line. Here is an example, that I hope helps to clarify things: This writes
This adds an additional empty line to the file
Notice the two For completeness, here is a bad example: This writes
|
Damn it. The web UI lied to me. I just verified the files and all is already fine (final new line, not empty lines). |
Thanks for the clarification. It always seemed to render as an empty line to me in editors when I noticed it adding such on save. I guess that varies by editor presentation 😅 |
Which of your suggestions should be commited now? I guess the one about |
Only the three unnecessary lines in I thought I deleted all wrong suggestions with the exception of one, but there were still two left. I deleted them now as well. So there is now only one wrong suggestion left, but only for the record, so that the following comments of polarathene and me makes sense. |
I realized that indeed there were two $ for FILE in * ; do hd $FILE | tail -n 2 | head -n 1 ; done
00001640 20 66 69 0a 7d 0a | fi.}.|
00000a30 69 61 73 65 73 5f 63 6f 6e 66 69 67 0a 7d 0a |iases_config.}.|
00000bc0 0a 7d 0a |.}.|
000009c0 6b 69 6c 6c 20 31 0a 7d 0a |kill 1.}.|
000003d0 63 72 69 70 74 73 0a |cripts.|
00000530 66 69 0a 7d 0a |fi.}.|
00000380 0a 7d 0a |.}.|
00000360 2a 2f 7d 22 0a 7d 0a |*/}".}.|
00000aa0 74 61 6c 69 61 73 2e 31 2e 68 74 6d 6c 0a |talias.1.html.|
00001040 0a 20 20 66 69 0a 7d 0a |. fi.}.|
000001a0 20 66 69 0a 7d 0a | fi.}.|
000056b0 7d 0a |}.|
000000e0 0a 7d 0a |.}.| |
Interesting. When I checked out the branch to verify, all looked good. But maybe I did some mistake by doing that. I don't know. Then the web UI didn't lie to me in the first place 😆 |
Description
This PR does not change any functionality of DMS, it just refactors the
helper-function.sh
script into smaller scripts in the earlier createdhelpers/
directory.helper-function.sh
was a mess and all over the place. Now, a single scriptindex.sh
(which was already created before this PR) sources all helper functions, or one can individually source smaller helpers, somewhat sorted. Again, this is just a refactoring without functionality changes :)One more thing: I changed
.
tosource
. As described in the commit message,source
is idiomatic to Bash, and I find it easier to understand that a script is sourced here. I hope this is not a major problem for someone :)Type of change
Checklist:
docs/
)