Linux 支持(Ubuntu 26.04 实测)——install.py find_asar 增加 /opt/ZCode、/usr/li… - #3
Conversation
…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 满足注入前提
There was a problem hiding this comment.
🟡 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.asarcandidate paths and a Linux fallback scan infind_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.
| 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): |
| if (sys.platform != "win32" and os.geteuid() != 0 | ||
| and not os.access(asar, os.W_OK)): | ||
| hint = " ".join(sys.argv[1:]) |
| 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 |
….md 归还普通用户,修 PR #3 审查发现的遗漏;此前 umask 077 的用户 sudo 安装后 /usage 命令会因 root 属主目录不可读)
|
感谢贡献!已完成审查并合并(23d20ae),Linux 用户从此可以直接用了 🎉 审查结论:
如果方便,欢迎在其它发行版/安装布局上也反馈实测情况(直接回 issue #2 或开新 issue 都行)。 |
- 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).
Linux 支持(Ubuntu 26.04 实测):安装器自动探测 /opt/ZCode、sudo 安装支持、语法自检适配