Skip to content
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

Add support for dotfiles repo #837

Closed
wants to merge 1 commit into from

Conversation

oleander
Copy link

@oleander oleander commented Jan 25, 2025

Add support for pulling down and executing user-provided dotfiles repository.

  • Add a new configuration option dotfiles_repo in ssh/config.yaml to specify the GitHub repository URL.
  • Update the schema in ssh/config.yaml to include the new dotfiles_repo option.
  • Update ssh/DOCS.md to include instructions on how to configure the dotfiles_repo option and provide an example configuration.
  • Update ssh/rootfs/etc/s6-overlay/s6-rc.d/init-user/run to clone the specified repository from the dotfiles_repo option and execute the setup scripts.

Summary by CodeRabbit

  • New Features

    • Added support for cloning and setting up dotfiles from a specified GitHub repository
    • New configuration option dotfiles_repo allows users to automate their environment setup
  • Documentation

    • Updated SSH add-on documentation to explain the new dotfiles repository configuration option

Add support for pulling down and executing user-provided dotfiles repository.

* Add a new configuration option `dotfiles_repo` in `ssh/config.yaml` to specify the GitHub repository URL.
* Update the schema in `ssh/config.yaml` to include the new `dotfiles_repo` option.
* Update `ssh/DOCS.md` to include instructions on how to configure the `dotfiles_repo` option and provide an example configuration.
* Update `ssh/rootfs/etc/s6-overlay/s6-rc.d/init-user/run` to clone the specified repository from the `dotfiles_repo` option and execute the setup scripts.
Copy link

coderabbitai bot commented Jan 25, 2025

Walkthrough

The pull request introduces a new dotfiles_repo configuration option for the SSH add-on. This feature allows users to specify a GitHub repository containing their dotfiles, which will be automatically cloned and set up during the SSH add-on initialization. The changes span across documentation, configuration files, and the initialization script, enabling users to easily customize their environment by providing a repository URL for their personal configuration files.

Changes

File Change Summary
ssh/DOCS.md Added documentation for new dotfiles_repo configuration option
ssh/config.yaml Introduced dotfiles_repo option with empty string default and string schema definition
ssh/rootfs/etc/s6-overlay/s6-rc.d/init-user/run Added logic to clone and execute dotfiles repository setup scripts

Sequence Diagram

sequenceDiagram
    participant User as User Configuration
    participant Addon as SSH Add-on
    participant Repo as Dotfiles Repository

    User->>Addon: Specify dotfiles_repo URL
    Addon->>Repo: Clone repository
    alt Successful Clone
        Addon->>Repo: Execute install.sh
        Repo-->>Addon: Configuration Complete
    else Clone Failure
        Addon-->>User: Error Logging
    end
Loading

Possibly related PRs

Suggested labels

documentation, bugfix

Suggested reviewers

  • frenck

Poem

🐰 A Rabbit's Dotfile Delight

With config so neat and bright,
Repositories clone with might,
Dotfiles dancing left and right,
Automation's pure delight!

🚀 Hop, configure, set things right! 🔧


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

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. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
ssh/rootfs/etc/s6-overlay/s6-rc.d/init-user/run (1)

122-125: Enhancement: Support additional setup script names

The implementation only supports install.sh, but many dotfiles repositories use different naming conventions.

Consider supporting additional common script names:

-    if [ -f /root/dotfiles/install.sh ]; then
-        bash /root/dotfiles/install.sh \
-            || bashio::exit.nok "Failed to execute dotfiles setup script"
-    fi
+    for script in install.sh setup.sh bootstrap.sh; do
+        if [ -f "/root/dotfiles/${script}" ]; then
+            bashio::log.info "Executing ${script}..."
+            bash "/root/dotfiles/${script}" \
+                || bashio::exit.nok "Failed to execute ${script}"
+            break
+        fi
+    done
ssh/config.yaml (1)

69-69: Enhancement: Add pattern validation for dotfiles_repo

The schema should validate that the URL matches the expected format.

Consider using a more restrictive schema:

-  dotfiles_repo: str
+  dotfiles_repo: match(^https://github.com/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+(.git)?$)?

This ensures that only valid GitHub repository URLs are accepted.

Also applies to: 88-88

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1a7977 and 97a49f6.

📒 Files selected for processing (3)
  • ssh/DOCS.md (2 hunks)
  • ssh/config.yaml (2 hunks)
  • ssh/rootfs/etc/s6-overlay/s6-rc.d/init-user/run (1 hunks)

Comment on lines +117 to +126
# Clone the specified dotfiles repository and execute setup scripts
if bashio::config.has_value 'dotfiles_repo'; then
dotfiles_repo=$(bashio::config 'dotfiles_repo')
git clone "${dotfiles_repo}" /root/dotfiles \
|| bashio::exit.nok "Failed to clone dotfiles repository: ${dotfiles_repo}"
if [ -f /root/dotfiles/install.sh ]; then
bash /root/dotfiles/install.sh \
|| bashio::exit.nok "Failed to execute dotfiles setup script"
fi
fi
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security: Add validation and restrictions for dotfiles repository

The current implementation has several security concerns that need to be addressed:

  1. No validation of the repository URL
  2. Executing arbitrary shell scripts with root privileges
  3. No cleanup of cloned repository

Consider applying these security improvements:

 # Clone the specified dotfiles repository and execute setup scripts
 if bashio::config.has_value 'dotfiles_repo'; then
     dotfiles_repo=$(bashio::config 'dotfiles_repo')
+    # Validate repository URL
+    if ! [[ "${dotfiles_repo}" =~ ^https://github.com/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+(.git)?$ ]]; then
+        bashio::exit.nok "Invalid repository URL. Only public GitHub repositories are supported"
+    fi
+    
+    # Clean up existing repository if present
+    rm -rf /root/dotfiles
+    
+    # Clone with restrictions
     git clone "${dotfiles_repo}" /root/dotfiles \
+        --depth=1 \
+        --single-branch \
+        --timeout=30 \
         || bashio::exit.nok "Failed to clone dotfiles repository: ${dotfiles_repo}"
+
+    # Validate repository contents
+    if [ -f /root/dotfiles/install.sh ]; then
+        # Check for suspicious commands
+        if grep -qE "(curl|wget|nc|telnet|sudo|chmod \+x|rm -rf /*)" /root/dotfiles/install.sh; then
+            bashio::exit.nok "Setup script contains suspicious commands"
+        fi
         bash /root/dotfiles/install.sh \
             || bashio::exit.nok "Failed to execute dotfiles setup script"
     fi
+    
+    # Clean up
+    rm -rf /root/dotfiles/.git
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Clone the specified dotfiles repository and execute setup scripts
if bashio::config.has_value 'dotfiles_repo'; then
dotfiles_repo=$(bashio::config 'dotfiles_repo')
git clone "${dotfiles_repo}" /root/dotfiles \
|| bashio::exit.nok "Failed to clone dotfiles repository: ${dotfiles_repo}"
if [ -f /root/dotfiles/install.sh ]; then
bash /root/dotfiles/install.sh \
|| bashio::exit.nok "Failed to execute dotfiles setup script"
fi
fi
# Clone the specified dotfiles repository and execute setup scripts
if bashio::config.has_value 'dotfiles_repo'; then
dotfiles_repo=$(bashio::config 'dotfiles_repo')
# Validate repository URL
if ! [[ "${dotfiles_repo}" =~ ^https://github.com/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+(.git)?$ ]]; then
bashio::exit.nok "Invalid repository URL. Only public GitHub repositories are supported"
fi
# Clean up existing repository if present
rm -rf /root/dotfiles
# Clone with restrictions
git clone "${dotfiles_repo}" /root/dotfiles \
--depth=1 \
--single-branch \
--timeout=30 \
|| bashio::exit.nok "Failed to clone dotfiles repository: ${dotfiles_repo}"
# Validate repository contents
if [ -f /root/dotfiles/install.sh ]; then
# Check for suspicious commands
if grep -qE "(curl|wget|nc|telnet|sudo|chmod \+x|rm -rf /*)" /root/dotfiles/install.sh; then
bashio::exit.nok "Setup script contains suspicious commands"
fi
bash /root/dotfiles/install.sh \
|| bashio::exit.nok "Failed to execute dotfiles setup script"
fi
# Clean up
rm -rf /root/dotfiles/.git
fi

Comment on lines +232 to +236
#### Option: `dotfiles_repo`

Specify the URL of your GitHub repository containing your dotfiles. The repository will be cloned, and the setup scripts will be executed to configure your environment.

**Note**: _Ensure the repository URL is correct and accessible._
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Documentation: Enhance dotfiles_repo section

The current documentation lacks important details about security implications and usage.

Consider expanding the documentation:

 #### Option: `dotfiles_repo`
 
-Specify the URL of your GitHub repository containing your dotfiles. The repository will be cloned, and the setup scripts will be executed to configure your environment.
+Specify the URL of your GitHub repository containing your dotfiles. The repository will be cloned, and the setup scripts will be executed to configure your environment. This feature allows you to automate your environment setup using version-controlled configuration files.
+
+**Repository Requirements:**
+- Must be a public GitHub repository
+- URL format: `https://github.com/username/repository`
+- Must contain one of the following setup scripts:
+  - `install.sh`
+  - `setup.sh`
+  - `bootstrap.sh`
+
+**Security Considerations:**
+- The setup script runs with root privileges
+- Carefully review the setup script before using it
+- Avoid scripts that download or execute external code
+- Repository contents are removed after setup
 
-**Note**: _Ensure the repository URL is correct and accessible._
+**Example:**
+```yaml
+dotfiles_repo: "https://github.com/username/dotfiles"
+```

@oleander oleander closed this Jan 25, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jan 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant