via-xephyr.py 844 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. import os
  3. import pathlib
  4. import random
  5. import subprocess
  6. def _main():
  7. image_id = subprocess.run(
  8. [
  9. "podman",
  10. "build",
  11. pathlib.Path(__file__).parent,
  12. "--iidfile",
  13. "/dev/stdout",
  14. ],
  15. text=True,
  16. stdout=subprocess.PIPE,
  17. check=True,
  18. ).stdout.rsplit("\n", maxsplit=1)[1]
  19. assert image_id.startswith("sha256:"), image_id
  20. display_name = ":" + str(random.randint(1, 2**31 - 1))
  21. subprocess.Popen(["Xephyr", display_name, "-resizeable"])
  22. os.execvpe(
  23. "podman",
  24. [
  25. "podman",
  26. "container",
  27. "runlabel",
  28. "podman-run-x11",
  29. image_id,
  30. ],
  31. os.environ | {"DISPLAY": display_name},
  32. )
  33. if __name__ == "__main__":
  34. _main()