This commit is contained in:
2026-01-19 06:24:09 -08:00
parent a961ac3ce7
commit 7ddf0065d1
45 changed files with 627 additions and 411 deletions

View File

@@ -55,11 +55,13 @@ from __future__ import annotations
import argparse
import os
import platform
import re
from pathlib import Path
import shutil
import subprocess
import sys
import time
from typing import Optional
def run(cmd: list[str], quiet: bool = False, debug: bool = False, cwd: Optional[Path] = None) -> None:
@@ -1088,7 +1090,7 @@ def main() -> int:
# 7. CLI Verification
pb.update("Verifying CLI configuration...")
try:
rc = subprocess.run(
cli_verify_result = subprocess.run(
[
str(venv_python),
"-c",
@@ -1098,7 +1100,7 @@ def main() -> int:
stderr=subprocess.DEVNULL,
check=False,
)
if rc.returncode != 0:
if cli_verify_result.returncode != 0:
cmd = [
str(venv_python),
"-c",
@@ -1335,7 +1337,7 @@ if (Test-Path (Join-Path $repo 'CLI.py')) {
else:
# POSIX
# If running as root (id 0), prefer /usr/bin or /usr/local/bin which are standard on PATH
if os.getuid() == 0:
if hasattr(os, "getuid") and os.getuid() == 0:
user_bin = Path("/usr/local/bin")
if not os.access(user_bin, os.W_OK):
user_bin = Path("/usr/bin")

View File

@@ -369,7 +369,11 @@ def is_elevated() -> bool:
return False
else:
try:
return os.geteuid() == 0
# Use getattr for platform-specific os methods to satisfy Mypy
geteuid = getattr(os, "geteuid", None)
if geteuid:
return bool(geteuid() == 0)
return False
except Exception:
return False
except Exception:
@@ -476,9 +480,9 @@ def fix_permissions_unix(
user = getpass.getuser()
try:
pw = pwd.getpwnam(user)
pw = pwd.getpwnam(user) # type: ignore[attr-defined]
uid = pw.pw_uid
gid = pw.pw_gid if not group else grp.getgrnam(group).gr_gid
gid = pw.pw_gid if not group else grp.getgrnam(group).gr_gid # type: ignore[attr-defined]
except Exception:
logging.warning("Could not resolve user/group to uid/gid; skipping chown.")
return False
@@ -500,16 +504,18 @@ def fix_permissions_unix(
except Exception:
# Best-effort fallback: chown/chmod individual entries
for root_dir, dirs, files in os.walk(path):
try:
os.chown(root_dir, uid, gid)
except Exception:
pass
for fn in files:
fpath = os.path.join(root_dir, fn)
if hasattr(os, "chown"):
try:
os.chown(fpath, uid, gid)
os.chown(root_dir, uid, gid)
except Exception:
pass
for fn in files:
fpath = os.path.join(root_dir, fn)
if hasattr(os, "chown"):
try:
os.chown(fpath, uid, gid)
except Exception:
pass
# Fix modes: directories 0o755, files 0o644 (best-effort)
for root_dir, dirs, files in os.walk(path):
@@ -1454,11 +1460,12 @@ def main(argv: Optional[list[str]] = None) -> int:
if p.exists():
client_found = p
break
run_client_script = None
if client_found:
# Prefer run_client helper located in the cloned repo; if missing, fall back to top-level scripts folder helper.
script_dir = Path(__file__).resolve().parent
helper_candidates = [dest / "run_client.py", script_dir / "run_client.py"]
run_client_script = None
for cand in helper_candidates:
if cand.exists():
run_client_script = cand
@@ -1477,7 +1484,7 @@ def main(argv: Optional[list[str]] = None) -> int:
)
else:
if getattr(args, "install_service", False):
if run_client_script.exists():
if run_client_script and run_client_script.exists():
cmd = [
str(venv_py),
str(run_client_script),
@@ -1513,7 +1520,7 @@ def main(argv: Optional[list[str]] = None) -> int:
dest / "run_client.py",
)
if getattr(args, "uninstall_service", False):
if run_client_script.exists():
if run_client_script and run_client_script.exists():
cmd = [
str(venv_py),
str(run_client_script),