Skip to content

fix: install script bugs (chmod 666, insserv typo, process handling)#35159

Merged
feici02 merged 8 commits intomainfrom
copilot-main-install-script-fixes
Apr 21, 2026
Merged

fix: install script bugs (chmod 666, insserv typo, process handling)#35159
feici02 merged 8 commits intomainfrom
copilot-main-install-script-fixes

Conversation

@tomchon
Copy link
Copy Markdown
Contributor

@tomchon tomchon commented Apr 16, 2026

问题背景

在 3.3.6 非 root 打包 backport 的 review 中,发现 main 分支安装/卸载脚本存在同类问题,可能影响安全性、跨平台兼容性和升级/卸载稳定性。本 PR 将相关修复同步到 main。

主要修复

  1. 安装脚本安全与兼容性修复
  • 修复 /etc/hosts 处理:非 root 模式跳过修改,root 模式仅在可写时追加,避免不安全权限操作。
  • 修复 SysV 注册拼写问题:insserv 参数多余字符导致注册失败。
  • 修复进程清理兼容性:去除 GNU 专有依赖,改为更稳妥的逐行处理。
  • 增强 non-root 运行提示:增加 systemd 版本检查与 linger 提示。
  1. 升级路径与安装目录保护
  • 升级场景支持读取 .install_path,尽量保持历史安装目录。
  • 新增危险路径校验,防止异常路径导致安装过程误操作系统目录。
  • 移除 install_main_path 中对 data/log/cfg 链接目录的危险删除逻辑,降低数据误删风险。
  1. 卸载脚本修复
  • 非 root 卸载补齐路径与模式识别逻辑。
  • 卸载时增加环境变量清理(PATH/LD_LIBRARY_PATH)。
  • 修复 taosgen 命名不一致问题。
  • 修复 sed 正则转义,避免误删无关环境变量行。

影响范围

  • packaging/tools/install.sh
  • packaging/tools/install_client.sh
  • packaging/tools/remove.sh
  • packaging/tools/remove_client.sh

验证建议

  • root / non-root 安装、升级、卸载全流程回归。
  • 覆盖 systemd 低版本与高版本场景。
  • 覆盖 bash 与 zsh 不同登录 shell 组合。
  • 覆盖自定义安装目录与历史 .install_path 升级场景。
  • 重点验证数据目录与日志目录在升级中不被误删。

关联 PR

- install.sh: remove chmod 666 /etc/hosts, skip in non-root mode
- install.sh: fix insserv $1} stray brace typo
- install.sh: replace xargs -r with portable while-read in kill_process()
- install_client.sh: fix kill_client() multi-PID handling

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tomchon tomchon requested a review from feici02 as a code owner April 16, 2026 09:22
Copilot AI review requested due to automatic review settings April 16, 2026 09:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes several issues in the TDengine packaging install scripts, focusing on security (unsafe /etc/hosts permissions), portability (GNU-only xargs -r), and more robust process/service handling during install/upgrade.

Changes:

  • Avoid insecure /etc/hosts permission changes; skip modification in non-root installs and only append when writable.
  • Replace xargs -r PID killing with while read loops for better cross-platform compatibility.
  • Fix a SysV init insserv invocation typo (insserv $1}insserv $1).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packaging/tools/install.sh Safer /etc/hosts handling, portable PID-kill fallback, and SysV insserv typo fix
packaging/tools/install_client.sh More consistent handling of multiple PIDs when killing client processes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packaging/tools/install.sh Outdated
Comment thread packaging/tools/install_client.sh Outdated
Comment thread packaging/tools/install_client.sh Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the installation scripts by refining process termination logic, enhancing the safety of /etc/hosts modifications, and fixing a syntax error in the SysVinit service installation. Specifically, it replaces xargs with while-read loops for killing processes and adds checks for user permissions before attempting to modify system files. A review comment suggests using pgrep -x in install_client.sh to more accurately target specific processes and avoid accidental termination of unrelated services.

Comment thread packaging/tools/install_client.sh Outdated
tomchon and others added 2 commits April 16, 2026 17:30
- install.sh: add || : to while-read pipeline in kill_process() fallback
- install_client.sh: use pgrep -x for exact match, add || true for set -e safety

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Non-root install requires systemd >= 232 for user service support.
Shows clear error on older systems (e.g., CentOS 7 with systemd 219).
Also adds linger reminder after successful non-root install if not enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 17, 2026 11:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

packaging/tools/install.sh:737

  • In add_newHostname_to_hosts, grep $1 uses an unquoted/regex pattern from user-provided hostname. If the hostname contains regex metacharacters (e.g. .) or starts with -, grep can mis-match or treat it as an option. Use fixed-string matching and -- (e.g., grep -F -- "$1") and quote $1 when reading from /etc/hosts.
  fi
  localIp="127.0.0.1"
  OLD_IFS="$IFS"
  IFS=" "
  iphost=$(cat /etc/hosts | grep $1 | awk '{print $1}')

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packaging/tools/install.sh
…, fix remove_client non-root

- install.sh: Read .install_path in setup_env() to preserve custom install
  directory on upgrade without -d flag
- remove.sh: Add clean_env_file() to remove PATH/LD_LIBRARY_PATH from shell
  rc file on non-root uninstall
- remove_client.sh: Add user_mode detection, .install_path reading, correct
  paths for non-root, env cleanup. Previously completely broken for non-root.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 20, 2026 07:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packaging/tools/remove_client.sh
Comment thread packaging/tools/remove_client.sh
Comment thread packaging/tools/remove_client.sh
Comment thread packaging/tools/install.sh
Comment thread packaging/tools/install.sh Outdated
…stall_main_path

The rm -rf was introduced in PR #34172 assuming these paths are always
symlinks. When upgrading from older versions that used -d to install data
directly in ${installDir}/data (real directory), this would delete user data.

These rm calls are entirely unnecessary:
- cfg_link_dir and log_link_dir: ln -sf in install_config/install_log
  already overwrites existing symlinks
- data_link_dir: install_data() is NOT called during upgrade, so removing
  the symlink means it won't be recreated

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tomchon tomchon force-pushed the copilot-main-install-script-fixes branch from e6d3fce to b53dc73 Compare April 20, 2026 07:58
Reject corrupted .install_path values like '/', '/bin', '/usr', '/etc',
'/var' to prevent install_main_path from operating on system directories.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 20, 2026 10:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packaging/tools/remove_client.sh
Comment thread packaging/tools/remove.sh
Comment thread packaging/tools/remove.sh Outdated
Comment thread packaging/tools/remove_client.sh Outdated
tomchon and others added 2 commits April 20, 2026 18:32
…an_env_file

- remove_client.sh: taosgen_name was 'gen' (taosgen) but
  install_client.sh installs it as 'taosgen' (taostaosgen).
  Fixed to match installer naming.
- remove.sh & remove_client.sh: escape regex metacharacters (especially
  '.' in .local paths) when building sed patterns for clean_env_file to
  avoid accidentally removing unrelated export lines.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… validation

Replace weak blacklist (/bin, /usr, /etc, /var) with a stronger check:
path must end with '/' (e.g., /taos). This is a natural whitelist
since install always sets installDir="${taosDir}/${PREFIX}", so any
legitimate .install_path will end with /taos.

Rejects /home, /opt, /root, /usr/local, or any other polluted value.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 03:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packaging/tools/remove.sh
Comment thread packaging/tools/install.sh
Comment thread packaging/tools/install.sh
Comment thread packaging/tools/install_client.sh
Comment thread packaging/tools/remove_client.sh
Comment thread packaging/tools/remove_client.sh
Copy link
Copy Markdown
Member

@feici02 feici02 left a comment

Choose a reason for hiding this comment

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

LGTM

@feici02 feici02 merged commit c5bf416 into main Apr 21, 2026
6 checks passed
@feici02 feici02 deleted the copilot-main-install-script-fixes branch April 21, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants