fix: save config to temp file before sudo re-exec, skip TUI on return
This commit is contained in:
+19
-4
@@ -85,11 +85,20 @@ def build_iso(config: Path, output: Path, keep_rootfs: bool) -> None:
|
||||
@click.option("-o", "--output", type=click.Path(path_type=Path), default=None, help="Output directory")
|
||||
@click.option("--keep-rootfs", is_flag=True, help="Don't remove rootfs after ISO generation")
|
||||
@click.option("-y", "--yes", is_flag=True, help="Skip confirmation prompts")
|
||||
def interactive(mode: str | None, output: Path | None, keep_rootfs: bool, yes: bool) -> None:
|
||||
@click.option("--config", "config_file", type=click.Path(path_type=Path), default=None,
|
||||
help="Load config from file (used by sudo re-exec)")
|
||||
def interactive(mode: str | None, output: Path | None, keep_rootfs: bool, yes: bool,
|
||||
config_file: Path | None) -> None:
|
||||
"""Launch interactive TUI — select distro, packages, and build."""
|
||||
from .tui import run_interactive, banner as tui_banner
|
||||
|
||||
cfg = run_interactive()
|
||||
# load config from file (sudo re-exec) or run TUI
|
||||
if config_file and config_file.exists():
|
||||
import json
|
||||
cfg = json.loads(config_file.read_text())
|
||||
config_file.unlink(missing_ok=True)
|
||||
else:
|
||||
cfg = run_interactive()
|
||||
|
||||
# override mode if flag given
|
||||
if mode:
|
||||
@@ -110,12 +119,18 @@ def interactive(mode: str | None, output: Path | None, keep_rootfs: bool, yes: b
|
||||
console = Console()
|
||||
|
||||
# check mode and re-exec if needed
|
||||
import shutil as _shutil
|
||||
if cfg["_mode"] == "root" and os.geteuid() != 0:
|
||||
console.print("[bold yellow]Root mode selected but not root. Re-executing with sudo...[/]")
|
||||
import subprocess as _sp
|
||||
import site
|
||||
args = [sys.executable, "-m", "euri_mklive", "interactive", "--root"]
|
||||
import json
|
||||
|
||||
# save config to temp file for sudo re-exec
|
||||
cfg_file = Path(tempfile.mktemp(suffix=".json", prefix="euri-cfg-"))
|
||||
cfg_file.write_text(json.dumps(cfg))
|
||||
|
||||
args = [sys.executable, "-m", "euri_mklive", "interactive", "--root",
|
||||
"--config", str(cfg_file)]
|
||||
if keep_rootfs:
|
||||
args.append("--keep-rootfs")
|
||||
if output:
|
||||
|
||||
Reference in New Issue
Block a user