1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-12 19:09:56 +03:00
Commit graph

229 commits

Author SHA1 Message Date
Newbyte
7d2f055bcb
pmb: Make RunOutputTypeDefault and RunOutputTypePopen enums
This allows us to get rid of some of the validation in sanity_checks()
as mypy handles this validation at "build time", and any typos in the
enum instantiation would be a runtime error rather than a silent
failure.

Additionally, it allows us to encode some of the behaviour of the
different output types into the type definition itself by using methods.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2642
2025-07-10 20:57:51 +02:00
Pablo Correa Gómez
496d1b657d
Revert "install: openrc: fix installing alpine-base early"
This reverts commit 6eb8cab84d.

This is a problematic way to solve the issue. We want to eventually
allow people to migrate from openrc, and having alpine-base in the
world file is an issue. Moreover, a package that runs rc-update
and doesn't depend on openrc simply has a packaging bug. This is
something that is documented, and should be generally fixed
(https://gitlab.postmarketos.org/postmarketOS/pmaports/-/issues/2097).
If we manage to detect more issues, we should fix them in packaging
instead, like with
https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6474

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2593
2025-05-05 21:58:17 +02:00
Oliver Smith
6eb8cab84d
install: openrc: fix installing alpine-base early
With recent changes we don't install alpine-base in the chroots anymore.
It still gets installed as postmarketos-base depends on it (for now,
this will change soon in master). But it is not guaranteed to be
installed before other packages which may run "rc-update" in their
postinst scripts.

Fix this by explicitly installing alpine-base early on during
"pmbootstrap install".

Fix for e.g. v24.12:pine64-pinephone:phosh images:

  (342/976) Installing eg25-manager-openrc (0.4.6-r5)
  (343/976) Installing device-pine64-pinephone-openrc (7-r0)
  Executing device-pine64-pinephone-openrc-7-r0.post-install
  lib/apk/exec/device-pine64-pinephone-openrc-7-r0.post-install: line 3: rc-update: not found
  ERROR: device-pine64-pinephone-openrc-7-r0.post-install: script exited with error 127

Related: https://builds.sr.ht/~postmarketos/job/1473669#task-img-743
Fixes: 12d125ab ("chroot: don't depende on alpine-base")

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2585
2025-04-18 10:38:34 +02:00
Anri Dellal
a80b27d0bd
install: Do not fail on invalid SSH key
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2576
2025-04-11 17:37:35 +02:00
Stephan Gerhold
e9038e50d6
pmb/install: Add option to create single combined boot/root partition
With recent rework in postmarketos-initramfs, we no longer need to mount
the /boot partition in the initramfs (assuming initramfs-extra is not
used). On devices that boot without accessing the boot file system (e.g.
Android boot images, fastboot, ...), that makes it possible to install
postmarketOS on a single (potentially encrypted) partition that contains
both root (/) and /boot files.

This avoids the extra complexity of the subpartition setup we usually use
on such devices, and also avoids having to flash two partitions (when using
--split to avoid the subpartitions).

Add a --single-partition option to pmbootstrap install that allows
installing postmarketOS in this mode. For now this is just an option that
must be selected explicitly, in the future we could choose to make this the
default for Android-based devices with a large enough boot partition.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2512
2025-04-11 17:35:20 +02:00
fossdd
745ee74138
pmb.install._install: install locale config on default lang aswell
Reduces complexity allows applications and users to have a single source
of truth without involving /etc/profile.d/..

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2547
2025-04-03 22:58:29 +02:00
fossdd
50d2bb45f4
pmb.install._install: write lang configuration to /etc/locale.conf
Previous reasons to write the locales to /etc/profile.d/.. was because
musl-locales do only support reading from environment variables and not
/etc/locale.conf.

However systemd-localed (and glibc) uses /etc/locale.conf to read and
write locale configurations. gnome-control-center, for example, uses
localed to change locales.

In the sake of a single source of truth, allow pmb to write to
/etc/locale.conf and allow its consumers (e.g. g-c-c via systemd) to
read/change these variables.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2547
2025-04-03 22:58:29 +02:00
fossdd
9656c53a6a
pmb.install._install: remove installation of lang
lang gets moved to `_pmb_recommends` of postmarketos-base-ui to allow
switching between languages on en_US devices

Closes: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/issues/3314

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2547
2025-04-03 22:58:24 +02:00
Theresa Schönhammer
ca1f87b873
install: remove redundant package musl-locales
lang depends on musl-locales

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2579
2025-03-31 17:45:48 +02:00
Oliver Smith
06957b2173
install: log space/inodes used in image (MR 2558)
Log how well we have used the space and available inodes in the
resulting images, to show how well the mkfs parameters we have decided
on are working.
2025-02-23 13:45:32 +01:00
SzczurekYT
b5f14e2b94
install: create_device_rootfs: check if ui extras package exists (MR 2534)
Don't try installing the ui -extras subpackage if the currently selected ui doesn't have one.
2025-01-28 11:41:33 +01:00
Newbyte
c797b30dfe
pmb: Use unpacking operator to concatenate collections (MR 2525)
See https://docs.astral.sh/ruff/rules/collection-literal-concatenation

This is also slightly faster according to a microbenchmark that
shows it taking around 19% less time to run:
https://github.com/astral-sh/ruff/pull/1957#issue-1538092351
2025-01-15 22:35:02 +01:00
Oliver Smith
3f9f1c96c1
install: support systemd for disabling services (MR 2529)
Write a preset file and run "systemctl preset" afterwards:

    % sh -c echo 'disable sshd.service' > /usr/lib/systemd/system-preset/80-pmbootstrap-install-disable-sshd.preset
    % systemctl preset sshd.service
    % systemctl is-enabled sshd.service
    disabled
2025-01-12 15:33:02 +01:00
Oliver Smith
786c62767e
install: merge disable_sshd(), disable_firewall() (MR 2529)
These functions are identical, except for the service name. Merge them
in preparation to add systemd support.
2025-01-12 15:33:02 +01:00
Robert Eckelmann
a2f177433f
Cosmetic: pmb/install/_install.py: tweak strings (MR 2529)
Merge strings that have a break in the same line. These were generated
when running "ruff format" initially.

Old:
  logging.info("Firewall is not supported in checked out pmaports" " branch.")
New:
  logging.info("Firewall is not supported in checked out pmaports branch.")

Signed-off-by: Robert Eckelmann <longnoserob@postmarketos.org>
Tweaked-by: Oliver Smith <ollieparanoid@postmarketos.org>
2025-01-12 15:32:57 +01:00
Newbyte
510469b304
pmb.config.pmaports: Get rid of cast hack for SectionProxy (MR 2519)
For some reason this also requires a fix in pmb.install._install.py,
didn't bother investigating why but the necessary change seems fine to
me.

Requires mypy 1.14 (maybe 1.14.1, not sure).
2025-01-02 14:17:55 +01:00
Newbyte
5ed5817e80
pmb: Add more type hints (MR 2490) 2024-12-19 10:09:22 +00:00
Anri Dellal
c831302a57
pmb.install._install: add setup_locale() (MR 2497)
Moves locale setup code to separate function
Adds code to install keyboard configuration based on chosen locale
2024-12-03 13:17:15 +01:00
Newbyte
472726a9dc
pmb: Add more type hints (MR 2489) 2024-11-14 23:16:29 +01:00
Dominik Bayerl
87515529cf
pmbootstrap: run partprobe after repartitioning (MR 2473)
On some kernels (notably, WSL2) parted fails to inform the kernel
about the new partition layout, leading to errors when trying to
create the new filesystems.

This change runs an additional `partprobe` after updating the
partition table, informing the kernel about the new layout.

Fixes: #2422
Signed-off-by: Dominik Bayerl <dominik.bayerl@carissma.eu>
[caleb: move call so it runs after partition_cgpt() as well]
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-04 08:09:37 +01:00
Newbyte
225d8b30a0
pmb: Add lots of type hints (MR 2464) 2024-10-30 12:39:45 +01:00
Newbyte
8bc848fa77
pmb.install._install: Use bool(...) when figuring out whether to use cgpt (MR 2464)
Otherwise, if pmb.parse.deviceinfo().cgpt_kpart is an empty string, for
example, we end up passing an empty string to get_partition_layout()
instead of False.
2024-10-29 23:08:37 +01:00
Newbyte
b0526128fe
pmb.install._install: Round root size to nearest int in get_subpartitions_size() (MR 2464)
This makes the behaviour match the docstring which specifies that this
function returns integers.
2024-10-29 23:08:36 +01:00
Clayton Craft
47dc493701
pmb.parse.depends.package_provider: add type hinting and fix references (MR 2439)
pmb.parse.apkindex.providers now returns a dict of string:ApkindexBlock,
probably from 71772b9b6

This adds type hinting to package_provider to reflect this, and fixes
code that calls it to properly deal with the possible return types.
Without this, building FDE images is broken.
2024-10-18 13:45:57 +02:00
Stefan Hansson
71772b9b6b
pmb.parse.apkindex: Introduce proper typing (MR 2425)
And adjust other code.

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2455
2024-10-13 20:12:34 +02:00
Oliver Smith
eb747ad21f
find_providers: tweak default matching (MR 2301)
The previous version would fail if the suffix contained a dash as well,
e.g. postmarketos-base-ui-audio-some-new-thing. Fix it and add example
comments.
2024-09-30 18:41:09 +02:00
JustSoup321
56a4329f4f
pmb.{config, helpers, install}: add _pmb_default support (MR 2301) 2024-09-30 18:37:01 +02:00
Clayton Craft
36c86cd971
install: create_device_rootfs: install pmos-base-systemd first (MR 2383)
When building a systemd image, this patch installs pmos-base-systemd
(and its dependencies) first before building the rest of the device
chroot. This is a workaround for...

The pmos-base-systemd package provides distro-wide systemd presets for
services, and when it's added to the `install_packages` list then
there's no guarantee that apk will install it *before* service packages
execute `systemctl preset`. In other words: `preset` may be run before
the distro presets are actually installed, and crushing expectations. By
making sure pmos-base-systemd is installed in the chroot first, we can
provide some guarantee that presets will be there when services are
installed a bit later.
2024-09-02 10:27:38 -07:00
JustSoup321
375814b9d2
pmb.{chroot, install}: modify for bsdutils (MR 2315)
Tweaked-By: Oliver Smith <ollieparanoid@postmarketos.org>
2024-09-01 15:45:06 +02:00
JustSoup321
3559ee4030
pmb.init: make default hostnames pass regex (MR 2393) 2024-09-01 15:01:02 +02:00
Caleb Connolly
0b0172bafc
install: add flash_boot for fastboot-bootpart (MR 2378)
When using fastboot-bootpart flash method to split root/boot partitions
out, it was no longer possible to flash the Android boot partition.

Add a new flash_boot action to handle this.

This will allow us to migrate devices like the OnePlus 6 to have the
boot partition (ESP) on system, and the rootfs on userdata rather than
the current subpartition method.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-21 12:53:28 +02:00
Caleb Connolly
c23a9ea9cd
install: fix root partition path in print (MR 2377)
When we output the root partition path, it says rootfs.img but it should
be root.img fix it.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-20 17:33:02 +02:00
Oliver Smith
36dd53f402
Run ruff check --fix (MR 2357)
Now that we have target-version = "py310" in [tool.ruff] in
pyproject.toml, ruff check complains about using typing.Optional and
typing.Union instead of newer syntax. Run the tool to fix it.
2024-07-16 00:26:35 +02:00
HenriDellal
2b577a8694
Fix pmbootstrap install --android-recovery-zip (MR 2368)
Tweaked-By: Oliver Smith <ollieparanoid@postmarketos.org>
2024-07-16 00:04:15 +02:00
Caleb Connolly
65d23905bc
treewide: another round of mypy fixes (MR 2344)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-08 16:01:13 +02:00
Caleb Connolly
6301212d99
install: partition: drop unused args (MR 2344)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-08 16:01:12 +02:00
Oliver Smith
18fa4e58a3
Ruff: fix typing.Xxx is deprecated, use xxx instead (MR 2327) 2024-06-23 19:13:57 +02:00
Hugo Osvaldo Barrera
cebd784d84
Prefer f-strings (MR 2327) 2024-06-23 19:13:57 +02:00
Hugo Osvaldo Barrera
f3f392ef66
Use simplified Python 3.8 syntax (MR 2327)
This commit was generated with:

    ruff check --fix --extend-select=UP .
2024-06-23 19:13:52 +02:00
Hugo Osvaldo Barrera
e421bb2d41
Auto-format codebase with ruff (MR 2325)
See: https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2324
Closes: https://gitlab.com/postmarketOS/pmbootstrap/-/merge_requests/2278
2024-06-23 15:40:13 +02:00
Caleb Connolly
099bd2f4fa
treewide: remove rogue leading slashes (MR 2252)
One flaw of pathlib is that Path("/tmp/") / "/some/relative/path"
results in Path("/some/relative/path")....

Fix the places in the codebase where we get this wrong.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
ceaad5c291
build: move run_abuild and friends to a new file (MR 2252)
_package.py was getting pretty big. split the actual build steps out.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
f2ca9c618e
ruff: run check --fix (MR 2252)
Get rid of unused imports and such

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:41 +02:00
Caleb Connolly
6087a9df8f
core: don't re-export get_context (MR 2252)
This makes testing a lot more annoying.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:40 +02:00
Caleb Connolly
6857882cf0
build: finish builder rework (MR 2252)
Rename build.package() to build.packages() and take a list of packages
to build, since every caller was inside a for loop this simplifies
usage and let's us give nicer log output by doing all the builds first,
so log messages don't get lost in the middle.

Behaviour is cleaned up so this shouuuuld work pretty well now. It
properly descends into dependencies and will build dependencies even if
the package given doesn't need building. Technically this was only done
before during install where the dependencies were recursed in
chroot.apk.install().

It probably makes the most sense to have a mode where it doesn't build
dependencies but warns the user about it, at least when invoked via
pmbootstrap build.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
e00d2a8e6d
install: don't call build in create_device_rootfs() (MR 2252)
The call to chroot.apk.install() will automatically build packages, so
we don't need to call it again beforehand.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
dbd0e97895
install: get_selected_providers: demote logging (MR 2252)
verbose is probably more suitable here.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
ef38c12e39
install: handle chroot unmount/mount properly (MR 2252)
We used to called pmb.chroot.shutdown() with "only_install_related=True"
here to unmount everything in the chroot so we could reliably "df" it to
figure out the rootfs image size.

Since ("pmb.chroot: only init once"), the chroot is no longer
automatically spun back up when we run mkinitfs, and the in-pmbootstrap
marker isn't recreated.

We only actually need to unmount the chroot anyway, so let's restrict it
to just that and remount things again afterwards.

This avoids weird side effects (like the native chroot being
shutdown?!), but this is something we should look into more in the
future since we're still doing a finnicky balancing act to manage chroot
state here.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
53a2953a4a
chroot: mount: drop args from remove_mnt_pmbootstrap (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
866e5bcfab
core: add an Arch type (MR 2252)
Move pmb/parse/arch.py over to core and refactor it as an Arch type,
similar to how Chroot was done. Fix all the uses (that I can find) of
arch in the codebase that need adjusting.

The new Arch type is an Enum, making it clear what architectures can be
represented and making it much easier to reason about. Since we support
~5 (kinda) different representations of an Architecture (Alpine, Kernel,
target triple, platform, and QEMU), we now formalise that the Alpine
format is what we represent internally, with methods to convert to any
of the others as-needed.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00