Skip to content

Download OS installers and Kiwix apps - #126

Merged
bubacoder merged 2 commits into
mainfrom
feature/offline-data
May 2, 2025
Merged

Download OS installers and Kiwix apps#126
bubacoder merged 2 commits into
mainfrom
feature/offline-data

Conversation

@bubacoder

@bubacoder bubacoder commented Apr 28, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added the ability to download offline data files both locally and from a remote Proxmox server using new tasks.
    • Introduced a command-line option to download installer images only, without creating virtual machines, for both OpenWRT and Ubuntu Server VM setup scripts.
    • Added a script to automatically download the latest matching offline data files from specified URLs.
  • Improvements

    • Enhanced file management by using versioned filenames and avoiding redundant downloads.
    • Improved control flow and modularization in VM creation scripts for clearer, more flexible operation.

@coderabbitai

coderabbitai Bot commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

"""

Walkthrough

This update introduces a refactor to the offline data retrieval process and enhances VM creation scripts for OpenWRT and Ubuntu Server. The get-offline-data task in Taskfile.yaml is split into two subtasks: one for local offline data downloads and another for downloading from a Proxmox server via SSH, each with its own environment setup and commands. The Proxmox VM creation scripts are modularized, adding support for a --download-only flag that allows users to download installer images without proceeding to VM creation, and improving file management and argument handling.

Changes

File(s) Change Summary
Taskfile.yaml Refactored get-offline-data to run two new subtasks: get-offline-data-local (for local downloads with dotenv env loading) and get-offline-data-proxmox (for remote Proxmox downloads via SSH). Added environment variable setup.
proxmox/create-openwrt-vm.sh Modularized with download_installer and create_vm functions. Added --download-only flag. Improved image filename handling, conditional execution, and file cleanup.
proxmox/create-ubuntu-server-vm.sh Added DOWNLOAD_ONLY flag and command-line parsing for --download-only. Adjusted logic to optionally skip VM creation. Moved success message inside the VM creation function.
scripts/get-offline-data-file.sh Added new script to download the latest file matching a pattern from a URL into a target directory, with input validation and error handling.
scripts/get-offline-data-kiwix.sh Deleted old script for downloading Kiwix ZIM files, replaced by calls to the new generic get-offline-data-file.sh script in the updated tasks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TaskRunner
    participant LocalEnv
    participant ProxmoxSSH

    User->>TaskRunner: Run get-offline-data
    TaskRunner->>LocalEnv: Run get-offline-data-local (dotenv, scripts)
    TaskRunner->>ProxmoxSSH: Run get-offline-data-proxmox (SSH, scripts)
Loading
sequenceDiagram
    participant User
    participant VMCreateScript

    User->>VMCreateScript: Run script with [--download-only]
    VMCreateScript->>VMCreateScript: Download installer image
    alt --download-only flag set
        VMCreateScript-->>User: Exit after download
    else
        VMCreateScript->>VMCreateScript: Create VM using downloaded image
        VMCreateScript-->>User: VM created successfully
    end
Loading

Possibly related PRs

  • bubacoder/infra#120: Adds the initial get-offline-data task for offline data download, which is now refactored and expanded in this PR to support both local and Proxmox-based downloads.
    """

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec739ac and 23baab5.

📒 Files selected for processing (3)
  • Taskfile.yaml (1 hunks)
  • scripts/get-offline-data-file.sh (1 hunks)
  • scripts/get-offline-data-kiwix.sh (0 hunks)
💤 Files with no reviewable changes (1)
  • scripts/get-offline-data-kiwix.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/get-offline-data-file.sh
  • Taskfile.yaml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: check
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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.

Actionable comments posted: 0

🧹 Nitpick comments (4)
proxmox/create-ubuntu-server-vm.sh (1)

112-124: Harden argument parsing
Using for arg in "$@" combined with shift can lead to subtle edge-cases if you ever pass multiple parameters. Consider switching to a while [[ $# -gt 0 ]] loop and handling $1 directly, for example:

- for arg in "$@"; do
-   case $arg in
-     --download-only)
-       DOWNLOAD_ONLY=true
-       shift
-       ;;
-     *)
-       echo "Unknown argument: ${arg}"
-       exit 1
-       ;;
-   esac
- done
+ while [[ $# -gt 0 ]]; do
+   case "$1" in
+     --download-only)
+       DOWNLOAD_ONLY=true
+       ;;
+     *)
+       echo "Unknown argument: $1" >&2
+       exit 1
+       ;;
+   esac
+   shift
+ done

This pattern is more idiomatic and guarantees each argument is consumed exactly once.

proxmox/create-openwrt-vm.sh (2)

18-28: Ensure working directory clarity
Currently the OpenWRT image lands in the script’s CWD (root’s home by default). To make artifact paths predictable, consider parameterizing or cd-ing into a designated directory (e.g., /var/lib/vz/template/iso) and verifying it exists before download.


59-71: Harden argument parsing
As in the Ubuntu script, swapping for arg in "$@" for a while [[ $# -gt 0 ]] loop that shifts $1 makes flag handling more predictable:

while [[ $# -gt 0 ]]; do
  case "$1" in
    --download-only) DOWNLOAD_ONLY=true ;;
    *) echo "Unknown argument: $1" >&2; exit 1 ;;
  esac
  shift
done
Taskfile.yaml (1)

142-151: Remote Proxmox offline data retrieval
Leveraging SSH+--download-only to pull ISOs/images is an elegant reuse of your VM scripts. The TODO comments for additional ISOs should be tracked—would you like help creating corresponding issues or backlog items?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e578a94 and 5fda80d.

📒 Files selected for processing (3)
  • Taskfile.yaml (2 hunks)
  • proxmox/create-openwrt-vm.sh (1 hunks)
  • proxmox/create-ubuntu-server-vm.sh (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
proxmox/create-ubuntu-server-vm.sh (1)
proxmox/create-openwrt-vm.sh (2)
  • download_installer (18-28)
  • create_vm (30-57)
proxmox/create-openwrt-vm.sh (1)
proxmox/create-ubuntu-server-vm.sh (2)
  • download_installer (78-86)
  • create_vm (88-109)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: check
🔇 Additional comments (8)
proxmox/create-ubuntu-server-vm.sh (3)

30-31: Introduce download-only flag
The DOWNLOAD_ONLY flag defaults to false, enabling downstream logic to skip VM creation when desired. This cleanly ties into your Taskfile’s --download-only workflow.


107-108: Echo moved inside create_vm
Logging success immediately after the qm create and configuration steps provides clear feedback that VM provisioning has completed.


127-133: Conditional VM creation in main logic
The flow—download first, exit early on --download-only, otherwise call create_vm—is clear and fault-tolerant. It cleanly separates download from provisioning.

proxmox/create-openwrt-vm.sh (3)

15-17: Introduce download-only flag
Adding DOWNLOAD_ONLY=false brings parity with the Ubuntu script and enables offline-data tasks to fetch ISOs/images without spinning up VMs.


30-57: VM creation logic is solid
The steps for copying, unpacking, resizing, importing, and cleaning up the disk image are correctly ordered and comprehensive. Using realpath for the import source is a nice touch.


74-80: Conditional VM creation in main logic
Exiting immediately after download when DOWNLOAD_ONLY is set ensures no unintended VMs are provisioned—exactly the desired behavior for offline data tasks.

Taskfile.yaml (2)

125-130: Split get-offline-data into local and remote subtasks
Orchestrating get-offline-data-local and get-offline-data-proxmox sequentially clarifies responsibilities and leverages the new download-only flags. This improves task readability and maintainability.


131-141: Local offline data task
The get-offline-data-local task cleanly loads the proper dotenv files and invokes the ollama and kiwix scripts. Make sure variables like $STORAGE_KIWIX are documented in your .env files and validated before use.

@bubacoder bubacoder changed the title Download OS installers Download OS installers and Kiwix apps May 2, 2025

@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.

Actionable comments posted: 1

🧹 Nitpick comments (4)
scripts/get-offline-data-file.sh (4)

4-9: Refine argument validation messaging

  • Update the comment to mention all three parameters (directory, URL, pattern).
  • Redirect error messages to stderr using echo >&2.
    Suggested diff:
-# Validate that both URL and pattern are provided as parameters
+# Validate that target directory, URL, and pattern are provided
 if [[ $# -ne 3 ]]; then
-  echo "Error: You must provide a target directory, a URL, and a pattern as parameters."
+  echo >&2 "Error: You must provide a target directory, a URL, and a pattern."
   echo "Usage: $0 <directory-path> <url> <pattern>"
   exit 1
 fi

16-21: Improve directory existence check feedback
Redirect the error message to stderr for clarity:

-if [[ ! -d "$TARGET_DIR" ]]; then
-  echo "Error: The specified directory '$TARGET_DIR' does not exist."
-  exit 1
-fi
+if [[ ! -d "$TARGET_DIR" ]]; then
+  echo >&2 "Error: The specified directory '$TARGET_DIR' does not exist."
+  exit 1
+fi

40-44: Consider grep portability and regex robustness
Relying on grep -oP (PCRE lookbehind) may not work on all systems. As an alternative, you could use a portable grep -E and sed pipeline:

FILES=$(echo "$HTML" \
  | grep -Eo 'href="[^"]*'"$pattern" \
  | sed -E 's|href="([^"]+)".*|\1|' \
  | sort -r)

Or detect PCRE support at runtime and fallback.


42-50: Use version-aware sorting for filenames
A lexicographical sort -r may misorder versioned filenames. Use sort -Vr for natural version sorting:

-FILES=$(echo "$HTML" | grep -oP "(?<=href=\")${pattern}" | sort -r)
+FILES=$(echo "$HTML" | grep -oP "(?<=href=\")${pattern}" | sort -Vr)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fda80d and ec739ac.

📒 Files selected for processing (3)
  • Taskfile.yaml (1 hunks)
  • scripts/get-offline-data-file.sh (1 hunks)
  • scripts/get-offline-data-kiwix.sh (0 hunks)
💤 Files with no reviewable changes (1)
  • scripts/get-offline-data-kiwix.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • Taskfile.yaml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: check
🔇 Additional comments (6)
scripts/get-offline-data-file.sh (6)

1-2: Good use of strict mode
The shebang and set -euo pipefail ensure reliable error handling and portability.


11-15: Parameter assignment is clear
Capturing positional arguments into named variables improves readability and maintainability.


22-25: Approve directory change
Changing into the target directory early ensures subsequent operations run in the correct context.


56-63: File existence check is solid
Skipping download when the latest file already exists prevents unnecessary network traffic.


65-73: Downloading logic is correct
Using wget --show-progress for visibility is helpful. Error handling on download failure is properly implemented.


75-77: Invoke download function and propagate exit code
With set -e, the script will exit if download_latest_file returns a non-zero status, aligning with intended behavior.

Comment thread scripts/get-offline-data-file.sh Outdated
@bubacoder
bubacoder force-pushed the feature/offline-data branch from ec739ac to 23baab5 Compare May 2, 2025 19:37
@bubacoder
bubacoder merged commit 6bbc62b into main May 2, 2025
@bubacoder
bubacoder deleted the feature/offline-data branch May 2, 2025 19:40
@coderabbitai coderabbitai Bot mentioned this pull request Jul 24, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Apr 26, 2026
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