Compare commits

...

7 Commits

Author SHA1 Message Date
Oliver Smith 5d5801b2a9
install --ondev: set username to "user" 2020-06-29 21:26:33 +02:00
Oliver Smith 4d940736a8
install --ondev: add ondev_min_version
Put a minimum version check for postmarketos-ondev in the pmbootstrap
install code and verify it before starting the installation. This avoids
using incompatible versions, similar to the pmaports.cfg version check
we already have. Set the minimum required version to 0.2.0.
2020-06-29 21:26:33 +02:00
Oliver Smith a6bcc2ba83
install --ondev: ondev-prepare: fix log msg 2020-06-29 21:26:33 +02:00
Oliver Smith afeeeee4d7
install --ondev: ondev-prepare: pass pmb ver, ui
Pass the pmbootstrap version and user interface, so it can be checked /
displayed in postmarketos-ondev.
2020-06-29 21:26:33 +02:00
Oliver Smith a7dbdf58bc
install --ondev: ondev-prepare: use env vars
Do not pass the arguments to ondev-prepare as command-line arguments in
a specific order, but instead as environment variables. New arguments
will be added in a follow-up patch.
2020-06-29 21:26:33 +02:00
Oliver Smith 7da4903223
pmbootstrap install --no-local-pkgs: new option
Don't install locally compiled packages and package signing keys. This
will be used for the official images generated with pmbootstrap.
2020-06-29 21:26:33 +02:00
Oliver Smith 879cd06024
pmbootstrap install: make building pkgs optional
Add a question at the end of "pmbootstrap init", to ask if the user
wants to build outdated packages during "pmbootstrap install". Store the
result in the new pmbootstrap.cfg key "install_build_pkgs". I've put it at
the end, because it is a rather complicated question compared to the rest.

This is useful to speed up the installation for casual users who can now
avoid compiling packages. But also for the official images where we only
want to ship the official binary packages and not build anything
on-the-fly.
2020-06-29 21:26:28 +02:00
6 changed files with 95 additions and 12 deletions

View File

@ -98,8 +98,13 @@ def install_is_necessary(args, build, arch, package, packages_installed):
:param packages_installed: Return value from installed().
:returns: True if the package needs to be installed/updated, False otherwise.
"""
# User may have disabled buiding packages during "pmbootstrap install"
build_disabled = False
if args.action == "install" and not args.install_build_pkgs:
build_disabled = True
# Build package
if build:
if build and not build_disabled:
pmb.build.package(args, package, arch)
# No further checks when not installed
@ -109,6 +114,12 @@ def install_is_necessary(args, build, arch, package, packages_installed):
# Make sure, that we really have a binary package
data_repo = pmb.parse.apkindex.package(args, package, arch, False)
if not data_repo:
if build_disabled:
raise RuntimeError(f"{package}: no binary package found for"
f" {arch}, and compiling packages during"
" 'pmbootstrap install' has been disabled."
" Consider changing this option in"
" 'pmbootstrap init'.")
logging.warning("WARNING: Internal error in pmbootstrap," +
" package '" + package + "' for " + arch +
" has not been built yet, but it should have"

View File

@ -31,6 +31,9 @@ pmaports_min_version = "7"
# see migrate_work_folder()).
work_version = 5
# Minimum required version of postmarketos-ondev (pmbootstrap install --ondev)
ondev_min_version = "0.2.0"
# Programs that pmbootstrap expects to be available from the host system. Keep
# in sync with README.md, and try to keep the list as small as possible. The
# idea is to run almost everything in Alpine chroots.
@ -42,6 +45,7 @@ config_keys = ["aports",
"device",
"extra_packages",
"hostname",
"install_build_pkgs",
"is_default_channel",
"jobs",
"kernel",
@ -71,6 +75,7 @@ defaults = {
"extra_packages": "none",
"fork_alpine": False,
"hostname": "",
"install_build_pkgs": True,
# A higher value is typically desired, but this can lead to VERY long open
# times on slower devices due to host systems being MUCH faster than the
# target device (see issue #429).

View File

@ -389,6 +389,15 @@ def ask_for_ssh_keys(args):
default=args.ssh_keys)
def ask_install_build_pkgs(args):
logging.info("After pmaports are changed, the binary packages may be"
" outdated. If you want to install postmarketOS without"
" changes, reply 'n' for a faster installation.")
return pmb.helpers.cli.confirm(args, "Build outdated packages during"
" 'pmbootstrap install'?",
default=args.install_build_pkgs)
def frontend(args):
require_programs()
@ -454,6 +463,9 @@ def frontend(args):
# pmaports path (if users change it with: 'pmbootstrap --aports=... init')
cfg["pmbootstrap"]["aports"] = args.aports
# Build outdated packages in pmbootstrap install
cfg["pmbootstrap"]["install_build_pkgs"] = str(ask_install_build_pkgs(args))
# Save config
pmb.config.save(args, cfg)

View File

@ -1,5 +1,6 @@
# Copyright 2020 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import json
import logging
import os
@ -222,12 +223,37 @@ def install(args):
raise ValueError("--on-device-installer cannot be combined with"
" --rsync")
# On-device installer overrides
if args.on_device_installer:
# To make code for the on-device installer not needlessly complex, just
# hardcode "user" as username here. (The on-device installer will set
# a password for the user, disable SSH password authentication,
# optionally add a new user for SSH that must not have the same
# username etc.)
if args.user != "user":
logging.warning(f"WARNING: custom username '{args.user}' will be"
" replaced with 'user' for the on-device"
" installer.")
args.user = "user"
if not args.sdcard and args.split is None:
# Default to split if the flash method requires it
flasher = pmb.config.flashers.get(args.deviceinfo["flash_method"], {})
if flasher.get("split", False):
args.split = True
# Don't install locally compiled packages and package signing keys
if not args.install_local_pkgs:
# Implies that we don't build outdated packages (overriding the answer
# in 'pmbootstrap init')
args.install_build_pkgs = False
# Safest way to avoid installing local packages is having none
if glob.glob(f"{args.work}/packages/*"):
raise ValueError("--no-local-pkgs specified, but locally built"
" packages found. Consider 'pmbootstrap zap -p'"
" to delete them.")
pmb.install.install(args)

View File

@ -154,12 +154,20 @@ def create_home_from_skel(args):
def configure_apk(args):
"""
Copies over all keys used locally to compile packages, and disables the
/mnt/pmbootstrap-packages repository.
Copy over all official keys, and the keys used to compile local packages
(unless --no-local-pkgs is set). Then disable the /mnt/pmbootstrap-packages
repository.
"""
# Official keys
pattern = f"{pmb.config.apk_keys_path}/*.pub"
# Official keys + local keys
if args.install_local_pkgs:
pattern = f"{args.work}/config_apk_keys/*.pub"
# Copy over keys
rootfs = args.work + "/chroot_native/mnt/install"
for key in glob.glob(args.work + "/config_apk_keys/*.pub"):
for key in glob.glob(pattern):
pmb.helpers.run.root(args, ["cp", key, rootfs + "/etc/apk/keys/"])
# Disable pmbootstrap repository
@ -374,6 +382,18 @@ def sanity_check_sdcard(device):
raise RuntimeError("{} is read-only, is the sdcard locked?".format(device))
def sanity_check_ondev_version(args):
arch = args.deviceinfo["arch"]
package = pmb.helpers.package.get(args, "postmarketos-ondev", arch)
ver_pkg = package["version"].split("-r")[0]
ver_min = pmb.config.ondev_min_version
if pmb.parse.version.compare(ver_pkg, ver_min) == -1:
raise RuntimeError("This version of pmbootstrap requires"
f" postmarketos-ondev version {ver_min} or"
" higher. The postmarketos-ondev found in pmaports"
f" / in the binary packages has version {ver_pkg}.")
def install_system_image(args, size_reserve, suffix, root_label="pmOS_root",
step=3, steps=5, split=False, sdcard=None):
"""
@ -530,14 +550,17 @@ def install_on_device_installer(args, step, steps):
# properties (e.g. to display the version number), or transform the image
# file into another format. This can all be done without pmbootstrap
# changes in the postmarketos-ondev package.
logging.info(f"({suffix_installer}) ondev-prepare-image")
logging.info(f"({suffix_installer}) ondev-prepare")
channel = pmb.config.pmaports.read_config(args)["channel"]
channel_cfg = pmb.config.pmaports.read_config_channel(args)
pmb.chroot.root(args, ["ondev-prepare", channel,
channel_cfg["description"],
channel_cfg["branch_pmaports"],
channel_cfg["branch_aports"],
channel_cfg["mirrordir_alpine"]], suffix_installer)
env = {"ONDEV_CHANNEL": channel,
"ONDEV_CHANNEL_BRANCH_APORTS": channel_cfg["branch_aports"],
"ONDEV_CHANNEL_BRANCH_PMAPORTS": channel_cfg["branch_pmaports"],
"ONDEV_CHANNEL_DESCRIPTION": channel_cfg["description"],
"ONDEV_CHANNEL_MIRRORDIR_ALPINE": channel_cfg["mirrordir_alpine"],
"ONDEV_PMBOOTSTRAP_VERSION": pmb.config.version,
"ONDEV_UI": args.ui}
pmb.chroot.root(args, ["ondev-prepare"], suffix_installer, env=env)
# Remove $DEVICE-boot.img (we will generate a new one if --split was
# specified, otherwise the separate boot image is not needed)
@ -555,6 +578,8 @@ def install(args):
# Sanity checks
if not args.android_recovery_zip and args.sdcard:
sanity_check_sdcard(args.sdcard)
if args.on_device_installer:
sanity_check_ondev_version(args)
# Number of steps for the different installation methods.
if args.no_image:
@ -597,8 +622,9 @@ def install(args):
install_packages += args.extra_packages.split(",")
if args.add:
install_packages += args.add.split(",")
for pkgname in install_packages:
pmb.build.package(args, pkgname, args.deviceinfo["arch"])
if args.install_build_pkgs:
for pkgname in install_packages:
pmb.build.package(args, pkgname, args.deviceinfo["arch"])
# Install all packages to device rootfs chroot (and rebuild the initramfs,
# because that doesn't always happen automatically yet, e.g. when the user

View File

@ -562,6 +562,9 @@ def arguments():
help="wrap the resulting image in a graphical"
" on-device installer, so the installation can"
" be customized after flashing")
install.add_argument("--no-local-pkgs", dest="install_local_pkgs",
help="do not install locally compiled packages and"
" package signing keys", action="store_false")
group = install.add_mutually_exclusive_group()
group.add_argument("--sparse", help="generate sparse image file"
" (even if unsupported by device)", default=None,