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

More robust user home #147

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Conversation

Erotemic
Copy link
Contributor

@Erotemic Erotemic commented Sep 15, 2024

Fixes #145 and makes the code a tiny bit more concise with a tiny bit less special branch cases.

The solution was guided by this stack overflow post: https://superuser.com/questions/484277/get-home-directory-by-username

Summary by CodeRabbit

  • New Features

    • Enhanced dynamic resolution of the RUN_AS_HOME environment variable for improved accuracy in user home directory assignment.
  • Bug Fixes

    • Corrected the logic for determining RUN_AS_HOME to ensure it reflects the correct home directory for both sudo and non-sudo users.

Copy link
Contributor

coderabbitai bot commented Sep 15, 2024

Walkthrough

The changes in this pull request focus on improving the determination of the RUN_AS_HOME environment variable in the installer.sh and utils/common.sh scripts. The previous implementation used hardcoded paths to assign the home directory based on the user type, which could lead to inaccuracies. The updated code now uses the eval echo ~"$RUN_AS" command to dynamically resolve the home directory, ensuring it correctly reflects the actual home directory of the user executing the script.

Changes

File(s) Change Summary
installer.sh, utils/common.sh Updated the logic for setting RUN_AS_HOME to use eval echo ~"$RUN_AS" for dynamic home directory resolution instead of hardcoded paths.

Assessment against linked issues

Objective Addressed Explanation
Home directory in utils/common.sh is not robust. (#145)

🐰 In a world of paths and homes so bright,
I found a way to make it right.
With eval I leap, to find my space,
No more hardcodes, just a warm embrace.
So hop along, my friends, rejoice,
For every user has a voice! 🥕


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f380c0a and 931add0.

Files selected for processing (2)
  • installer.sh (1 hunks)
  • utils/common.sh (1 hunks)
Additional context used
Shellcheck
installer.sh

[warning] 9-9: Declare and assign separately to avoid masking return values.

(SC2155)

utils/common.sh

[warning] 48-48: Declare and assign separately to avoid masking return values.

(SC2155)

Additional comments not posted (2)
installer.sh (1)

9-9: LGTM! The change improves the robustness of determining the user's home directory.

The updated code uses eval echo ~"$RUN_AS" to dynamically resolve the home directory of the user stored in RUN_AS. This approach is more reliable than the previous implementation, which relied on hardcoded paths based on the user type.

By dynamically resolving the home directory, the script can now accurately determine the correct path regardless of the actual location of the user's home directory. This change addresses the concern raised in issue #145 and enhances the script's compatibility across different environments.

Note: The static analysis hint suggesting to declare and assign separately is a false positive in this case. The command substitution is intentional and necessary to dynamically resolve the home directory.

Tools
Shellcheck

[warning] 9-9: Declare and assign separately to avoid masking return values.

(SC2155)

utils/common.sh (1)

48-48: Excellent improvement to the home directory determination logic!

The change from hardcoded paths to dynamic evaluation using eval echo ~"$RUN_AS" enhances the flexibility and correctness of the script. It ensures that RUN_AS_HOME accurately reflects the actual home directory of the user, regardless of whether they are a sudo user or root.

This modification streamlines the logic by consolidating the home directory assignment into one line, improving code readability and maintainability.

Tools
Shellcheck

[warning] 48-48: Declare and assign separately to avoid masking return values.

(SC2155)


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 generate interesting stats about this repository and render them as a table.
    -- @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 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.

@goldyfruit goldyfruit added the enhancement New feature or request label Sep 16, 2024
@goldyfruit goldyfruit added this to the Descent milestone Sep 16, 2024
@goldyfruit goldyfruit merged commit ab513c6 into OpenVoiceOS:main Sep 16, 2024
@goldyfruit
Copy link
Member

Thanks @Erotemic 👍

goldyfruit added a commit that referenced this pull request Sep 16, 2024
goldyfruit added a commit that referenced this pull request Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Home directory in utils/common.sh is not robust.
2 participants