2023-01-22 18:11:10 +00:00
|
|
|
# Copyright 2023 Attila Szollosi
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-08-24 21:07:36 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import pmb.chroot
|
2021-08-25 01:00:59 +00:00
|
|
|
import pmb.config.pmaports
|
2017-09-28 22:05:00 +00:00
|
|
|
import pmb.flasher
|
2017-09-02 03:53:58 +00:00
|
|
|
import pmb.helpers.frontend
|
2017-08-24 21:07:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_zip(args, suffix):
|
|
|
|
"""
|
|
|
|
Create android recovery compatible installer zip.
|
|
|
|
"""
|
|
|
|
zip_root = "/var/lib/postmarketos-android-recovery-installer/"
|
|
|
|
rootfs = "/mnt/rootfs_" + args.device
|
2017-09-02 03:53:58 +00:00
|
|
|
flavor = pmb.helpers.frontend._parse_flavor(args)
|
2017-12-21 22:12:52 +00:00
|
|
|
method = args.deviceinfo["flash_method"]
|
2017-09-28 22:05:00 +00:00
|
|
|
vars = pmb.flasher.variables(args, flavor, method)
|
2017-08-24 21:07:36 +00:00
|
|
|
|
|
|
|
# Install recovery installer package in buildroot
|
|
|
|
pmb.chroot.apk.install(args,
|
|
|
|
["postmarketos-android-recovery-installer"],
|
|
|
|
suffix)
|
|
|
|
|
|
|
|
logging.info("(" + suffix + ") create recovery zip")
|
|
|
|
|
2019-02-16 19:53:22 +00:00
|
|
|
for key in vars:
|
|
|
|
pmb.flasher.check_partition_blacklist(args, key, vars[key])
|
|
|
|
|
2017-08-24 21:07:36 +00:00
|
|
|
# Create config file for the recovery installer
|
2017-09-28 22:05:00 +00:00
|
|
|
options = {
|
|
|
|
"DEVICE": args.device,
|
|
|
|
"FLASH_KERNEL": args.recovery_flash_kernel,
|
|
|
|
"ISOREC": method == "heimdall-isorec",
|
|
|
|
"KERNEL_PARTLABEL": vars["$PARTITION_KERNEL"],
|
|
|
|
"INITFS_PARTLABEL": vars["$PARTITION_INITFS"],
|
|
|
|
"SYSTEM_PARTLABEL": vars["$PARTITION_SYSTEM"],
|
|
|
|
"INSTALL_PARTITION": args.recovery_install_partition,
|
|
|
|
"CIPHER": args.cipher,
|
|
|
|
"FDE": args.full_disk_encryption,
|
|
|
|
}
|
|
|
|
|
2021-08-25 01:00:59 +00:00
|
|
|
# Backwards compatibility with old mkinitfs (pma#660)
|
|
|
|
pmaports_cfg = pmb.config.pmaports.read_config(args)
|
|
|
|
if pmaports_cfg.get("supported_mkinitfs_without_flavors", False):
|
|
|
|
options["FLAVOR"] = ""
|
|
|
|
else:
|
|
|
|
options["FLAVOR"] = f"-{flavor}" if flavor is not None else "-"
|
|
|
|
|
2017-09-28 22:05:00 +00:00
|
|
|
# Write to a temporary file
|
|
|
|
config_temp = args.work + "/chroot_" + suffix + "/tmp/install_options"
|
|
|
|
with open(config_temp, "w") as handle:
|
|
|
|
for key, value in options.items():
|
|
|
|
if isinstance(value, bool):
|
|
|
|
value = str(value).lower()
|
|
|
|
handle.write(key + "='" + value + "'\n")
|
2017-08-24 21:07:36 +00:00
|
|
|
|
|
|
|
commands = [
|
|
|
|
# Move config file from /tmp/ to zip root
|
2017-11-16 22:20:57 +00:00
|
|
|
["mv", "/tmp/install_options", "chroot/install_options"],
|
2017-08-24 21:07:36 +00:00
|
|
|
# Create tar archive of the rootfs
|
2018-01-12 21:53:15 +00:00
|
|
|
["tar", "-pcf", "rootfs.tar", "--exclude", "./home", "-C", rootfs,
|
|
|
|
"."],
|
2017-10-14 15:41:12 +00:00
|
|
|
# Append packages keys
|
|
|
|
["tar", "-prf", "rootfs.tar", "-C", "/", "./etc/apk/keys"],
|
|
|
|
# Compress with -1 for speed improvement
|
|
|
|
["gzip", "-f1", "rootfs.tar"],
|
2017-11-16 22:20:57 +00:00
|
|
|
["build-recovery-zip", args.device]]
|
2017-08-24 21:07:36 +00:00
|
|
|
for command in commands:
|
2018-07-14 01:13:28 +00:00
|
|
|
pmb.chroot.root(args, command, suffix, zip_root)
|