Flavor instead of device name when creating recovery zip (#491)

* Flavor instead of device name when creating recovery zip.
* Move parse_flavor_arg function
This commit is contained in:
Attila Szöllősi 2017-09-02 05:53:58 +02:00 committed by Oliver Smith
parent 54d8010af1
commit c6fe6e134a
4 changed files with 32 additions and 26 deletions

View File

@ -25,34 +25,12 @@ import pmb.install
import pmb.chroot.apk
import pmb.chroot.initfs
import pmb.chroot.other
def parse_flavor_arg(args):
"""
Verify the flavor argument if specified, or return a default value.
"""
# Make sure, that at least one kernel is installed
suffix = "rootfs_" + args.device
pmb.chroot.apk.install(args, ["device-" + args.device], suffix)
# Parse and verify the flavor argument
flavor = args.flavor
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix)
if flavor:
if flavor not in flavors:
raise RuntimeError("No kernel installed with flavor " + flavor + "!" +
" Run 'pmbootstrap flasher list_flavors' to get a list.")
return flavor
if not len(flavors):
raise RuntimeError(
"No kernel flavors installed in chroot " + suffix + "! Please let"
" your device package depend on a package starting with 'linux-'.")
return flavors[0]
import pmb.helpers.frontend
def kernel(args):
# Rebuild the initramfs, just to make sure (see #69)
flavor = parse_flavor_arg(args)
flavor = pmb.helpers.frontend._parse_flavor(args)
pmb.chroot.initfs.build(args, flavor, "rootfs_" + args.device)
# Generate the paths and run the flasher
@ -126,7 +104,7 @@ def export(args):
" install' first (without the 'sdcard' parameter).")
# Rebuild the initramfs, just to make sure (see #69)
flavor = parse_flavor_arg(args)
flavor = pmb.helpers.frontend._parse_flavor(args)
pmb.chroot.initfs.build(args, flavor, "rootfs_" + args.device)
pmb.flasher.export(args, flavor, args.export_folder)

View File

@ -39,6 +39,29 @@ import pmb.parse
import pmb.qemu
def _parse_flavor(args):
"""
Verify the flavor argument if specified, or return a default value.
"""
# Make sure, that at least one kernel is installed
suffix = "rootfs_" + args.device
pmb.chroot.apk.install(args, ["device-" + args.device], suffix)
# Parse and verify the flavor argument
flavor = args.flavor
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix)
if flavor:
if flavor not in flavors:
raise RuntimeError("No kernel installed with flavor " + flavor + "!" +
" Run 'pmbootstrap flasher list_flavors' to get a list.")
return flavor
if not len(flavors):
raise RuntimeError(
"No kernel flavors installed in chroot " + suffix + "! Please let"
" your device package depend on a package starting with 'linux-'.")
return flavors[0]
def _parse_suffix(args):
if args.rootfs:
return "rootfs_" + args.device

View File

@ -19,6 +19,7 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
import logging
import pmb.chroot
import pmb.helpers.frontend
def create_zip(args, suffix):
@ -27,6 +28,7 @@ def create_zip(args, suffix):
"""
zip_root = "/var/lib/postmarketos-android-recovery-installer/"
rootfs = "/mnt/rootfs_" + args.device
flavor = pmb.helpers.frontend._parse_flavor(args)
# Install recovery installer package in buildroot
pmb.chroot.apk.install(args,
@ -52,7 +54,7 @@ def create_zip(args, suffix):
# Move config file from /tmp/ to zip root
["mv", "/tmp/install_options", "install_options"],
# Copy boot.img to zip root
["cp", rootfs + "/boot/boot.img-" + args.device, "boot.img"],
["cp", rootfs + "/boot/boot.img-" + flavor, "boot.img"],
# Create tar archive of the rootfs
["tar", "-pczf", "rootfs.tar.gz", "--exclude", "./home/user/*",
"-C", rootfs, "."],

View File

@ -192,6 +192,9 @@ def arguments():
" added to the rootfs (e.g. 'vim,gcc')")
install.add_argument("--no-fde", help="do not use full disk encryption",
action="store_false", dest="full_disk_encryption")
install.add_argument("--flavor",
help="Specify kernel flavor to include in recovery"
" flashable zip", default=None)
install.add_argument("--android-recovery-zip",
help="generate TWRP flashable zip",
action="store_true", dest="android_recovery_zip")