1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-24 21:15:10 +03:00

allow detecting when in chroot (MR 2063)

Touch the file /in-pmbootstrap in chroots so that we can avoid
performing automated actions that should only happen on a real device
(like flashing the kernel).
This commit is contained in:
Caleb Connolly 2021-06-03 23:36:37 +01:00 committed by Clayton Craft
parent 7145ab2e50
commit e27bb82252
No known key found for this signature in database
GPG key ID: 7A3461CA187CEA54
2 changed files with 16 additions and 0 deletions

View file

@ -30,6 +30,16 @@ def copy_resolv_conf(args, suffix="native"):
pmb.helpers.run.root(args, ["touch", chroot])
def mark_in_chroot(args, suffix="native"):
"""
Touch a flag so we can know when we're running in chroot (and
don't accidentally flash partitions on our host)
"""
in_chroot_file = f"{args.work}/chroot_{suffix}/in-pmbootstrap"
if not os.path.exists(in_chroot_file):
pmb.helpers.run.root(args, ["touch", in_chroot_file])
def setup_qemu_emulation(args, suffix):
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
if not pmb.parse.arch.cpu_emulation_required(args, arch):
@ -53,6 +63,7 @@ def init(args, suffix="native"):
pmb.chroot.mount(args, suffix)
setup_qemu_emulation(args, suffix)
mark_in_chroot(args, suffix)
if os.path.islink(f"{chroot}/bin/sh"):
pmb.config.workdir.chroot_check_channel(args, suffix)
copy_resolv_conf(args, suffix)