forked from Mirror/pmbootstrap
Alias: "pmbootstrap export" for "pmbootstrap flasher export" (#417)
* moved export code to pmb/export and split it up * added deprecation notice to "pmbootstrap flasher export" * made "pmbootstrap export" work * adjusted the "pmbootstrap flasher export" hints in the code
This commit is contained in:
parent
cd9baf4026
commit
b29cc877a7
9 changed files with 164 additions and 96 deletions
21
pmb/export/__init__.py
Normal file
21
pmb/export/__init__.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
"""
|
||||||
|
Copyright 2017 Oliver Smith
|
||||||
|
|
||||||
|
This file is part of pmbootstrap.
|
||||||
|
|
||||||
|
pmbootstrap is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
pmbootstrap is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
from pmb.export.frontend import frontend
|
||||||
|
from pmb.export.odin import odin
|
||||||
|
from pmb.export.symlinks import symlinks
|
30
pmb/export/frontend.py
Normal file
30
pmb/export/frontend.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
import pmb.helpers.run
|
||||||
|
import pmb.helpers.frontend
|
||||||
|
import pmb.chroot.initfs
|
||||||
|
import pmb.export
|
||||||
|
|
||||||
|
|
||||||
|
def frontend(args):
|
||||||
|
# Create the export folder
|
||||||
|
target = args.export_folder
|
||||||
|
if not os.path.exists(target):
|
||||||
|
pmb.helpers.run.user(args, ["mkdir", "-p", target])
|
||||||
|
|
||||||
|
# System image note
|
||||||
|
img_path = "/home/user/rootfs/" + args.device + ".img"
|
||||||
|
if not os.path.exists(args.work + "/chroot_native" + img_path):
|
||||||
|
logging.info("NOTE: To export the system image, run 'pmbootstrap"
|
||||||
|
" install' first (without the 'sdcard' parameter).")
|
||||||
|
|
||||||
|
# Rebuild the initramfs, just to make sure (see #69)
|
||||||
|
flavor = pmb.helpers.frontend._parse_flavor(args)
|
||||||
|
pmb.chroot.initfs.build(args, flavor, "rootfs_" + args.device)
|
||||||
|
|
||||||
|
# Do the export, print all files
|
||||||
|
logging.info("Export symlinks to: " + target)
|
||||||
|
if args.odin_flashable_tar:
|
||||||
|
pmb.export.odin(args, flavor, target)
|
||||||
|
pmb.export.symlinks(args, flavor, target)
|
|
@ -17,8 +17,6 @@ You should have received a copy of the GNU General Public License
|
||||||
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import glob
|
|
||||||
|
|
||||||
import pmb.build
|
import pmb.build
|
||||||
import pmb.chroot.apk
|
import pmb.chroot.apk
|
||||||
|
@ -27,60 +25,7 @@ import pmb.flasher
|
||||||
import pmb.helpers.file
|
import pmb.helpers.file
|
||||||
|
|
||||||
|
|
||||||
def export(args, flavor, folder):
|
def odin(args, flavor, folder):
|
||||||
logging.info("Export symlinks to: " + folder)
|
|
||||||
if args.odin_flashable_tar:
|
|
||||||
odin_flashable_tar(args, flavor, folder)
|
|
||||||
symlinks(args, flavor, folder)
|
|
||||||
|
|
||||||
|
|
||||||
def symlinks(args, flavor, folder):
|
|
||||||
"""
|
|
||||||
Create convenience symlinks to the system image and boot files.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# File descriptions
|
|
||||||
info = {
|
|
||||||
"boot.img-" + flavor: "Fastboot compatible boot.img file,"
|
|
||||||
" contains initramfs and kernel",
|
|
||||||
"initramfs-" + flavor: "Initramfs",
|
|
||||||
"uInitrd-" + flavor: "Initramfs, legacy u-boot image format",
|
|
||||||
"uImage-" + flavor: "Kernel, legacy u-boot image format",
|
|
||||||
"vmlinuz-" + flavor: "Linux kernel",
|
|
||||||
args.device + ".img": "System partition",
|
|
||||||
"pmos-" + args.device + ".zip": "Android recovery flashable zip",
|
|
||||||
}
|
|
||||||
|
|
||||||
# Generate a list of patterns
|
|
||||||
path_native = args.work + "/chroot_native"
|
|
||||||
path_boot = args.work + "/chroot_rootfs_" + args.device + "/boot"
|
|
||||||
path_buildroot = args.work + "/chroot_buildroot_" + args.deviceinfo["arch"]
|
|
||||||
patterns = [path_boot + "/*-" + flavor,
|
|
||||||
path_native + "/home/user/rootfs/" + args.device + ".img",
|
|
||||||
path_buildroot +
|
|
||||||
"/var/lib/postmarketos-android-recovery-installer/pmos-" +
|
|
||||||
args.device + ".zip"]
|
|
||||||
|
|
||||||
# Generate a list of files from the patterns
|
|
||||||
files = []
|
|
||||||
for pattern in patterns:
|
|
||||||
files += glob.glob(pattern)
|
|
||||||
|
|
||||||
# Iterate through all files
|
|
||||||
for file in files:
|
|
||||||
basename = os.path.basename(file)
|
|
||||||
link = folder + "/" + basename
|
|
||||||
|
|
||||||
# Display a readable message
|
|
||||||
msg = " * " + basename
|
|
||||||
if basename in info:
|
|
||||||
msg += " (" + info[basename] + ")"
|
|
||||||
logging.info(msg)
|
|
||||||
|
|
||||||
pmb.helpers.file.symlink(args, file, link)
|
|
||||||
|
|
||||||
|
|
||||||
def odin_flashable_tar(args, flavor, folder):
|
|
||||||
"""
|
"""
|
||||||
Create Odin flashable tar file with kernel and initramfs for devices configured with
|
Create Odin flashable tar file with kernel and initramfs for devices configured with
|
||||||
the flasher method 'heimdall-isorec' and with boot.img for devices with 'heimdall-bootimg'
|
the flasher method 'heimdall-isorec' and with boot.img for devices with 'heimdall-bootimg'
|
73
pmb/export/symlinks.py
Normal file
73
pmb/export/symlinks.py
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
"""
|
||||||
|
Copyright 2017 Oliver Smith
|
||||||
|
|
||||||
|
This file is part of pmbootstrap.
|
||||||
|
|
||||||
|
pmbootstrap is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
pmbootstrap is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import glob
|
||||||
|
|
||||||
|
import pmb.build
|
||||||
|
import pmb.chroot.apk
|
||||||
|
import pmb.config
|
||||||
|
import pmb.flasher
|
||||||
|
import pmb.helpers.file
|
||||||
|
|
||||||
|
|
||||||
|
def symlinks(args, flavor, folder):
|
||||||
|
"""
|
||||||
|
Create convenience symlinks to the system image and boot files.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# File descriptions
|
||||||
|
info = {
|
||||||
|
"boot.img-" + flavor: "Fastboot compatible boot.img file,"
|
||||||
|
" contains initramfs and kernel",
|
||||||
|
"initramfs-" + flavor: "Initramfs",
|
||||||
|
"uInitrd-" + flavor: "Initramfs, legacy u-boot image format",
|
||||||
|
"uImage-" + flavor: "Kernel, legacy u-boot image format",
|
||||||
|
"vmlinuz-" + flavor: "Linux kernel",
|
||||||
|
args.device + ".img": "System partition",
|
||||||
|
"pmos-" + args.device + ".zip": "Android recovery flashable zip",
|
||||||
|
}
|
||||||
|
|
||||||
|
# Generate a list of patterns
|
||||||
|
path_native = args.work + "/chroot_native"
|
||||||
|
path_boot = args.work + "/chroot_rootfs_" + args.device + "/boot"
|
||||||
|
path_buildroot = args.work + "/chroot_buildroot_" + args.deviceinfo["arch"]
|
||||||
|
patterns = [path_boot + "/*-" + flavor,
|
||||||
|
path_native + "/home/user/rootfs/" + args.device + ".img",
|
||||||
|
path_buildroot +
|
||||||
|
"/var/lib/postmarketos-android-recovery-installer/pmos-" +
|
||||||
|
args.device + ".zip"]
|
||||||
|
|
||||||
|
# Generate a list of files from the patterns
|
||||||
|
files = []
|
||||||
|
for pattern in patterns:
|
||||||
|
files += glob.glob(pattern)
|
||||||
|
|
||||||
|
# Iterate through all files
|
||||||
|
for file in files:
|
||||||
|
basename = os.path.basename(file)
|
||||||
|
link = folder + "/" + basename
|
||||||
|
|
||||||
|
# Display a readable message
|
||||||
|
msg = " * " + basename
|
||||||
|
if basename in info:
|
||||||
|
msg += " (" + info[basename] + ")"
|
||||||
|
logging.info(msg)
|
||||||
|
|
||||||
|
pmb.helpers.file.symlink(args, file, link)
|
|
@ -19,4 +19,3 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||||
from pmb.flasher.init import init
|
from pmb.flasher.init import init
|
||||||
from pmb.flasher.run import run
|
from pmb.flasher.run import run
|
||||||
from pmb.flasher.frontend import frontend
|
from pmb.flasher.frontend import frontend
|
||||||
from pmb.flasher.export import export
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import pmb.install
|
||||||
import pmb.chroot.apk
|
import pmb.chroot.apk
|
||||||
import pmb.chroot.initfs
|
import pmb.chroot.initfs
|
||||||
import pmb.chroot.other
|
import pmb.chroot.other
|
||||||
|
import pmb.export.frontend
|
||||||
import pmb.helpers.frontend
|
import pmb.helpers.frontend
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,24 +93,6 @@ def sideload(args):
|
||||||
pmb.flasher.run(args, "sideload")
|
pmb.flasher.run(args, "sideload")
|
||||||
|
|
||||||
|
|
||||||
def export(args):
|
|
||||||
# Create the export folder
|
|
||||||
if not os.path.exists(args.export_folder):
|
|
||||||
pmb.helpers.run.user(args, ["mkdir", "-p", args.export_folder])
|
|
||||||
|
|
||||||
# System image note
|
|
||||||
img_path = "/home/user/rootfs/" + args.device + ".img"
|
|
||||||
if not os.path.exists(args.work + "/chroot_native" + img_path):
|
|
||||||
logging.info("NOTE: To export the system image, run 'pmbootstrap"
|
|
||||||
" install' first (without the 'sdcard' parameter).")
|
|
||||||
|
|
||||||
# Rebuild the initramfs, just to make sure (see #69)
|
|
||||||
flavor = pmb.helpers.frontend._parse_flavor(args)
|
|
||||||
pmb.chroot.initfs.build(args, flavor, "rootfs_" + args.device)
|
|
||||||
|
|
||||||
pmb.flasher.export(args, flavor, args.export_folder)
|
|
||||||
|
|
||||||
|
|
||||||
def frontend(args):
|
def frontend(args):
|
||||||
action = args.action_flasher
|
action = args.action_flasher
|
||||||
if action in ["boot", "flash_kernel"]:
|
if action in ["boot", "flash_kernel"]:
|
||||||
|
@ -123,4 +106,7 @@ def frontend(args):
|
||||||
if action == "sideload":
|
if action == "sideload":
|
||||||
sideload(args)
|
sideload(args)
|
||||||
if action == "export":
|
if action == "export":
|
||||||
export(args)
|
logging.info("WARNING: 'pmbootstrap flasher export' is deprecated and"
|
||||||
|
" will be removed soon. The new syntax is 'pmbootstrap"
|
||||||
|
" export'.")
|
||||||
|
pmb.export.frontend(args)
|
||||||
|
|
|
@ -140,6 +140,10 @@ def flasher(args):
|
||||||
pmb.flasher.frontend(args)
|
pmb.flasher.frontend(args)
|
||||||
|
|
||||||
|
|
||||||
|
def export(args):
|
||||||
|
pmb.export.frontend(args)
|
||||||
|
|
||||||
|
|
||||||
def menuconfig(args):
|
def menuconfig(args):
|
||||||
pmb.build.menuconfig(args, args.package, args.deviceinfo["arch"])
|
pmb.build.menuconfig(args, args.package, args.deviceinfo["arch"])
|
||||||
|
|
||||||
|
@ -174,7 +178,8 @@ def stats(args):
|
||||||
|
|
||||||
def log(args):
|
def log(args):
|
||||||
if args.clear_log:
|
if args.clear_log:
|
||||||
pmb.helpers.run.user(args, ["truncate", "-s", "0", args.log], log=False)
|
pmb.helpers.run.user(args, ["truncate", "-s", "0", args.log],
|
||||||
|
log=False)
|
||||||
pmb.helpers.run.user(args, ["tail", "-f", args.log, "-n", args.lines],
|
pmb.helpers.run.user(args, ["tail", "-f", args.log, "-n", args.lines],
|
||||||
log=False)
|
log=False)
|
||||||
|
|
||||||
|
@ -187,4 +192,5 @@ def log_distccd(args):
|
||||||
|
|
||||||
|
|
||||||
def zap(args):
|
def zap(args):
|
||||||
pmb.chroot.zap(args, packages=args.packages, http=args.http, mismatch_bins=args.mismatch_bins)
|
pmb.chroot.zap(args, packages=args.packages, http=args.http,
|
||||||
|
mismatch_bins=args.mismatch_bins)
|
||||||
|
|
|
@ -212,8 +212,8 @@ def install_system_image(args):
|
||||||
|
|
||||||
# Export information
|
# Export information
|
||||||
logging.info("* If the above steps do not work, you can also create"
|
logging.info("* If the above steps do not work, you can also create"
|
||||||
" symlinks to the generated files with 'pmbootstrap flasher"
|
" symlinks to the generated files with 'pmbootstrap export'"
|
||||||
" export [export_folder]' and flash outside of pmbootstrap.")
|
" and flash outside of pmbootstrap.")
|
||||||
|
|
||||||
|
|
||||||
def install_recovery_zip(args):
|
def install_recovery_zip(args):
|
||||||
|
@ -231,9 +231,8 @@ def install_recovery_zip(args):
|
||||||
|
|
||||||
# Export information
|
# Export information
|
||||||
logging.info("* If this does not work, you can also create a"
|
logging.info("* If this does not work, you can also create a"
|
||||||
" symlink to the generated zip with 'pmbootstrap flasher"
|
" symlink to the generated zip with 'pmbootstrap"
|
||||||
" export --android-recovery-zip [export_folder]' and"
|
" export' and flash outside of pmbootstrap.")
|
||||||
" flash outside of pmbootstrap.")
|
|
||||||
|
|
||||||
|
|
||||||
def install(args):
|
def install(args):
|
||||||
|
|
|
@ -21,6 +21,21 @@ import pmb.config
|
||||||
import pmb.parse.arch
|
import pmb.parse.arch
|
||||||
|
|
||||||
|
|
||||||
|
def arguments_export(subparser):
|
||||||
|
ret = subparser.add_parser("export", help="create convenience symlinks"
|
||||||
|
" to generated image files (system, kernel,"
|
||||||
|
" initramfs, boot.img, ...)")
|
||||||
|
|
||||||
|
ret.add_argument("export_folder", help="export folder, defaults to"
|
||||||
|
" /tmp/postmarketOS-export",
|
||||||
|
default="/tmp/postmarketOS-export", nargs="?")
|
||||||
|
ret.add_argument("--odin", help="odin flashable tar"
|
||||||
|
" (boot.img/kernel+initramfs only)",
|
||||||
|
action="store_true", dest="odin_flashable_tar")
|
||||||
|
ret.add_argument("--flavor", default=None)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def arguments_flasher(subparser):
|
def arguments_flasher(subparser):
|
||||||
ret = subparser.add_parser("flasher", help="flash something to the"
|
ret = subparser.add_parser("flasher", help="flash something to the"
|
||||||
" target device")
|
" target device")
|
||||||
|
@ -28,29 +43,22 @@ def arguments_flasher(subparser):
|
||||||
ret.add_argument("--method", help="override flash method",
|
ret.add_argument("--method", help="override flash method",
|
||||||
dest="flash_method", default=None)
|
dest="flash_method", default=None)
|
||||||
|
|
||||||
# Boot, flash kernel, export
|
# Boot, flash kernel
|
||||||
boot = sub.add_parser("boot", help="boot a kernel once")
|
boot = sub.add_parser("boot", help="boot a kernel once")
|
||||||
boot.add_argument("--cmdline", help="override kernel commandline")
|
boot.add_argument("--cmdline", help="override kernel commandline")
|
||||||
flash_kernel = sub.add_parser("flash_kernel", help="flash a kernel")
|
flash_kernel = sub.add_parser("flash_kernel", help="flash a kernel")
|
||||||
export = sub.add_parser("export", help="create convenience symlinks to the"
|
for action in [boot, flash_kernel]:
|
||||||
" generated image files (system,"
|
|
||||||
" kernel, initramfs, boot.img, ...)")
|
|
||||||
for action in [boot, flash_kernel, export]:
|
|
||||||
action.add_argument("--flavor", default=None)
|
action.add_argument("--flavor", default=None)
|
||||||
|
|
||||||
# Other
|
# Actions without extra arguments
|
||||||
sub.add_parser("flash_system", help="flash the system partition")
|
sub.add_parser("flash_system", help="flash the system partition")
|
||||||
|
sub.add_parser("sideload", help="sideload recovery zip")
|
||||||
sub.add_parser("list_flavors", help="list installed kernel flavors" +
|
sub.add_parser("list_flavors", help="list installed kernel flavors" +
|
||||||
" inside the device rootfs chroot on this computer")
|
" inside the device rootfs chroot on this computer")
|
||||||
sub.add_parser("list_devices", help="show connected devices")
|
sub.add_parser("list_devices", help="show connected devices")
|
||||||
sub.add_parser("sideload", help="sideload recovery zip")
|
|
||||||
|
|
||||||
# Export: additional arguments
|
# Deprecated "pmbootstrap flasher export"
|
||||||
export.add_argument("export_folder", help="export folder, defaults to"
|
arguments_export(sub)
|
||||||
" /tmp/postmarketOS-export",
|
|
||||||
default="/tmp/postmarketOS-export", nargs="?")
|
|
||||||
export.add_argument("--odin", help="odin flashable tar (boot.img/kernel+initramfs only)",
|
|
||||||
action="store_true", dest="odin_flashable_tar")
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,6 +144,7 @@ def arguments():
|
||||||
sub.add_parser("shutdown", help="umount, unregister binfmt")
|
sub.add_parser("shutdown", help="umount, unregister binfmt")
|
||||||
sub.add_parser("index", help="re-index all repositories with custom built"
|
sub.add_parser("index", help="re-index all repositories with custom built"
|
||||||
" packages (do this after manually removing package files)")
|
" packages (do this after manually removing package files)")
|
||||||
|
arguments_export(sub)
|
||||||
arguments_flasher(sub)
|
arguments_flasher(sub)
|
||||||
arguments_initfs(sub)
|
arguments_initfs(sub)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue