Commit graph

130 commits

Author SHA1 Message Date
Oliver Smith
9dfa89c58c
Use pmbootstrap_v3.cfg as config file (MR 2350)
Using pmbootstrap v3 with the old config can cause problems, for example
when having $WORK in the pmaports dir instead of the actual work path.
This is not supported anymore by v3 to reduce complexity. The format of
how mirrors are stored in the config also has changed.

Use a separate config file, so users can go back from v3 to 2.3.x if
they need to (for figuring out a regression) and so users won't run into
bugs when moving from 2.3.x to v3.
2024-07-10 20:06:25 +02:00
Caleb Connolly
8da12a98a7
helpers: other: drop args from migrate_work_folder() (MR 2352)
Was erronesously passing args to cli.confirm.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-09 00:45:23 +02:00
Caleb Connolly
35eff91564
treewide: drop context.device (MR 2332)
this turns out to have never been set??? We have config.device anyways,
so let's use that instead.

Tweaked-by: Oliver Smith <ollieparanoid@postmarketos.org>
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-30 17:51:45 +02:00
Caleb Connolly
84332cdce0
config: init: args.keymap -> config.keymap (MR 2332)
Note by Oliver: this patch also removes the args argument from
ask_for_username.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-30 17:51:35 +02:00
gompa
8390a093d8
Fix quotation reuse (MR 2336)
Python 3.10.12 fails without this patch:

File "/media/gompa/73d88639-a730-456c-a428-6d500b4020b7/pmbootstrap/pmb/parse/arguments.py", line 844 help="Alpine Linux mirror, default: " f"{default_config.mirrors["alpine"]}",
SyntaxError: f-string: unmatched '['

Related: https://peps.python.org/pep-0701/
(Commit message written by Oliver)
2024-06-24 21:55:53 +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
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
8398bc1218
Do not use bare except (MR 2325)
A bare except catches things like ctrl+c (KeyboardInterrupt). If don't
want to catch this exception. Remove the bare except and restore the
default lint.
2024-06-23 15:40:13 +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
3f11fa2500
tests: basic pkgrepo tests, clone pmaports (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:41 +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
fc010bc7c8
config: fixes + handle mirrors migration (MR 2252)
Get rid of config.mirror_alpine and mirrors_postmarketos and make sure
they get migrated over for existing users.

mirrors_postmarketos being a list was always a bit off, but now we have
per-aports mirrors which make a lot more sense for what we're trying to
do with systemd.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:40 +02:00
Caleb Connolly
1a01738d50
config: sanity check via types (MR 2252)
Replace the "sanity_check" code with type checking built into the Config
__setattr__ operator.

This keeps all the Config related code in one place.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
450bc6873d
core: move Config type (MR 2252)
Keeping the Config class in types seemed kinda weird and was just done
as a workaround to some cyclical imports. But now things are more in
shape let's move it to core.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
bc0b6e39e8
config: fix load/save/ask (MR 2252)
Fix all the config code so pmbootstrap init works again...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
d8d55c3e52
aportgen: fix fork_alpine flag (MR 2252)
Broke during rework

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
97bd8b96ec
parse: deviceinfo: make Deviceinfo a class (MR 2252)
Introduce a Deviceinfo class and use it rather than the dictionary. This
gives us sweet sweet autocomplete, and lays the foundation for having a
proper deviceinfo validator in the future.

Additionally, continue refactoring out args...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
d9e1da98b2
more n more (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
de4c912692
WIP: 2024-06-05: args hacking and more (MR 2252)
Continue removing args and do some other optimisations.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
48cd886401
more wip (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
34dd9d42ba
WIP: start ripping out args (MR 2252)
Cease merging pmbootstrap.cfg into args, implement a Context type to let
us pull globals out of thin air (as an intermediate workaround) and rip
args out of a lot of the codebase.

This is just a first pass, after this we can split all the state that
leaked over into Context into types with narrower scopes (like a
BuildContext(), etc).

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
0a0cba51e1
helpers: ui: rename list() to list_ui() (MR 2252)
list is a reserved keyword...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
1be8653935
drop args from helpers.git and chroot.apk (MR 2252)
be gone!

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
05c86be11c
helpers: drop args from helpers.run functions (MR 2252)
Now we can run commands without needs args available!

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:37 +02:00
Caleb Connolly
31cc898dd5
treewide: adopt pathlib.Path and type hinting (MR 2252)
With the new chroot type, we can now write fancy paths in the pythonic
way. Convert most of the codebase over, as well as adding various other
type hints.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:37 +02:00
Caleb Connolly
71e7af57e6
pmb.helpers.logging: wrap logging module (MR 2252)
We use a custom verbose log level in pmbootstrap, unfortunately it isn't
possible to correctly type this due to some limitations in the logging
library [1], [2].

Given that our usecase is fairly simple, we can just wrap the module
with our own so we only have to tell mypy to ignore the error once
instead of at every callsite.

[1]: https://github.com/cryptax/droidlysis/issues/15
[2]: https://github.com/python/typing/discussions/980

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:37 +02:00
Caleb Connolly
198f302a36
treewide: add a Chroot type and adopt pathlib.Path (MR 2252)
Introduce a new module: pmb.core to contain explicitly typed pmbootstrap
API. The first component being Suffix and SuffixType. This explicitly
defines what suffixes are possible, future changes should aim to further
constrain this API (e.g. by validating against available device
codenames or architectures for buildroot suffixes).

Additionally, migrate the entire codebase over to using pathlib.Path.
This is a relatively new part of the Python standard library that uses a
more object oriented model for path handling. It also uses strong type
hinting and has other features that make it much cleaner and easier to
work with than pure f-strings. The Chroot class overloads the "/"
operator the same way the Path object does, allowing one to write paths
relative to a given chroot as:

builddir = chroot / "home/pmos/build"

The Chroot class also has a string representation ("native", or
"rootfs_valve-jupiter"), and a .path property for directly accessing the
absolute path (as a Path object).

The general idea here is to encapsulate common patterns into type hinted
code, and gradually reduce the amount of assumptions made around the
codebase so that future changes are easier to implement.

As the chroot suffixes are now part of the Chroot class, we also
implement validation for them, this encodes the rules on suffix naming
and will cause a runtime exception if a suffix doesn't follow the rules.
2024-06-23 12:38:37 +02:00
Newbyte
0df75422b4
treewide: Rename unmaintained to archived (MR 2308)
See https://gitlab.com/postmarketOS/pmaports/-/merge_requests/5046
2024-05-15 17:06:37 +02:00
Robert Eckelmann
044d3b5a6a
pmb.*: various comment reformatting to assist with generating docs (MR 2266) 2024-05-14 14:36:22 +02:00
Oliver Smith
8bafa93bb2
pmbootstrap init: remove text about daily zapping (MR 2293)
Now that pmbootstrap displays a warning on stale chroots, we don't need
to show this at the end of "pmbootstrap init".
2024-04-11 21:50:35 +00:00
Oliver Smith
4478116379
Add sanity check for "systemd" config values (MR 2273)
Make sure users don't set systemd to "true" or other not allowed values
(allowed are "always", "default", "never").

Check for it:
* after loading the config
* when using 'pmbootstrap config systemd <newvalue>'
2024-03-12 23:53:47 +00:00
Oliver Smith
bfc64d1cb8
Support pmb:systemd-never option (MR 2273)
For UI packages that have pmb:systemd-never set:
* do not ask in "pmbootstrap init" whether to use systemd or not
* do not install systemd, even if the systemd option is set to "always"

The point of this is to not add maintenance burden to Sxmo (and possibly
other UIs who not wish to support systemd with postmarketOS), so users
don't install with this unsupported use case and report issues with it.
2024-03-12 23:53:47 +00:00
Oliver Smith
e96ca36376
init: ask whether to install systemd (MR 2273)
Add the following question to "pmbootstrap init":

[22:12:57] Based on your UI selection, 'default' will result in installing systemd.
[22:12:57] Install systemd? (default/always/never) [default]:

Determine whether the UI prefers to have systemd or not, based on
"pmb:systemd" in the UI package's APKBUILD.

Determine whether the currently selected branch supports systemd, by
checking for a "[repo:systemd]" section in pmaports.cfg. This section
will also contain bootstrap information, to be used in future patches.
2024-03-12 23:53:42 +00:00
Clayton Craft
aa594b76fa
pmb.config: do not prompt for nonfree fw/userland (MR 2255)
This drops the prompt for using non-free firmware in images. The logic
for searching/installing non-free fw subpackages for devices is kept,
and will always be installed. This is to support the many device
packages in pmaports that still have nonfree-firmware subpackages. Going
forward, device packages can list firmware in `depends=` (for required
fw) or `pmb_recommends` (for optional fw).

nonfree-userland wasn't used in pmaports as far as I could find.
2024-02-15 16:00:56 -08:00
Clayton Craft
c0937a52dc
config.init: allow using pmb_select in pmos-base-ui
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20231122081214.11872-3-clayton@craftyguy.net%3E
2023-11-26 11:01:35 +01:00
Oliver Smith
17ce5e611c
init: tweak UIs hidden message
Shorten this message:

> NOTE: 6 user interfaces are not available. If device supports GPU
> acceleration, set "deviceinfo_gpu_accelerated" to make UIs available.
> See: <https://wiki.postmarketos.org/wiki/Deviceinfo_reference

to:

> NOTE: 6 UIs are hidden because "deviceinfo_gpu_accelerated" is not set
> (see https://postmarketos.org/deviceinfo).

This also fixes the non-closed angle bracket by simply removing it. I
used to put angle brackets around all URLs printed in pmbootstrap
initially, but have been moving away from that when touching related
code as it doesn't add anything useful.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230802172542.4861-3-ollieparanoid@postmarketos.org%3E
2023-08-06 20:05:50 +02:00
Luca Weiss
374d7779e9
pmb.config: only show first 3 releases
Currently we're already showing a long list of unsupported releases,
which should not really be used by any user. Hide them by just showing
the first 3 releases in the list which avoids adding complicated custom
logic to e.g. channels.cfg.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230607205714.84945-1-luca@z3ntu.xyz%3E
2023-06-12 08:46:23 +02:00
Luca Weiss
50ccaae76b
pmb.config: select default UI in case current is not available
For kernel selection we already choose a default like this, which makes
sense since there's no point in having a preselected choice which
doesn't exist (anymore). Also useful for some test suites where it runs
"yes | pmbootstrap init" which would hang on this question.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230607204449.84020-2-luca@z3ntu.xyz%3E
2023-06-12 08:46:23 +02:00
Oliver Smith
197b8d3521
init: allow all locales
Replace the (outdated) list of locales supported in musl with a list
from all locales supported by glibc. The list of locales is taken from
the patch that is applied to musl-locales in alpine.

Related: 2dc905dc77
Closes: pmbootstrap issue 1997
Reviewed-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230603160540.18732-1-ollieparanoid@postmarketos.org%3E
2023-06-12 08:46:22 +02:00
Pablo Correa Gómez
10fd860837
pmb.config.init: copy pmaports githooks to default git hooks dir
So that githooks can be used in pmaports without the risk that symlinks
pose when checking out random branches from random people. The hooks
are copied, only when doing "pmbootstrap init", selecting the edge
channel and having the master branch checked out (not any other branch
on the edge channel or on any other channel).

Closes: pmaports#2055
Related: pmaports!4008
Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Co-developed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3CDB9P192MB129107CAA025F4EF59D3FB53C7999@DB9P192MB1291.EURP192.PROD.OUTLOOK.COM%3E
2023-04-15 01:44:36 +02:00
Oliver Smith
98290f9191
pmbootstrap init: don't allow 'root' as username
While going over the wiki pages recently, I've noticed that somebody
added a note to not use "root" as username. I don't think many people
will attempt to do this, but let's catch it here in pmbootstrap with a
friendly message instead of mentioning it in the wiki.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230126071154.1689-1-ollieparanoid@postmarketos.org%3E
2023-02-19 16:13:52 +01:00
Oliver Smith
9975d373b0
Bump copyright to 2023 2023-01-22 19:18:06 +01:00
Luca Weiss
58c39f2cb2
pmb.config.init: fix init when work path is an empty directory (MR 2192)
In case a user removes all contents of the work path then pmbootstrap
init will fail and show

  WARNING: Your work folder version needs to be migrated (from version 0 to 6)!

Later the migration would fail with the error

  ERROR: We have split the aports repository from the pmbootstrap repository (#383). Please run 'pmbootstrap init' again to clone it.

This is due to the existing check not accounting for e.g. log.txt being
written in the work path before we get to this check. Now change it so
we always create the version file if it doesn't exist yet.

Test plan:
$ grep work ~/.config/pmbootstrap.cfg
work = /tmp/pmbootstrap-work
$ rm -rf /tmp/pmbootstrap-work
$ mkdir /tmp/pmbootstrap-work
$ pmbootstrap init

This was previously attempted to be fixed in !1975
2022-06-24 14:57:20 +02:00
Oliver Smith
6f6a3b0408
Happy new year 2022! 2022-01-02 22:39:14 +01:00
BO41
99bed38272
pmb.parse.apkbuild: remove unused args argument (MR 2136) 2021-11-27 14:13:33 +01:00
Minecrell
8ace36113c
pmb.config/install: add flexible provider selection for "pmbootstrap init" (MR 2132)
The provider selection for "pmbootstrap init" added in this commit
is a flexible way to offer UI/device-specific configuration options
in "pmbootstrap init", without hardcoding them in pmbootstrap.
Instead, the options are defined entirely in pmaports using APK's
virtual package provider mechanism. The code in pmbootstrap searches
for available providers and displays them together with their pkgdesc.

There are many possible use cases for this but I have tested two so far:

  1. Selecting root provider (sudo vs doas). This can be defined entirely
     in postmarketos-base, without having to handle this specifically in
     pmbootstrap.

     $ pmbootstrap init
     [...]
     Available providers for postmarketos-root (2):
      * sudo: Use sudo to run root commands (**default**)
      * doas: Use doas (minimal replacement for sudo) to run root commands
              (Note: Does not support all functionality of sudo)
     Provider [default]: doas

  2. Device-specific options. My main motivation for working on this
     feature is a new configuration option for the MSM8916-based devices.
     It allows more control about which firmware to enable:

     $ pmbootstrap init
     [...]
     Available providers for soc-qcom-msm8916-rproc (3):
      * all: Enable all remote processors (audio goes through modem) (default)
      * no-modem: Disable only modem (audio bypasses modem, ~80 MiB more RAM)
      * none: Disable all remote processors (no WiFi/BT/modem, ~90 MiB more RAM)
     Provider [default]: no-modem

The configuration prompts show up dynamically by defining
_pmb_select="<virtual packages>" in postmarketos-base, a UI PKGBUILD
or the device APKBUILD. Selecting "default" (just pressing enter)
means that no provider is selected. This allows APK to choose it
automatically based on the "provider_priority". It also provides
compatibility with existing installation; APK will just choose the
default provider when upgrading. The selection can still be changed
after installation by installing another provider using "apk".

Note that at the end this is just a more convenient interface for the
already existing "extra packages" prompt. When using pmbootstrap in
automated scripts the providers (e.g. "postmarketos-root-doas") can be
simply selected through the existing "extra_packages" option.
2021-11-06 15:04:34 +01:00
Minecrell
9d724d5d3d
pmb.config.init: parse deviceinfo only once (MR 2132)
Instead of parsing the deviceinfo over and over again, parse it once
and pass it to all the functions that make use of it.
2021-11-06 15:04:20 +01:00
BO41
944f539dd6
args.logfd: remove (MR 2114)
Replace "args.logfd" with "pmb.helpers.logging.logfd" in order to avoid
passing "args" to all functions that only use it to write to logfd. This
is the first step to get rid of this args-passed-to-all-functions
pattern in pmbootstrap.
2021-10-10 16:59:17 +02:00
BO41
e1aef47271
pmbootstrap: make use of consistent casing (MR 2090) 2021-08-12 17:06:11 +02:00