Skip to content

Linux 支持(Ubuntu 26.04 实测)——install.py find_asar 增加 /opt/ZCode、/usr/li… - #3

Merged
xhwxt merged 1 commit into
xhwxt:mainfrom
tuigou888:linux-support
Sep 10, 2026
Merged

Linux 支持(Ubuntu 26.04 实测)——install.py find_asar 增加 /opt/ZCode、/usr/li…#3
xhwxt merged 1 commit into
xhwxt:mainfrom
tuigou888:linux-support

Conversation

@tuigou888

Copy link
Copy Markdown

Linux 支持(Ubuntu 26.04 实测):安装器自动探测 /opt/ZCode、sudo 安装支持、语法自检适配

…b/zcode 等 deb/rpm 候选路径与 /opt、/usr/lib、/usr/local/lib 一层兜底扫描(对等 win32 兜底),非 sudo 运行遇 root 属主 asar 给出 sudo 指引而非 traceback;sudo 安装支持:real_home() 按 SUDO_USER 解析真实用户家目录,数据目录/MCP 注册//usage 命令照常落 ~/.zcode,运行时副本与 config 写入后 chown 回普通用户(泵与客户端以普通用户身份读写,asar 保持 root 属主);patch_install.py zcode_exe_for 增加 Linux 布局 <root>/zcode(语法自检在 Linux 真正生效,ELECTRON_RUN_AS_NODE 实测 exit=0),install 前置可写性预检友好拦截权限错误,L() 语言回退兼容 sudo 场景;install_monitor.py 缺省 asar 增加 Linux 分支;fuse 实测 EmbeddedAsarIntegrityValidation=0、RunAsNode=1 满足注入前提
Copilot AI lite review requested due to automatic review settings September 9, 2026 10:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Several sudo-path writes/chown flows are incomplete or inconsistent (ownership not restored in some branches, and one permission check is incorrect), which can cause real permission failures for Linux system installs.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR extends the installer/patcher scripts to better support Linux (validated on Ubuntu 26.04), including auto-detection of common Linux ZCode install layouts and improved behavior when running installers via sudo so runtime/config artifacts land in the real user’s home directory.

Changes:

  • Add Linux app.asar candidate paths and a Linux fallback scan in find_asar().
  • Add sudo-aware “real home” resolution plus ownership handoff (chown) for generated artifacts.
  • Improve Linux defaults and permission guidance for system install locations (e.g., /opt).
File summaries
File Description
patch_install.py Adds sudo-aware config-lang lookup, Linux executable inference for syntax check, and early permission messaging before patching asar.
install.py Adds Linux asar auto-detection, sudo real-home handling, ownership handoff helper, and sudo guidance when system locations are not writable.
install_monitor.py Adds Linux default asar path fallback when invoked without explicit argv.
Review details

Suppressed comments (2)

install.py:299

  • When running under sudo, install_command creates ~/.zcode/commands and copies usage.md into the real user's home but does not chown them back to the real user, leaving the /usage command root-owned.
        ZCODE_CONFIG.parent.mkdir(parents=True, exist_ok=True)
        chown_to_user(ZCODE_CONFIG.parent)
        if ZCODE_CONFIG.is_file():
            shutil.copy2(ZCODE_CONFIG, ZCODE_CONFIG.with_suffix(".json.zusage.bak"))
        ZCODE_CONFIG.write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")
        chown_to_user(ZCODE_CONFIG)

install.py:264

  • In the "migrate old config" branch, running under sudo will copy the repo config into the real user's home but leaves both the directory and the copied config root-owned. This is inconsistent with the new chown_to_user behavior in the generated-config path and can cause permission issues later.
        cfg.parent.mkdir(parents=True, exist_ok=True)
        chown_to_user(cfg.parent)
        cfg.write_text(json.dumps(vals, indent=2, ensure_ascii=False), encoding="utf-8")
        chown_to_user(cfg)
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread install.py
Comment on lines +195 to +205
def chown_to_user(path):
"""sudo 运行时把产物归还给真实用户(数据目录、config、注册文件);
asar 属系统安装(root 所有),保持原属主不动。非 sudo 是 no-op。"""
sudo_user = _sudo_user()
if not sudo_user:
return
try:
import pwd
st = pwd.getpwnam(sudo_user)
os.chown(path, st.pw_uid, st.pw_gid)
except (KeyError, OSError, AttributeError):
Comment thread install.py
Comment on lines +416 to +418
if (sys.platform != "win32" and os.geteuid() != 0
and not os.access(asar, os.W_OK)):
hint = " ".join(sys.argv[1:])
Comment thread patch_install.py
Comment on lines 303 to +311
assert LOADER.exists(), L(f"loader 缺失:{LOADER}", f"loader missing: {LOADER}")
if not os.access(ASAR, os.W_OK) or not os.access(ASAR.parent, os.W_OK):
print(L(f"[权限] app.asar 或所在目录不可写(Linux 上 /opt 等系统位置需要 root):{ASAR}",
f"[permission] app.asar or its directory is not writable (Linux system locations like /opt need root): {ASAR}"))
print(L("请用 sudo 重跑(推荐走一键安装,会自动处理目标定位与数据目录归属):",
"Please re-run with sudo (the one-shot installer is recommended; it resolves the target and data-dir ownership automatically):"))
print(L(" sudo python install.py # 自动探测(含 /opt/ZCode)",
" sudo python install.py # auto-detects (including /opt/ZCode)"))
return False
@xhwxt
xhwxt merged commit 23d20ae into xhwxt:main Sep 10, 2026
xhwxt added a commit that referenced this pull request Sep 10, 2026
….md 归还普通用户,修 PR #3 审查发现的遗漏;此前 umask 077 的用户 sudo 安装后 /usage 命令会因 root 属主目录不可读)
@xhwxt

xhwxt commented Sep 10, 2026

Copy link
Copy Markdown
Owner

感谢贡献!已完成审查并合并(23d20ae),Linux 用户从此可以直接用了 🎉

审查结论

  • 实现与 v60 的 macOS 支持同构,路径探测、兜底扫描、权限指引、sudo 产物归属(real_home + chown)思路都对;fuse 前提(EmbeddedAsarIntegrityValidation=0、RunAsNode=1)的实测记录尤其关键,这正是注入可行性的硬前提。
  • Windows 侧已验证无行为影响:模块级 real_home() 在非 sudo 下等价 Path.home(),py_compile 与 --help 均通过。
  • Copilot 提到的两处 chown 缺口逐条核实过:prepare_config 迁移分支那条是误报(它引用的代码里已有 chown_to_user 调用);install_command 那条属实——sudo 安装后 ~/.zcode/commands 与 usage.md 属 root,umask 077 的用户会读不了 /usage。已在 main 补了 follow-up 提交(70e03c7),欢迎复核。
  • 小观察不阻塞:install.py 的权限预检只查了 asar 本身没查父目录(原子替换需要父目录写权限),不过 patch_install.py 的第二道预检两项都查了,会兜住。

如果方便,欢迎在其它发行版/安装布局上也反馈实测情况(直接回 issue #2 或开新 issue 都行)。

xhwxt referenced this pull request in hey-money/zcode-token-usage-statusbar Sep 10, 2026
- zusage.py: force sids missing from the local db are fetched from a
  remote host over SSH (same zusage.py json protocol) and merged into
  the payload with remote/host annotations; remote 'today' carried as
  remote_today; known_sids existence signal + negative cache (2min ok /
  60s error backoff) so unknown sessions do not re-probe and local
  sessions never probe
- inject-main.cjs: track remote sids from payload; while a remote
  session is focused, poll at remote.poll_ms (default 3s) since local
  fs.watch cannot see remote writes; local sessions stay event-driven
- overlay.js: remote badge (host + last error in tooltip) and today
  segment switches to remote_today when a remote session is displayed
- config.example.json + README(zh/en): remote section docs

Requires passwordless SSH to the server; remote host deploys the same
zusage.py with no remote section (recursion-safe).
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.

4 participants