Skip to content

Helper scripts - #318

Merged
bubacoder merged 2 commits into
mainfrom
feature/helper-scripts
Apr 26, 2026
Merged

Helper scripts#318
bubacoder merged 2 commits into
mainfrom
feature/helper-scripts

Conversation

@bubacoder

@bubacoder bubacoder commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Commits in this PR

  • Add documentation headers to scripts
  • Get-offline-data: keep only 2 latest data files, kimplify ollama model management

Summary by CodeRabbit

  • New Features

    • Added Ollama task for acquiring AI models into Docker container.
    • Added Kiwix task for downloading offline content assets.
    • Implemented automatic retention of previous versions for downloaded files (keeps latest 2 versions by default).
  • Documentation

    • Enhanced script documentation with descriptive comments clarifying purpose and behavior across multiple utility scripts.
    • Updated offline data acquisition guidance.

@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This change restructures the offline data acquisition workflow by moving Ollama model pulling from a dedicated script into a Taskfile task, introducing a new Kiwix download task, adding file version retention logic to the file download script, and adding clarifying documentation comments to multiple utility scripts.

Changes

Cohort / File(s) Summary
Offline Data Task Restructuring
Taskfile.yaml, .claude/commands/update-ai-models.md
Replaces get-offline-data-local task with get-offline-data-ollama and get-offline-data-kiwix tasks; updates documentation to reference Taskfile instead of shell scripts for Ollama model configuration.
Ollama Script Removal
scripts/get-offline-data-ollama.sh
Removed script that previously pulled three specific Ollama models; functionality consolidated into Taskfile task.
File Download Enhancement
scripts/get-offline-data-file.sh
Adds configurable version retention (defaults to 2 versions) to prune older downloaded files after successful wget completion.
Documentation Comments
scripts/copy-repo-template.sh, scripts/git-rebase-to-main.sh, scripts/infra-mcp/start-server.sh, scripts/jellyfin-rescan.sh
Adds inline comments describing script purpose and behavior without modifying logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Add scripts to download data for offline use #120: Directly inverse—that PR introduced scripts/get-offline-data-ollama.sh and a Taskfile task invoking it, while this PR removes the script and consolidates logic into a Taskfile task.
  • Download OS installers and Kiwix apps #126: Both restructure the offline data workflow by replacing get-offline-data-local with subtasks and modifying file download scripts like scripts/get-offline-data-file.sh.
  • Add new AI models, update docs #137: Related through Ollama model management—this PR documents syncing ollama-local-* entries in docker/ai/litellm/config/config.yaml after updating the Taskfile, while that PR directly updates those config entries.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and overly broad. 'Helper scripts' does not convey meaningful information about the main changes: Ollama task refactoring, file retention logic, and documentation additions. Revise the title to be more specific, such as 'Refactor Ollama model management and add file retention logic' or 'Move Ollama models to Taskfile and add script documentation headers'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/helper-scripts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/get-offline-data-file.sh (1)

60-74: ⚠️ Potential issue | 🟡 Minor

Retention is skipped when the latest file is already cached.

The early return 0 at lines 60–63 short-circuits before the new pruning block at 69–74, so old versions are only pruned during runs that actually download a new file. If the upstream version hasn't changed (steady state) or stale files predate this feature, they'll accumulate indefinitely. Consider hoisting the prune step so it runs on every successful invocation, regardless of whether a download occurred.

♻️ Suggested fix: prune on every successful run
-  # Check if the file already exists locally
-  if [[ -f "$LATEST_FILE" ]]; then
-    echo "File '$LATEST_FILE' already exists locally. No download needed."
-    return 0
-  fi
-
-  # Download the latest file
-  echo "Downloading the latest file: $LATEST_FILE..."
-  if wget -q --show-progress "${url}${LATEST_FILE}"; then
-    echo "File '$LATEST_FILE' successfully downloaded to $(pwd)."
-    local OLD_FILES
-    OLD_FILES=$(for f in *; do [[ "$f" =~ ^${pattern}$ ]] && echo "$f"; done | sort -r | tail -n +"$((VERSIONS_TO_KEEP + 1))")
-    if [[ -n "$OLD_FILES" ]]; then
-      echo "Removing old versions..."
-      echo "$OLD_FILES" | xargs rm -v
-    fi
-  else
-    echo "Failed to download the file '$LATEST_FILE'. Exiting."
-    return 1
-  fi
+  # Download the latest file (skip if already present)
+  if [[ -f "$LATEST_FILE" ]]; then
+    echo "File '$LATEST_FILE' already exists locally. No download needed."
+  else
+    echo "Downloading the latest file: $LATEST_FILE..."
+    if ! wget -q --show-progress "${url}${LATEST_FILE}"; then
+      echo "Failed to download the file '$LATEST_FILE'. Exiting."
+      return 1
+    fi
+    echo "File '$LATEST_FILE' successfully downloaded to $(pwd)."
+  fi
+
+  # Prune older local versions on every successful run
+  local OLD_FILES
+  OLD_FILES=$(for f in *; do [[ -f "$f" && "$f" =~ ^${pattern}$ ]] && echo "$f"; done | sort -r | tail -n +"$((VERSIONS_TO_KEEP + 1))")
+  if [[ -n "$OLD_FILES" ]]; then
+    echo "Removing old versions..."
+    echo "$OLD_FILES" | xargs rm -v
+  fi

Note: also added -f "$f" to the test so directories that happen to match the regex aren't fed to rm (which would fail without -r).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/get-offline-data-file.sh` around lines 60 - 74, The early return when
LATEST_FILE already exists skips the retention/prune logic, so hoist the pruning
block so it executes on every successful run (both when the file is already
present and after a download); specifically, move the OLD_FILES calculation and
the "Removing old versions..." xargs rm step out of the wget-success branch and
run it unconditionally before returning, and update the file-selection loop that
sets OLD_FILES to include a file-existence guard (use -f "$f") when matching
against pattern and sorting so directories aren't passed to rm; keep references
to LATEST_FILE, pattern, VERSIONS_TO_KEEP, OLD_FILES, url, and wget to find and
modify the relevant code.
🧹 Nitpick comments (1)
scripts/get-offline-data-file.sh (1)

70-73: Optional: harden against unusual filenames.

echo "$OLD_FILES" | xargs rm -v word-splits on whitespace. Current Kiwix/Ollama filenames are safe, but using newline-delimited input makes this future-proof:

-      echo "$OLD_FILES" | xargs rm -v
+      printf '%s\n' "$OLD_FILES" | xargs -d '\n' -r rm -v
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/get-offline-data-file.sh` around lines 70 - 73, The removal step is
vulnerable to word-splitting because echo "$OLD_FILES" is whitespace-split
before xargs; update the cleanup to pass filenames null-delimited and use xargs
-0: produce null-separated output (e.g., via printf '%s\0' for each filename
stored in OLD_FILES or build OLD_FILES as a null-separated string) and call
xargs -0 rm -v so rm receives correct filenames even if they contain
spaces/newlines; target the OLD_FILES production and the line that pipes into
xargs rm -v.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@scripts/get-offline-data-file.sh`:
- Around line 60-74: The early return when LATEST_FILE already exists skips the
retention/prune logic, so hoist the pruning block so it executes on every
successful run (both when the file is already present and after a download);
specifically, move the OLD_FILES calculation and the "Removing old versions..."
xargs rm step out of the wget-success branch and run it unconditionally before
returning, and update the file-selection loop that sets OLD_FILES to include a
file-existence guard (use -f "$f") when matching against pattern and sorting so
directories aren't passed to rm; keep references to LATEST_FILE, pattern,
VERSIONS_TO_KEEP, OLD_FILES, url, and wget to find and modify the relevant code.

---

Nitpick comments:
In `@scripts/get-offline-data-file.sh`:
- Around line 70-73: The removal step is vulnerable to word-splitting because
echo "$OLD_FILES" is whitespace-split before xargs; update the cleanup to pass
filenames null-delimited and use xargs -0: produce null-separated output (e.g.,
via printf '%s\0' for each filename stored in OLD_FILES or build OLD_FILES as a
null-separated string) and call xargs -0 rm -v so rm receives correct filenames
even if they contain spaces/newlines; target the OLD_FILES production and the
line that pipes into xargs rm -v.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2181378f-5b00-4ff7-8a52-f978ad1ec455

📥 Commits

Reviewing files that changed from the base of the PR and between 8d301ce and 2da51ed.

📒 Files selected for processing (8)
  • .claude/commands/update-ai-models.md
  • Taskfile.yaml
  • scripts/copy-repo-template.sh
  • scripts/get-offline-data-file.sh
  • scripts/get-offline-data-ollama.sh
  • scripts/git-rebase-to-main.sh
  • scripts/infra-mcp/start-server.sh
  • scripts/jellyfin-rescan.sh
💤 Files with no reviewable changes (1)
  • scripts/get-offline-data-ollama.sh

@bubacoder
bubacoder merged commit a51628a into main Apr 26, 2026
4 checks passed
@bubacoder
bubacoder deleted the feature/helper-scripts branch April 26, 2026 12:45
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.

1 participant