#!/usr/bin/env python3 """Install the container runner, app-menu entry and icons for the current user.""" import os from pathlib import Path import shutil def desktop_exec(path): """Quote one Exec argument at both desktop-entry escaping layers.""" value = str(path).replace("%", "%%") value = "".join("\\" + char if char in '\\"`$' else char for char in value) return ('"' + value + '"').replace("\\", "\\\\") def main(): root = Path(__file__).resolve().parent.parent runner = Path.home() / ".local/bin/moonmix-container" data_home = Path(os.environ.get("XDG_DATA_HOME") or Path.home() / ".local/share") runner.parent.mkdir(parents=True, exist_ok=True) shutil.copyfile(root / "tools/moonmix-container", runner) runner.chmod(0o755) # Reuse the native entry's app id and metadata so Wayland associates the # container window with this launcher. An absolute Exec avoids GUI PATH issues. desktop = data_home / "applications/org.latha.moonmix.desktop" desktop.parent.mkdir(parents=True, exist_ok=True) template = (root / "data/org.latha.moonmix.desktop").read_text() # GIO checks the executable before expanding %% field codes. Using env # also supports a literal percent sign in the runner's absolute path. desktop.write_text("".join( f"Exec=/usr/bin/env {desktop_exec(runner)}\n" if line.startswith("Exec=") else line for line in template.splitlines(keepends=True) )) desktop.chmod(0o644) for variant in ("scalable", "symbolic"): name = "org.latha.moonmix" + ("-symbolic" if variant == "symbolic" else "") + ".svg" relative = Path("icons/hicolor") / variant / "apps" / name destination = data_home / relative destination.parent.mkdir(parents=True, exist_ok=True) shutil.copyfile(root / "data" / relative, destination) destination.chmod(0o644) print(f"Installed runner: {runner}") print(f"Installed desktop launcher: {desktop}") if __name__ == "__main__": main()