Skip to content

Conversation

@Lirzh
Copy link

@Lirzh Lirzh commented Oct 4, 2025

更加人性化的提示

  1. 对于 install.sh :添加了提示以及退路

    • 新bug:对于 uninstall.sh 和 reset.sh 应也有与 install.sh 相同的环境变量问题
    • 在实际测试(KVM的 debian13)中,测试尝试修复后的 uninstall.sh,出现了奇怪的Bug,这是日志
      环境:KVM 的 debian13,CPU为I7 9700(amd 64),不过网络为校园网(未备案的网站访问不了)
      Lirzh.log

Summary by CodeRabbit

  • New Features

    • Added bilingual (English/Chinese) diagnostics during install/uninstall when the detected user differs from the environment user.
    • Displayed guidance for restoring service startup (e.g., resurrection and startup commands) during install.
  • Bug Fixes

    • Automatic environment normalization during install/uninstall by aligning user-related variables to root when needed.
    • Preflight root-permission check in uninstall to prevent proceeding without required privileges, with clear bilingual instructions.
  • Style

    • Minor formatting cleanups around prompts and verification output.

@coderabbitai
Copy link

coderabbitai bot commented Oct 4, 2025

Walkthrough

Two installer scripts were updated. install/install.sh now detects when actual_user differs from USER, prints English and Chinese diagnostics, force-exports USER, LOGNAME, HOME, and PWD to root values, and echoes commands related to Hydro startup and pm2 (resurrect, unstartup, startup) with bilingual guidance. install/uninstall.sh adds a root permission preflight check with bilingual messaging and exit, and includes the same environment remediation when actual_user differs from USER prior to the confirmation delay. Minor whitespace adjustments were made.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “More humanized prompts” directly reflects the addition of more user-friendly and bilingual messages in the install and uninstall scripts, capturing a key, user-facing change introduced by the pull request. Although it does not mention the accompanying environment fallback logic, it clearly signals the primary enhancement to script prompts without introducing irrelevant details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d05109 and 5a555ee.

📒 Files selected for processing (2)
  • install/install.sh (1 hunks)
  • install/uninstall.sh (2 hunks)
🧰 Additional context used
🪛 Shellcheck (0.11.0)
install/uninstall.sh

[warning] 9-9: This $? refers to echo/printf, not a previous command. Assign to variable to avoid it being overwritten.

(SC2320)


[warning] 26-26: actual_user is referenced but not assigned.

(SC2154)

Comment on lines +4 to +9
if [ $EUID != 0 ]; then
echo "This script requires root however you are currently running under another user."
echo "Please use 'sudo su' to switch to root user before running this script."
echo "卸载脚本需要使用 root 权限,请先使用 sudo su 切换到 root 用户后再运行此脚本。"
# sudo "$0" "$@"
exit $?
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Return a failure code when root is required

After the informational echo calls, $? is 0, so exit $? reports success even though the script aborted. Please return a non-zero status (for example exit 1) so callers can detect the failure.

-    exit $?
+    exit 1
📝 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
if [ $EUID != 0 ]; then
echo "This script requires root however you are currently running under another user."
echo "Please use 'sudo su' to switch to root user before running this script."
echo "卸载脚本需要使用 root 权限,请先使用 sudo su 切换到 root 用户后再运行此脚本。"
# sudo "$0" "$@"
exit $?
if [ $EUID != 0 ]; then
echo "This script requires root however you are currently running under another user."
echo "Please use 'sudo su' to switch to root user before running this script."
echo "卸载脚本需要使用 root 权限,请先使用 sudo su 切换到 root 用户后再运行此脚本。"
# sudo "$0" "$@"
exit 1
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 9-9: This $? refers to echo/printf, not a previous command. Assign to variable to avoid it being overwritten.

(SC2320)

🤖 Prompt for AI Agents
In install/uninstall.sh around lines 4 to 9, the script exits with "exit $?"
after printing the root-required messages which returns 0 (success); change that
to a non-zero exit (e.g., exit 1) so the script reports failure when not run as
root; simply replace "exit $?" with "exit 1" immediately after the echo lines.

Comment on lines +26 to +37
if [ "$actual_user" != "$USER" ]; then
echo "In the current environment, the environmental variable does not belong to root, which can lead to failed uninstallation and strange errors"
echo "在目前环境下,环境变量并不属于 root,这会导致卸载失败以及奇怪的错误"
echo "Try to fix it..."
echo "尝试修复..."
export USER=root
export LOGNAME=root
export HOME=/root
export PWD=/root
echo "This might work"
echo "这可能会奏效"
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 | 🟠 Major

Define actual_user before using it

actual_user is never assigned, so the test on Line 26 always treats it as empty, entering this block and printing misleading messages while forcibly rewriting env vars. Add actual_user=$(whoami) (as in install.sh) before the comparison.

-read -p "> " confirm;
+read -p "> " confirm;
 if [ "$confirm" != "Yes, do as I say!" ];then
   echo "Aborted."
   exit;
 fi
+actual_user=$(whoami)
 if [ "$actual_user" != "$USER" ]; then
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 26-26: actual_user is referenced but not assigned.

(SC2154)

🤖 Prompt for AI Agents
In install/uninstall.sh around lines 26 to 37, actual_user is never assigned so
the if-test always treats it as empty and the script unnecessarily overwrites
environment variables; fix it by assigning actual_user=$(whoami) (same as
install.sh) immediately before the comparison, then keep the existing if [
"$actual_user" != "$USER" ] conditional and its body unchanged so the check
behaves correctly and only runs when users differ.

actual_user=$(whoami)
if [ "$actual_user" != "$USER" ]; then
echo "In the current environment, the environment variable does not belong to the root, which will cause Hydro to fail to start up properly after the server restart"
echo "在目前环境下,环境变量并不属于 root,这会导致服务器重启后 Hydro 可能不能正常自启动"
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps the wording should be optimized (?)

Copy link
Author

Choose a reason for hiding this comment

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

换成 环境变量有误 ?

@undefined-moe
Copy link
Member

This is a 'script'. If you already know it will broke in some environment that you want to support, find out the most fundamental reason and fix it automatically instead of telling user what to do - likely they are going to ignore those messages.

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.

3 participants