pmbootstrap chroot --xauth: new option (MR 1944)

Make it easy to start any X11 application from the native chroot.
This commit is contained in:
Oliver Smith 2020-06-02 23:29:33 +02:00
parent 2dd707a7ea
commit 6d013b4472
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
2 changed files with 17 additions and 2 deletions

View File

@ -117,20 +117,31 @@ def chroot(args):
not suffix.startswith("buildroot_")):
raise RuntimeError("--user is only supported for native or"
" buildroot_* chroots.")
if args.xauth and suffix != "native":
raise RuntimeError("--xauth is only supported for native chroot.")
# apk: check minimum version, install packages
pmb.chroot.apk.check_min_version(args, suffix)
if args.add:
pmb.chroot.apk.install(args, args.add.split(","), suffix)
# Xauthority
env = {}
if args.xauth:
pmb.chroot.other.copy_xauthority(args)
env["DISPLAY"] = os.environ.get("DISPLAY")
env["XAUTHORITY"] = "/home/pmos/.Xauthority"
# Run the command as user/root
if args.user:
logging.info("(" + suffix + ") % su pmos -c '" +
" ".join(args.command) + "'")
pmb.chroot.user(args, args.command, suffix, output=args.output)
pmb.chroot.user(args, args.command, suffix, output=args.output,
env=env)
else:
logging.info("(" + suffix + ") % " + " ".join(args.command))
pmb.chroot.root(args, args.command, suffix, output=args.output)
pmb.chroot.root(args, args.command, suffix, output=args.output,
env=env)
def config(args):

View File

@ -493,6 +493,10 @@ def arguments():
default="tui")
chroot.add_argument("command", default=["sh", "-i"], help="command"
" to execute inside the chroot. default: sh", nargs='*')
chroot.add_argument("-x", "--xauth", action="store_true",
help="Copy .Xauthority and set environment variables,"
" so X11 applications can be started (native"
" chroot only)")
for action in [build_init, chroot]:
suffix = action.add_mutually_exclusive_group()
if action == chroot: