Skip to content

fix: correct sudo usage in node installer#21

Open
MuDerakhshan wants to merge 1 commit into
PasarGuard:mainfrom
MuDerakhshan:fix-node-install-sudo
Open

fix: correct sudo usage in node installer#21
MuDerakhshan wants to merge 1 commit into
PasarGuard:mainfrom
MuDerakhshan:fix-node-install-sudo

Conversation

@MuDerakhshan

@MuDerakhshan MuDerakhshan commented Jun 14, 2026

Copy link
Copy Markdown

Summary

Fix root/non-root handling in install_node_command().

Problem

The current implementation invokes sudo when already running as root and runs the installer directly when not running as root:

if [ "$(id -u)" = "0" ]; then
    sudo bash -c "$(curl -sL https://github.com/PasarGuard/scripts/raw/main/pg-node.sh)" @ install
else
    bash -c "$(curl -sL https://github.com/PasarGuard/scripts/raw/main/pg-node.sh)" @ install
fi

This causes node installation to fail on systems where sudo is not installed.

Reproduction

Environment:

  • Debian 13
  • Logged in as root
  • sudo package not installed

Command:

pasarguard install-node

Output:

Running node installation with sudo...
sudo: command not found

Verification

After applying this patch:

Running node installation as root...
Installing PasarGuard Node
...

The installer proceeds normally and reaches the next installation steps.

Solution

  • Run the node installer directly when already running as root.
  • Use sudo only for non-root users.

Additionally, pg-node.sh already performs multiple check_running_as_root checks, so this change aligns the invocation logic with the installer requirements.

Summary by CodeRabbit

  • Bug Fixes
    • Improved node installation script execution to properly handle different user permission levels.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 83f9cbcd-4a17-411b-bec2-98b6bd7d1542

📥 Commits

Reviewing files that changed from the base of the PR and between 945933b and 3518ab1.

📒 Files selected for processing (1)
  • pasarguard.sh

Walkthrough

In pasarguard.sh, the install_node_command function is updated so that when running as root (id -u == 0), the node installation script is executed directly with bash; when running as a non-root user, it is executed with sudo bash. All other control flow remains unchanged.

Changes

Root/Non-root Node Installation Fix

Layer / File(s) Summary
Root vs non-root bash invocation
pasarguard.sh
install_node_command now uses bash directly for root and sudo bash for non-root users when invoking the node installation script.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 A root needs no sudo, that much is true,
So bash runs alone when the uid is zero!
Non-root still politely says "sudo, please do,"
Three lines swapped cleanly — a tiny shell hero.
Hop hop, the script works for every user now! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: correcting reversed sudo logic in the node installer script.
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 unit tests (beta)
  • Create PR with unit tests

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.

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