fix/minors #20

Merged
kleb merged 4 commits from fix/minors into main 2025-12-29 13:22:32 +01:00
Owner

PR Type

Enhancement, Bug fix, Documentation


Description

  • Improved sed safety by escaping replacement strings to prevent command injection or syntax errors.

  • Enhanced Fish shell installation logic with better error handling and dependency checks for Fisher.

  • Added CLAUDE.md to provide comprehensive project guidelines and architecture overview for AI assistants.

  • Updated versioning and metadata headers across multiple shell scripts for better maintenance.


Diagram Walkthrough

flowchart LR
  subgraph "Safety Improvements"
  A["utils.sh"] -- "escapeSedReplacement" --> B["sed -i"]
  end
  subgraph "Feature Updates"
  C["system.sh"] -- "Check type -q fisher" --> D["Fisher/Catppuccin"]
  end
  subgraph "Documentation"
  E["CLAUDE.md"] -- "Project Guide" --> F["Developer Workflow"]
  end

File Walkthrough

Relevant files
Bug fix
2 files
utils.sh
Implement escapeSedReplacement for safer string manipulation in sed
+25/-9   
software.sh
Secure hostname replacement using escaped strings in Zabbix addon
+8/-7     
Documentation
3 files
CLAUDE.md
Add project-specific guidelines and architecture documentation for AI
tools
+94/-0   
zabbix.sh
Add script header and author information                                 
+8/-0     
README.md
Minor formatting adjustment in risk acknowledgment section
+83/-12 
Enhancement
1 files
system.sh
Refine Fish shell and Fisher plugin manager installation logic
+35/-15 
Miscellaneous
7 files
miscellaneous.sh
Update version and metadata for Miscellaneous Installer   
+3/-3     
motd.sh
Bump version and update modification date for MOTD script
+3/-3     
utilities.sh
Update versioning for Utilities Installer                               
+3/-3     
unix-format.sh
Update version and modification date for format converter
+3/-3     
apt.sh
Bump version for APT updates check script                               
+2/-2     
clean.sh
Update version and metadata for cleanup utility                   
+2/-3     
update.sh
Update version and metadata for update utility                     
+2/-3     
Formatting
2 files
checksum.sh
Add standardized file header and metadata                               
+9/-1     
kInit.sh
Remove trailing whitespace at end of file                               
+3/-4     
Configuration changes
1 files
checksums.sha256
Update file checksums to reflect script changes                   
+10/-9   

### **PR Type** Enhancement, Bug fix, Documentation ___ ### **Description** - Improved `sed` safety by escaping replacement strings to prevent command injection or syntax errors. - Enhanced Fish shell installation logic with better error handling and dependency checks for Fisher. - Added `CLAUDE.md` to provide comprehensive project guidelines and architecture overview for AI assistants. - Updated versioning and metadata headers across multiple shell scripts for better maintenance. ___ ### Diagram Walkthrough ```mermaid flowchart LR subgraph "Safety Improvements" A["utils.sh"] -- "escapeSedReplacement" --> B["sed -i"] end subgraph "Feature Updates" C["system.sh"] -- "Check type -q fisher" --> D["Fisher/Catppuccin"] end subgraph "Documentation" E["CLAUDE.md"] -- "Project Guide" --> F["Developer Workflow"] end ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>utils.sh</strong><dd><code>Implement <code>escapeSedReplacement</code> for safer string manipulation in <code>sed</code></code></dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/utils.sh">+25/-9</a>&nbsp; &nbsp; </td> </tr> <tr> <td><strong>software.sh</strong><dd><code>Secure hostname replacement using escaped strings in Zabbix addon</code></dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/software/software.sh">+8/-7</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Documentation</strong></td><td><details><summary>3 files</summary><table> <tr> <td><strong>CLAUDE.md</strong><dd><code>Add project-specific guidelines and architecture documentation for AI </code><br><code>tools</code></dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/CLAUDE.md">+94/-0</a>&nbsp; &nbsp; </td> </tr> <tr> <td><strong>zabbix.sh</strong><dd><code>Add script header and author information</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/.scripts/unix/download/zabbix.sh">+8/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>README.md</strong><dd><code>Minor formatting adjustment in risk acknowledgment section</code></dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/README.md">+83/-12</a>&nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Enhancement</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>system.sh</strong><dd><code>Refine Fish shell and Fisher plugin manager installation logic</code></dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/system/system.sh">+35/-15</a>&nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Miscellaneous</strong></td><td><details><summary>7 files</summary><table> <tr> <td><strong>miscellaneous.sh</strong><dd><code>Update version and metadata for Miscellaneous Installer</code>&nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/miscellaneous/miscellaneous.sh">+3/-3</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>motd.sh</strong><dd><code>Bump version and update modification date for MOTD script</code></dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/system/files/motd.sh">+3/-3</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>utilities.sh</strong><dd><code>Update versioning for Utilities Installer</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/utilities/utilities.sh">+3/-3</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>unix-format.sh</strong><dd><code>Update version and modification date for format converter</code></dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/.scripts/unix/unix-format.sh">+3/-3</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>apt.sh</strong><dd><code>Bump version for APT updates check script</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/software/zabbix/addons/apt/apt.sh">+2/-2</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>clean.sh</strong><dd><code>Update version and metadata for cleanup utility</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/utilities/files/clean.sh">+2/-3</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>update.sh</strong><dd><code>Update version and metadata for update utility</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/utilities/files/update.sh">+2/-3</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Formatting</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>checksum.sh</strong><dd><code>Add standardized file header and metadata</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/.scripts/unix/checksum.sh">+9/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>kInit.sh</strong><dd><code>Remove trailing whitespace at end of file</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/kInit.sh">+3/-4</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Configuration changes</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>checksums.sha256</strong><dd><code>Update file checksums to reflect script changes</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/checksums.sha256">+10/-9</a>&nbsp; &nbsp; </td> </tr> </table></details></td></tr></tr></tbody></table> </details> ___
Collaborator

PR Reviewer Guide 🔍

(Review updated until commit 94a900c68a)

Here are some key observations to aid the review process:

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

Logic Change

The installation logic for Fisher and Catppuccin has been wrapped in conditional checks. While this improves idempotency, the use of fish -c "type -q fisher" is a change from the previous command -v check. Ensure that fish is guaranteed to be in the PATH at this stage of the script execution.

if ! fish -c "type -q fisher" >/dev/null 2>&1; then
    if fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher" >/dev/null 2>&1; then
        logInfo "Fisher plugin manager installed"
    else
        logWarning "Failed to install Fisher plugin manager"
    fi
else
    logInfo "Fisher already installed, skipping"
fi

if [[ "$FISH_INSTALL_CATPPUCCIN" == "TRUE" ]]; then
    if fish -c "fisher install catppuccin/fish" >/dev/null 2>&1; then
        mkdir -p "$HOME/.config/fish"
        executeWithPrompt "y" "fish -c \"fish_config theme save 'Catppuccin Mocha'\""
        logInfo "Catppuccin Mocha theme installed and set"
    else
        logWarning "Failed to install Catppuccin theme"
    fi
Sed Safety

The replace function now uses escapeSedPattern and escapeSedReplacement. Since the implementation of these escaping functions is not visible in the diff, it is critical to verify they correctly handle the delimiter used in the sed command (which is |) to prevent syntax errors or injection.

local escapedPattern escapedReplacement
escapedPattern=$(escapeSedPattern "$pattern")
escapedReplacement=$(escapeSedReplacement "$replacement")

if ! sed -i 's|'"$escapedPattern"'|'"$escapedReplacement"'|g' "$file"; then
## PR Reviewer Guide 🔍 #### (Review updated until commit https://git.kleb.sh/kleb/kInit/commit/94a900c68ac76248e66043eed7aecbedea070b2e) Here are some key observations to aid the review process: <table> <tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>: 2 🔵🔵⚪⚪⚪</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/fix/minors/installer/system/system.sh#L338-L355'><strong>Logic Change</strong></a> The installation logic for Fisher and Catppuccin has been wrapped in conditional checks. While this improves idempotency, the use of `fish -c "type -q fisher"` is a change from the previous `command -v` check. Ensure that `fish` is guaranteed to be in the PATH at this stage of the script execution. </summary> ```shell if ! fish -c "type -q fisher" >/dev/null 2>&1; then if fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher" >/dev/null 2>&1; then logInfo "Fisher plugin manager installed" else logWarning "Failed to install Fisher plugin manager" fi else logInfo "Fisher already installed, skipping" fi if [[ "$FISH_INSTALL_CATPPUCCIN" == "TRUE" ]]; then if fish -c "fisher install catppuccin/fish" >/dev/null 2>&1; then mkdir -p "$HOME/.config/fish" executeWithPrompt "y" "fish -c \"fish_config theme save 'Catppuccin Mocha'\"" logInfo "Catppuccin Mocha theme installed and set" else logWarning "Failed to install Catppuccin theme" fi ``` </details> <details><summary><a href='https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/utils.sh#L672-L676'><strong>Sed Safety</strong></a> The `replace` function now uses `escapeSedPattern` and `escapeSedReplacement`. Since the implementation of these escaping functions is not visible in the diff, it is critical to verify they correctly handle the delimiter used in the `sed` command (which is `|`) to prevent syntax errors or injection. </summary> ```shell local escapedPattern escapedReplacement escapedPattern=$(escapeSedPattern "$pattern") escapedReplacement=$(escapeSedReplacement "$replacement") if ! sed -i 's|'"$escapedPattern"'|'"$escapedReplacement"'|g' "$file"; then ``` </details> </td></tr> </table>
Collaborator

PR Code Suggestions

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Escape the delimiter in sed patterns

The sed command uses | as a delimiter, but the pattern variable is not escaped. If
pattern contains a | character, the sed command will fail or behave unexpectedly.
Ensure the pattern is also escaped or use a delimiter that is guaranteed not to
appear in the input.

installer/utils.sh [670]

-if ! sed -i 's|'"$pattern"'|'"$escapedReplacement"'|g' "$file"; then
+local escapedPattern
+escapedPattern=$(echo "$pattern" | sed 's/[|]/\\&/g')
+if ! sed -i 's|'"$escapedPattern"'|'"$escapedReplacement"'|g' "$file"; then
Suggestion importance[1-10]: 7

__

Why: The replace function in utils.sh uses | as a sed delimiter. While the replacement string is now escaped in this PR, the search pattern is not. If the $pattern variable contains the | character, the sed command will fail.

Medium
Possible issue
Fix potential sed delimiter collision

The sed command uses / as a delimiter, but escapeSedReplacement likely only escapes
characters for the replacement string (like & or </code>). If escapedSuffix contains a /,
the sed command will break. Use a different delimiter like | or ensure / is also
escaped.

installer/software/software.sh [180-181]

+local escapedSuffix
 escapedSuffix=$(escapeSedReplacement "$(hostname)${ZABBIX_HOSTNAME_SUFFIX[$detectedDC]}")
-sed -i "s/hostname=\"\$(hostname)\"/hostname=\"$escapedSuffix\"/" "apt.sh"
+sed -i "s|hostname=\"\$(hostname)\"|hostname=\"$escapedSuffix\"|" "apt.sh"
Suggestion importance[1-10]: 6

__

Why: The sed command on line 181 uses / as a delimiter. If the escapedSuffix (which contains the hostname) contains a /, the command will break. Using a less common delimiter like | is a standard safety practice in shell scripting.

Low
Security
Avoid piping curl directly to source

Piping a remote script directly into source within a subshell is risky if the
download is interrupted or the source is compromised. Additionally, if the curl
fails, the source command might still execute with partial or no input depending on
shell behavior. Consider downloading to a temporary file first and verifying it.

installer/system/system.sh [337]

-if fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher" >/dev/null 2>&1; then
+if fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish -o /tmp/fisher.fish && source /tmp/fisher.fish && fisher install jorgebucaran/fisher" >/dev/null 2>&1; then
Suggestion importance[1-10]: 5

__

Why: Piping curl directly to source is a common but risky pattern. While the suggestion improves robustness against partial downloads, the impact is moderate as this is an installer script where such patterns are frequently used for convenience.

Low
## PR Code Suggestions ✨ <!-- 94a900c --> 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>General</td> <td> <details><summary>Escape the delimiter in sed patterns</summary> ___ **The <code>sed</code> command uses <code>|</code> as a delimiter, but the <code>pattern</code> variable is not escaped. If <br><code>pattern</code> contains a <code>|</code> character, the <code>sed</code> command will fail or behave unexpectedly. <br>Ensure the pattern is also escaped or use a delimiter that is guaranteed not to <br>appear in the input.** [installer/utils.sh [670]](https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/utils.sh#L670-L670) ```diff -if ! sed -i 's|'"$pattern"'|'"$escapedReplacement"'|g' "$file"; then +local escapedPattern +escapedPattern=$(echo "$pattern" | sed 's/[|]/\\&/g') +if ! sed -i 's|'"$escapedPattern"'|'"$escapedReplacement"'|g' "$file"; then ``` <details><summary>Suggestion importance[1-10]: 7</summary> __ Why: The `replace` function in `utils.sh` uses `|` as a `sed` delimiter. While the replacement string is now escaped in this PR, the search pattern is not. If the `$pattern` variable contains the `|` character, the `sed` command will fail. </details></details></td><td align=center>Medium </td></tr><tr><td rowspan=1>Possible issue</td> <td> <details><summary>Fix potential sed delimiter collision</summary> ___ **The <code>sed</code> command uses <code>/</code> as a delimiter, but <code>escapeSedReplacement</code> likely only escapes <br>characters for the replacement string (like <code>&</code> or <code>\</code>). If <code>escapedSuffix</code> contains a <code>/</code>, <br>the <code>sed</code> command will break. Use a different delimiter like <code>|</code> or ensure <code>/</code> is also <br>escaped.** [installer/software/software.sh [180-181]](https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/software/software.sh#L180-L181) ```diff +local escapedSuffix escapedSuffix=$(escapeSedReplacement "$(hostname)${ZABBIX_HOSTNAME_SUFFIX[$detectedDC]}") -sed -i "s/hostname=\"\$(hostname)\"/hostname=\"$escapedSuffix\"/" "apt.sh" +sed -i "s|hostname=\"\$(hostname)\"|hostname=\"$escapedSuffix\"|" "apt.sh" ``` <details><summary>Suggestion importance[1-10]: 6</summary> __ Why: The `sed` command on line 181 uses `/` as a delimiter. If the `escapedSuffix` (which contains the hostname) contains a `/`, the command will break. Using a less common delimiter like `|` is a standard safety practice in shell scripting. </details></details></td><td align=center>Low </td></tr><tr><td rowspan=1>Security</td> <td> <details><summary>Avoid piping curl directly to source</summary> ___ **Piping a remote script directly into <code>source</code> within a subshell is risky if the <br>download is interrupted or the source is compromised. Additionally, if the <code>curl</code> <br>fails, the <code>source</code> command might still execute with partial or no input depending on <br>shell behavior. Consider downloading to a temporary file first and verifying it.** [installer/system/system.sh [337]](https://git.kleb.sh/kleb/kInit/src/branch/fix/minors/installer/system/system.sh#L337-L337) ```diff -if fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher" >/dev/null 2>&1; then +if fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish -o /tmp/fisher.fish && source /tmp/fisher.fish && fisher install jorgebucaran/fisher" >/dev/null 2>&1; then ``` <details><summary>Suggestion importance[1-10]: 5</summary> __ Why: Piping `curl` directly to `source` is a common but risky pattern. While the suggestion improves robustness against partial downloads, the impact is moderate as this is an installer script where such patterns are frequently used for convenience. </details></details></td><td align=center>Low </td></tr></tr></tbody></table>
Author
Owner

/review

/review
Collaborator

Persistent review updated to latest commit 94a900c68a

**[Persistent review](https://git.kleb.sh/kleb/kInit/pulls/20#issuecomment-178)** updated to latest commit https://git.kleb.sh/kleb/kInit/commit/94a900c68ac76248e66043eed7aecbedea070b2e
kleb merged commit db8803cc19 into main 2025-12-29 13:22:32 +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!20
No description provided.