1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-15 20:35:11 +03:00
Commit graph

2035 commits

Author SHA1 Message Date
Caleb Connolly
ae35603197
test: parse: add tests for bootimg parsing (MR 2477)
Add some unit tests to ensure that the parser correctly detects boot
images with header v0, 2, and 3.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-08 01:57:26 +01:00
Caleb Connolly
b888ddde30
test: conftest: adjust pmaports fixture (MR 2477)
make sure that calls to get_upstream_remote() will succeed by setting
pmb.config.git_repos() for the entire run. This might pollute some other
tests...

TODO: make less things depend on pmaports being cloned...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-08 01:57:26 +01:00
Caleb Connolly
29b9a57cd6
test: conftest: describe paramaterize for config_file (MR 2477)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-08 01:57:26 +01:00
Caleb Connolly
953f84a79a
parse: bootimg: make it work again (MR 2477)
Commit 826bb4f2dd (pmb: Properly type Bootimg (MR 2464)) broke the
bootimg_analyze command since some assumptions in whether the bootimg
dictionary had empty keys or non-existent keys were changed without
their usage being updated.

Fix this and apply a trivial cleanup to aportgen.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-08 01:57:26 +01:00
Luca Weiss
26f9d56b20
pmb.config: Print ssh keys filenames that will be copied during init (MR 2251)
Make it clear to the user which SSH keys get copied to the device, and
also link to the wiki page that tells the user how to change
ssh_key_glob.
2024-11-07 01:14:06 +01:00
Luca Weiss
49fd496c94
pmb.config: Set default ssh_key_glob to *.pub (MR 2251)
When generating an ssh key it's simple to change the name of the key to
something that's not e.g. id_rsa.pub or id_ed25519.pub, so let's try to
capture ssh keys for more users.
2024-11-07 01:14:06 +01:00
Luca Weiss
ca9610a153
pmb.config: use ssh_key_glob for ask_for_ssh_keys (MR 2251)
Since a user can modify the glob to be somewhat arbitrary, use that to
check if any ssh keys exist and ask in pmbootstrap init.

Otherwise ssh_key_glob would only work if it was a subset of
~/.ssh/id_*.pub, so e.g. ~/.ssh/id_foo.pub but ~/.ssh/foo.pub wouldn't
work.
2024-11-07 01:14:02 +01:00
Oliver Smith
ee154ccdf9
require_programs: losetup --json: set output=null (MR 2475)
We don't care about the output of "losetup --json" here, we just want to
make sure that the argument exists. If it does not exist, we already
give an error to the user.

Set the output to null so it does not clutter the log since it runs with
every pmbootstrap command now.
2024-11-06 23:53:33 +01:00
Oliver Smith
54e55f26ef
require_programs: run losetup with absolute path (MR 2475)
Use the absolute path for it, so it works in Debian too as we run it
without sudo here to just check if the argument is supported.
2024-11-06 23:53:33 +01:00
Caleb Connolly
765ba770dd
chroot: merge executibles_absolute_path() logic into require_programs() (MR 2475)
Remove this chroot-specific helper and merge it in with the existing
require_programs() logic. Now we have one unified way to discover and
use programs from the host and where we can put any additional special
handling we might need.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-06 23:53:33 +01:00
Caleb Connolly
585c477239
config: find required programs every time pmbootstrap is run (MR 2475)
On debian systems in particular special handling is needed for
/usr/sbin. Let's do this once and then provide the host deps we use in a
nice accessible dictionary.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
Tweaked-by: Oliver Smith <ollieparanoid@postmarketos.org>
2024-11-06 23:53:33 +01:00
Oliver Smith
c4194759f5
require_programs: Debian: find kpartx and losetup (MR 2475)
In Debian, /usr/sbin is not in PATH of regular users unless using sudo.
Fix that pmbootstrap won't find kpartx and losetup in /usr/sbin, and
complains about these even though they are installed.

Fixes: issue 2489
2024-11-06 23:53: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
Caleb Connolly
39235fedfb
show the status output on failure (MR 2472)
There is a lot of context and state management needed when using
pmbootstrap, sometimes it can be a lot to keep in your head. Let's print
the output of "pmbootstrap status" when stuff goes wrong, this might
help remind people if e.g. their pmaports checkout is on the wrong
branch, or they're building for the wrong device.

Additionally, don't print the "run pmbootstrap log for details" message
if pmbootstrap was called with --details-to-stdout

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-04 10:15:59 +09:00
Caleb Connolly
7e7057042f
core: chroot: make ChrootType membership check work on python 3.10 (MR 2471)
You can't check enum membership with __contains__() on Python 3.10, poke
inside the enum instead.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 13:52:21 +01:00
Caleb Connolly
d57b9e31e1
config: init: support --aports too (MR 2470)
We shouldn't overwrite config.aports if the user specified a custom
--aports directory. We only want to do this to update the default if
they're using a custom workdir.

Make the code here less aggressive, and correctly use the last entry in
config.aports as "pmaports" instead of the first.

Fixes: #2386
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 12:26:32 +01:00
Caleb Connolly
a72a60f546
core: pkgrepo: support arbitrarily named pmaports directories (MR 2470)
There was an oversight when this API was originally created and it
implicitly assumed that the pmaports repository was always named
"pmaports". This unfortunately broke some peoples workflows.

Introduce a new "pkgrepo_name()" function and adjust the codebase to use
it, as well as adjusting pkgrepo internally to special case the
"pmaports" repo so that it's always named pmaports no matter what the
directory itself is named.

This is probably more complexity than we should be dealing with here, we
should probably create a new type to encode this behaviour.

Fixes: #2412
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 12:26:32 +01:00
Caleb Connolly
70dc855281
config: init: dont clobber config (MR 2470)
When pmbootstrap starts up, it loads the config file (or uses the
defaults) and then merged some arguments (e.g. --work) into it. However
in config.init.frontend() we were creating yet another new Config, but
it's too late to merge args in at this point...

Rework this slightly to fix that major oversight and remove the totally
unnecessary hack of calling pmb.config.load() again.

This fixes calling pmbootstrap init with --work

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 12:26:26 +01:00
Caleb Connolly
500b0908f8
helpers: run: stop handling Arch in PathString (MR 2463)
This was always a hack, and it looks like there (hopefully) aren't any
placs where we still need to handle this.

Possibly expecting regressions... But then we have something to write a
test for.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:39 +01:00
Caleb Connolly
41c8413fda
helpers: apk: sanity check final command (MR 2463)
When running "apk add" we must always have --cache-dir set! We also
expect --no-interactive to be set.

Add some asserts so we don't regress here.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:39 +01:00
Caleb Connolly
7847488058
commands: remove deviceinfo_parse (MR 2463)
Since parse.deviceinfo() returns a custom class now, it can't be
trivially serialized as JSON.

This has been broken for months now so it's clear nobody is using this.
Let's take the chance to get rid of it.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
26ec1631ca
helpers: apk_static: move from pmb.chroot (MR 2463)
Move the apk_static module from pmb/chroot to pmb/helpers which is a
more suitable location.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
c4a92c37a8
chroot: apk_static: remove dead run() function (MR 2463)
Since all apk invocations withing pmbootstrap now use apk.static by
default, apk_static.run() isn't called anymore, so let's remove it.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
42158637a7
chroot: apk: use apk.static in all cases (MR 2463)
In 0b4fb9119f (chroot: always run apk static v2 (MR 2423)) we adjusted
install_run_apk() to run apk static on the host and pass in the local
binary repo with "--repository". This function can call apk in two ways,
either with the progress bar handling or without, the second case was
never updated and still ran apk inside the chroot incorrectly and with
an incorrect --repository flag.

Let's finish the job by refactoring helpers/apk.py to support all our
usecases and pointing everything to it, removing the last few situations
where we call "pmb.chroot.root(["apk", ...]).

The apk_with_progress() function is replaced by a generic "run()"
function which takes a boolean to indicate if we should render apk
progress.

Additionally, a new cache_clean() function is added so that "pmbootstrap
zap --pkgs-online-mismatch" can FINALLY be refactored to not rely on a
chroot existing. This requires some hacks but nothing serious, see the
comments in the function for details.

The chroot.init() code is now simplified since handling the --root,
--arch, --cache-dir, and --repository flags is now all done by
apk._prepare_cmd() as and when appropriate.

Lastly, this fixes a (previously unnoticed) bug where apk.static was
actually using /var/cache/apk on your host machine for its cache... This
is definitely not good behaviour....

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
12846f3b8e
helpers: apk: move update_repository_list() from chroot.apk (MR 2463)
This function better belongs here, especially as it will be used outside
of the context of a chroot() soon.

Additionally, it's adjusted to take the rootfs path as its first
argument rather than a chroot, since it could operate on any rootfs.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
af1bf53867
helpers: logging: reduce the risk of a cyclical import (MR 2463)
Lazy load pmb.config.styles and move the pmb.__version__ print elsewhere
so the logging module is (closer to) a standalone entity. This is
necessary to be able to import it in pmb/helpers/apk.py otherwise we get
a cyclical dependency.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
2f39edd584
commands: repo_bootstrap: type hint (MR 2463)
make mypy happy

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
8b880b7198
config: export workdir modules (MR 2463)
Make intellisense happy

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 17:49:41 +01:00
Newbyte
b524d6daa2
pmb.parse.bootimg: Fall back to empty string if mtk properties don't exist (MR 2466)
This should match the previous behaviour and fix crashes when these
properties don't exist.

Tested with a htc-primou bootimg.

Fixes 826bb4f2dd
[ci:skip-build]: already built successfully in CI
2024-10-31 11:09:13 +01:00
Caleb Connolly
b9354d3ccd
test: parse: add test_deviceinfo (MR 2453)
Write some basic parser tests for deviceinfo. The parser is quite basic
so there isn't much to test yet. Expecting this to gain features as we
look at e.g. making the parser the "source of truth" for the deviceinfo
format.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-30 23:14:01 +01:00
Newbyte
225d8b30a0
pmb: Add lots of type hints (MR 2464) 2024-10-30 12:39:45 +01:00
Newbyte
d05d57b37e
pmb.install.recovery: Assert that partitions are not None (MR 2464)
They should definitely not be None here, thus assert it so we don't need
to keep checking for None later.
2024-10-29 23:08:37 +01:00
Newbyte
b49da9ad82
pmb.install.recovery: Check for None before going through blacklist (MR 2464)
It doesn't really make sense to check the blacklist against None, so
just skip the value if it's None. Appeases mypy.
2024-10-29 23:08:37 +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
fc44b64233
pmb.flasher.init: Assert that depends is a list (MR 2464)
pmaports_cfg.get() can return other types, too. As such, we need to
assert that it's a list to appease mypy.
2024-10-29 23:08:37 +01:00
Newbyte
d5586979aa
pmb.sideload: Separate distinct uses of add_cmd into different variables (MR 2464)
Helps mypy understand the code better and also makes it easier to read
as a human in my opinion.
2024-10-29 23:08:36 +01:00
Newbyte
d4ea780752
pmb.helpers.run_core: Properly type pipe_read() (MR 2464)
I think the "these types make no sense" comment were about
output_return_buffer, which defaulted to False but was to be set to
list[bytes] if used. I changed it so that it defaults to None, which
probably is more conventional. Other than that I didn't notice anything
weird about the types here.

Also check for None as necessary to appease mypy.
2024-10-29 23:08:36 +01:00
Newbyte
47c8492577
pmb.qemu.run: Use f-string for img_path_2nd argument building (MR 2464)
img_path_2nd is a Path, not a str, so we can't just rely on string
concatenation here.

img_path_2nd is a Path as that's what create_second_storage() returns
since 198f302a36.
2024-10-29 23:08:36 +01:00
Newbyte
826bb4f2dd
pmb: Properly type Bootimg (MR 2464)
This could be done better with a real class instead of a TypedDict, but
it's better than a regular dict.
2024-10-29 23:08:36 +01:00
Newbyte
f2c7fa1107
pmb.types: Add Apkbuild type (MR 2464)
Useful for annotating places where a parsed APKBUILD is expected.
2024-10-29 23:08:36 +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
Newbyte
c1527ba95d
pmb.types: Simplify CrossCompileType definition (MR 2464)
This is equivalent to the previous definition, but more concise.
2024-10-29 23:08:36 +01:00
Newbyte
6b55ce7b53
pmb.build.envkernel: Convert Arch.native() to str (MR 2464)
We don't want an actual Arch object in the environment object.
2024-10-29 23:08:36 +01:00
Newbyte
98f1491426
pmb.build.envkernel: Properly construct path to remove (MR 2464)
Can't construct a path by using the / operator on strings, so use the
Path constructor instead.
2024-10-29 23:08:36 +01:00
Newbyte
613f50b834
pmb.parse.depends: Remove unused functions (MR 2464)
This is no longer used as of 1299c2ef6d,
so just remove this dead code.
2024-10-29 15:42:46 +01:00
Newbyte
6f79967fde
pmb.chroot.initfs: Assert that flavor is not None in build() (MR 2464)
If flavor is None here, something has gone wrong and the line after will
fail. Explicitly assert that it has the right value to appease mypy.
2024-10-29 14:49:36 +01:00
Newbyte
1aa0b05014
pmb.install.blockdevice: Avoid reusing size_mb variable in create_and_mount_image() (MR 2464)
Reusing this variable might lead to confusing bugs later if this code is
changed in the future, and also leads to mypy being confused about the
type of size_mb as it then gets assigned both str and int values.
2024-10-29 14:21:01 +01:00
Newbyte
f507aed9aa
pmb.build.autodetect: Fix return type and docstring for arch() (MR 2464)
At some point, this function was updated to use the Arch type instead of
plain strings, but the return type was left omitted and the docstring
outdated.
2024-10-29 13:49:37 +01:00
Newbyte
a89ecb11d2
pmb.build._package: Remove reference to nonexistent parameter (MR 2464)
No parameter called "now" exists for this function, so don't document
it.
2024-10-29 13:08:07 +01:00
Oliver Smith
7269d05b20
pmb.helpers.repo.download: proper error for 404 (MR 2462)
Flush the progress bar displayed by the function before logging a
warning message for 404 not found responses from the server. Without
flushing, this message gets lost.

In addition to the warning, display a NOTE and ERROR at the end to
explain what went wrong:

  [20:16:50] Update package index for x86_64 (4 file(s))
  [20:16:51] WARNING: file not found: http://mirror.postmarketos.org/postmarketos_get_404_test/edge/main/x86_64/APKINDEX.tar.gz
  [20:16:51] NOTE: check the [mirrors] section in 'pmbootstrap config'
  [20:16:51] ERROR: getting APKINDEX from binary package mirror failed!

Without handling this properly, pmbootstrap would fail slightly later
with a much less useful error:

  [15:14:28] ERROR: expected str, bytes or os.PathLike object, not NoneType

Fixes: pmbootstrap issue 2424
2024-10-27 20:52:13 +01:00