Optimizing motd.sh #11

Merged
kleb merged 2 commits from opti/motd.sh into main 2025-12-11 10:14:04 +01:00
Owner
No description provided.
Collaborator

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵
🧪 No relevant tests
🔒 No security concerns identified
 Recommended focus areas for review

Syntax Error

The line exit 0≈ includes an unexpected non-ASCII character () which will cause a syntax error. Remove the trailing character to ensure the script executes correctly.

exit 0≈
Variable Initialization

The variables memory_total_kb and swap_total_kb are used in formatSize but their initialization isn’t visible in this diff. Confirm they are set by collectResourceInfo to avoid empty or incorrect output.

memory_total_formatted=$(formatSize "$memory_total_kb")
swap_total_formatted=$(formatSize "$swap_total_kb")
## PR Reviewer Guide 🔍 Here are some key observations to aid the review process: <table> <tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>: 3 🔵🔵🔵⚪⚪</td></tr> <tr><td>🧪&nbsp;<strong>No relevant tests</strong></td></tr> <tr><td>🔒&nbsp;<strong>No security concerns identified</strong></td></tr> <tr><td>⚡&nbsp;<strong>Recommended focus areas for review</strong><br><br> <details><summary><a href='https://git.kleb.sh/kleb/kInit/src/branch/opti/motd.sh/installer/system/files/motd.sh#L516-L516'><strong>Syntax Error</strong></a> The line `exit 0≈` includes an unexpected non-ASCII character (`≈`) which will cause a syntax error. Remove the trailing character to ensure the script executes correctly. </summary> ```shell exit 0≈ ``` </details> <details><summary><a href='https://git.kleb.sh/kleb/kInit/src/branch/opti/motd.sh/installer/system/files/motd.sh#L412-L413'><strong>Variable Initialization</strong></a> The variables `memory_total_kb` and `swap_total_kb` are used in `formatSize` but their initialization isn’t visible in this diff. Confirm they are set by `collectResourceInfo` to avoid empty or incorrect output. </summary> ```shell memory_total_formatted=$(formatSize "$memory_total_kb") swap_total_formatted=$(formatSize "$swap_total_kb") ``` </details> </td></tr> </table>
Collaborator

PR Code Suggestions

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Remove stray character from exit

Remove the stray non-ASCII ‘≈’ character after the exit command, which will
otherwise cause a syntax error or prevent the script from terminating as intended.

installer/system/files/motd.sh [516]

-exit 0≈
+exit 0
Suggestion importance[1-10]: 10

__

Why: The stray non-ASCII ‘≈’ on the exit 0 line will cause a syntax error and prevent proper script termination.

High
General
Declare locals in function

Prevent these intermediate variables from polluting the global scope by declaring
them as local. Do the same for other newly introduced variables in printMotd.

installer/system/files/motd.sh [412-413]

-memory_total_formatted=$(formatSize "$memory_total_kb")
-swap_total_formatted=$(formatSize "$swap_total_kb")
+local memory_total_formatted=$(formatSize "$memory_total_kb")
+local swap_total_formatted=$(formatSize "$swap_total_kb")
Suggestion importance[1-10]: 6

__

Why: Declaring memory_total_formatted and swap_total_formatted as local prevents variable leakage outside printMotd, improving encapsulation.

Low
## PR Code Suggestions ✨ <!-- 3356c7d --> Explore these optional code suggestions: <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>Possible issue</td> <td> <details><summary>Remove stray character from exit</summary> ___ **Remove the stray non-ASCII ‘≈’ character after the exit command, which will <br>otherwise cause a syntax error or prevent the script from terminating as intended.** [installer/system/files/motd.sh [516]](https://git.kleb.sh/kleb/kInit/src/branch/opti/motd.sh/installer/system/files/motd.sh#L516-L516) ```diff -exit 0≈ +exit 0 ``` <details><summary>Suggestion importance[1-10]: 10</summary> __ Why: The stray non-ASCII ‘≈’ on the `exit 0` line will cause a syntax error and prevent proper script termination. </details></details></td><td align=center>High </td></tr><tr><td rowspan=1>General</td> <td> <details><summary>Declare locals in function</summary> ___ **Prevent these intermediate variables from polluting the global scope by declaring <br>them as <code>local</code>. Do the same for other newly introduced variables in <code>printMotd</code>.** [installer/system/files/motd.sh [412-413]](https://git.kleb.sh/kleb/kInit/src/branch/opti/motd.sh/installer/system/files/motd.sh#L412-L413) ```diff -memory_total_formatted=$(formatSize "$memory_total_kb") -swap_total_formatted=$(formatSize "$swap_total_kb") +local memory_total_formatted=$(formatSize "$memory_total_kb") +local swap_total_formatted=$(formatSize "$swap_total_kb") ``` <details><summary>Suggestion importance[1-10]: 6</summary> __ Why: Declaring `memory_total_formatted` and `swap_total_formatted` as `local` prevents variable leakage outside `printMotd`, improving encapsulation. </details></details></td><td align=center>Low </td></tr></tr></tbody></table>
kleb merged commit a396770c9e into main 2025-12-11 10:14:04 +01:00
kleb changed title from reworking to Optimizing motd.sh 2025-12-11 14:09:23 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kleb/kInit!11
No description provided.