Compare commits

...

635 Commits

Author SHA1 Message Date
Clayton Craft 4ff0b1f6c2
parse.apkindex: fix typo
CI apparently enforces spellcheck for comments now, so this also fixes
CI :D
2023-10-11 12:15:17 -07:00
Lauren N. Liberda 753e563ccc
parse: allow "-r" in pkgver
this seems to be parsed correctly, other than this one check

bug: https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2260
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230813202045.24493-1-lauren@selfisekai.rocks%3E
2023-08-14 09:52:23 +02:00
Raymond Hackley 9045bfb2b9
README.md: add armv7 to supported architecture
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230812155519.52730-1-raymondhackley@protonmail.com%3E
2023-08-14 09:52:23 +02:00
Oliver Smith f4fed3d99e
test/test_crossdirect: remove
Remove test_crossdirect_rust, the only test in test_crossdirect.py. The
behavior that was tested here with all the "mv /usr/bin/rustc" commands
was specific to version 4 and isn't valid anymore since version 5
(pmaports MR 4234).

The previous behavior was that crossdirect always tried to run rustc
from /native, and if it failed, it would fall back to using qemu. The
new behavior is that it runs rustc from /native only when it expects it
to succeed, and runs rustc via qemu otherwise, without attempting
/native first. As the logic to decide whether to use native rustc or not
is now done beforehand, it does not do the fallback to qemu if native
fails.

Note that the test hasn't been failing because we switch to the v23.06
channel and therefore use the older crossdirect version.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230806184729.4891-6-ollieparanoid@postmarketos.org%3E
2023-08-14 09:52:22 +02:00
Oliver Smith 147a0f5c4d
build: use sccache for rust
Cache the compiler output of rust code with sccache, like we use ccache
for c code.

I've considered using sccache to completely replace ccache since it can
cache output of C/C++ code too. But let's not do it for now since ccache
doesn't need to run a daemon in the background that needs to be stopped
when shutting down / zapping. Also it would need more refactoring.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230806184729.4891-5-ollieparanoid@postmarketos.org%3E
2023-08-14 09:52:22 +02:00
Oliver Smith 94fbe9746b
Cosmetic: build: add comment about rust deps
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230806184729.4891-4-ollieparanoid@postmarketos.org%3E
2023-08-14 09:52:22 +02:00
Oliver Smith 0ff6ad481d
install: remove /mnt/pmbootstrap at the end
Don't include the /mnt/pmbootstrap directories in the images created
with "pmbootstrap install".

Reviewed-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230806184729.4891-3-ollieparanoid@postmarketos.org%3E
2023-08-14 09:52:22 +02:00
Oliver Smith fdbb8eebb8
chroot: /mnt/pmbootstrap-* -> /mnt/pmbootstrap/*
Have one /mnt/pmbootstrap directory with subdirectories, instead of
several /mnt/pmbootstrap-* directories.

Reviewed-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230806184729.4891-2-ollieparanoid@postmarketos.org%3E
2023-08-14 09:52:17 +02:00
Oliver Smith b08d29df5d
install: get install_user_groups from pmaports.cfg
Get the groups from pmaports.cfg in the currently checked out pmaports
branch. This is in preparation for removing "input" from the list of
default groups to tighten security. We can do it in edge first, fix
possible fallout and have it in the next release branch.

Related: pmbootstrap issue 2257
Related: https://postmarketos.org/pmaports.cfg
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230803080203.6549-1-ollieparanoid@postmarketos.org%3E
2023-08-06 20:05:50 +02: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
Oliver Smith 216b3ef267
pmb.aportgen.device: modernize defaults
Change the defaults in the new device port wizard:

* arch: armv7 -> aarch64
  New devices are more likely to be aarch64.

* flash method: 0xffff -> none
  The only device that uses 0xffff is the N900, it's extremely unlikely
  that it will get used for a new port. Use the neutral "none" instead.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230802172542.4861-2-ollieparanoid@postmarketos.org%3E
2023-08-06 20:05:45 +02:00
Oliver Smith b721b08e19
Prepare 2.0.0 release 2023-08-01 07:51:02 +02:00
Pablo Correa Gómez 0489f7f40c
aportgen: device: rename modules to modules-initfs
The extra verbosity can be useful here.

See https://gitlab.com/postmarketOS/pmaports/-/merge_requests/4169#note_1489955273
for more details

Fixes ad85c7bc17

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230728113116.31529-1-pabloyoyoista@postmarketos.org%3E
2023-07-30 19:10:51 +02:00
Oliver Smith 93bf267481
test: fix test_build_depends_binary_outdated
After we have removed binutils-aarch64 etc. from pmaports, this test
started to fail with the following:
  Failed: DID NOT RAISE <class 'RuntimeError'>

Rewrite it to try to build "hello-world-wrapper" instead, and mark its
dependency "hello-world" as outdated. While it's not great to depend on
packages in pmaports for testing, at least these two are explicitly
made for the testsuite and are less likely to change.

Related: https://gitlab.com/postmarketOS/pmaports/-/merge_requests/3275
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230724070509.1885-3-ollieparanoid@postmarketos.org%3E
2023-07-25 09:13:39 +02:00
Oliver Smith 685f2fa9a8
test: fix running test_build_package.py standalone
Add the "args" fixture to test_skip_already_built, so it correctly
initializes logging (and indirectly pmb.helpers.other.cache). With this
it becomes possible to run the test file on its own. See "def args" on
top of the file for implementation of the "args" fixture.

Fix for:
$ pytest -xvv test/test_build_package.py
…
>       assert pmb.helpers.other.cache["built"] == {}                                                                                                          E       TypeError: 'NoneType' object is not subscriptable

Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230724070509.1885-2-ollieparanoid@postmarketos.org%3E
2023-07-25 09:13:33 +02:00
Pablo Correa Gómez a806835441
deviceinfo: make parse_kernel_suffix private
Just a small and trivial improvement to signal method is private

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230720164718.18964-1-pabloyoyoista@postmarketos.org%3E
2023-07-21 08:54:10 +02:00
Pablo Correa Gómez ad85c7bc17
aportgen: replace deviceinfo_modules_initfs for modules file
So deviceinfo_modules_initfs is going to be phased out in pmaports!4169 as
a preparation for pmaports#1836. The implementation for the alternative of
using a modules file has already been merged in pmaports!4193, so stop
promoting the soon-to-be-phased-out deviceinfo variable, and instead use
the new and already-supported alternative.

Related: https://gitlab.com/postmarketOS/pmaports/-/issues/1836
Related: https://gitlab.com/postmarketOS/pmaports/-/merge_requests/4169
Related: https://gitlab.com/postmarketOS/pmaports/-/merge_requests/4193
Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230720164706.18936-1-pabloyoyoista@postmarketos.org%3E
2023-07-21 08:54:10 +02:00
Oliver Smith 13c4ac425b
pmb.helpers.run_core: fix proxy env var logic
Fix that the list "cmd" was turned into a string if one of the proxy
vars was set in the environment. Add a test for this code path. Before
this patch:

$ FTP_PROXY=test pmbootstrap -v --details-to-stdout status
…
% cd /home/user/.local/var/pmbootstrap/cache_git/pmaports; git remote -v
run: FTP_PROXY=test ['git', 'remote', '-v']
ERROR: [Errno 2] No such file or directory: "FTP_PROXY=test ['git', 'remote', '-v']"

Fixes: 1a00c04f ("pmb.helpers.run_core: always configure proxy vars if set in environment")
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230713182337.6185-3-ollieparanoid@postmarketos.org%3E
2023-07-21 08:54:10 +02:00
Oliver Smith 20a0ccf36f
pmb.helpers.run_core: move flat_cmd here
Move pmb.helpers.run.flat_cmd to run_core, as it will be used by
pmb.helpers.run_core.core in the next patch.

Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230713182337.6185-2-ollieparanoid@postmarketos.org%3E
2023-07-21 08:54:04 +02:00
Anton Bambura 46789ccee8
pmb.install: create fstab and crypttab
It is needed for booting with UUIDs

Link: https://gitlab.com/postmarketOS/pmaports/-/issues/1531
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Tested-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C168964079267.5324.15935279761788836851-1@git.sr.ht%3E
2023-07-20 08:22:10 +02:00
Anton Bambura 94f697c7f5
pmb/partition: fix cgpt root_size to not cause resize on boot
Current setup leaves 991 unused sectors which causes root partition
to be resized on boot. Fix it.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C168962297313.22523.18408902364202107570-1@git.sr.ht%3E
2023-07-20 08:21:19 +02:00
Caleb Connolly 1b8edd9abb
test/test_pkgrel_bump: make sure pmb doesn't cross compile
When build_default_device_arch is set in your local pmbootstrap config,
some tests fail because pmbootstrap tries to cross compile. Make sure
this option is disabled in the test context.

Signed-off-by: Caleb Connolly <kc@postmarketos.org>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230629-suffix-type-hint-v1-5-e92802ae20a8@postmarketos.org%3E
2023-07-13 10:07:54 +02:00
Caleb Connolly ab3093db18
test: crossdirect: update stable branch ref
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230629-suffix-type-hint-v1-4-e92802ae20a8@postmarketos.org%3E
2023-07-13 10:07:54 +02:00
Caleb Connolly 78b78410a4
test: specify default git branch
don't assume that master is the default branch name.

Signed-off-by: Caleb Connolly <kc@postmarketos.org>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230629-suffix-type-hint-v1-3-e92802ae20a8@postmarketos.org%3E
2023-07-13 10:07:53 +02:00
Caleb Connolly d32be64820
test: dont fail on githook symlinks
Since introducing git hooks, these tests fail locally because copytree
can't handle the relative symlinks. Add a helper for this common pattern
and set ignore_dangling_symlinks to safely skip these symlinks.

Signed-off-by: Caleb Connolly <kc@postmarketos.org>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230629-suffix-type-hint-v1-2-e92802ae20a8@postmarketos.org%3E
2023-07-13 10:07:53 +02:00
Clayton Craft 1a00c04f74
pmb.helpers.run_core: always configure proxy vars if set in environment
By configuring proxy vars in run_core.core, we can ensure that the
environment is always aware of any configured proxy, whether it's
running natively or in a chroot.

fixes https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2249

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230713021822.15223-2-clayton@craftyguy.net%3E
2023-07-13 10:07:53 +02:00
hexaheximal caf4d779e3
Add mtkclient as a flasher option
Since we're using mtkclient a lot anyways, it makes sense to add
support for it to pmbootstrap.

This was originally implemented by JustSoup321, but they had issues
submitting the patch, so I've cleaned it up for upstream submission.

Co-Authored-By: JustSoup321 <brandonboese@protonmail.com>
Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
Signed-off-by: hexaheximal <hexaheximal@proton.me>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230712231807.22590-1-hexaheximal@proton.me%3E
2023-07-13 10:07:53 +02:00
Affe Null 122b90005f
Install makedepends in native chroot for packages using Rust
The changes in pmaports!4234 cause cargo build scripts to be built
for and run on the host (native) architecture, so their dependencies
must be present in the native chroot.

pmbootstrap can't tell which of the dependencies specified in
makedepends are actually needed by build scripts, so just duplicate all
of them in the native chroot.

Acked-by: Caleb Connolly <kc@postmarketos.org>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230710135001.184769-1-otto.pflueger@abscue.de%3E
2023-07-13 10:07:53 +02:00
Oliver Smith c734b2c523
CI: add codespell
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230706211537.10438-3-ollieparanoid@postmarketos.org%3E
2023-07-13 10:07:53 +02:00
Oliver Smith 67fe5a62fd
treewide: fix typos found with codespell
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230706211537.10438-2-ollieparanoid@postmarketos.org%3E
2023-07-13 10:07:53 +02:00
Anton Bambura 047df10d57
Support --no-cgpt
Some people may use U-Boot instead of depthcharge and they don't want cgpt

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C168861285289.22824.11703157261469263638-0@git.sr.ht%3E
2023-07-13 10:07:47 +02:00
Anton Bambura a3a82f623a
install/partition: rearrange cgpt commands in natural order
This workaround is not needed anymore.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C168844148723.7161.318848193297628515-1@git.sr.ht%3E
2023-07-05 10:02:40 +02:00
Anton Bambura b1536416ed
install/partition: set efi flag with cgpt
Some devices (veyron) have read-only primary GPT record on eMMC and
parted can't handle it. It results in U-Boot not being able to boot
from eMMC.

Fix it by setting efi flag with cgpt instead of parted.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C168844148723.7161.318848193297628515-0@git.sr.ht%3E
2023-07-05 10:02:40 +02:00
Luca Weiss 1e3eea7087
CI: enable eval-annotations for vermin
It has happened more than once that Python 3.9+ type annotation have
slipped into the code and broken earlier Python versions. Enable the
eval-annotations flag in vermin to catch that.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230625193650.528651-2-luca@z3ntu.xyz%3E
2023-07-05 10:02:28 +02:00
Luca Weiss a3dda34785
pmb.config: Use Python 3.8-compatible type annotation
The 'list' type annotation only works from Python 3.9 and since we still
support Python 3.7 we should use the version from the typing package
instead.

Closes: https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2247
Fixes: d31313f7 ("Don't use 'sudo' when running as root")
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230625193650.528651-1-luca@z3ntu.xyz%3E
2023-07-05 10:02:28 +02:00
eval Nya 620f3af691
envkernel.sh: use realpath to deal with symlink
Suggest to change suffix to bash:
POSIX does not provide a way to detect sourced script path, and
the working method in this script is bash-specific. (The sh-method
would not working in some cases like shell in shell)

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230618045230.28622-1-11857526-nexplorer-3e@users.noreply.gitlab.com%3E
2023-07-05 10:02:18 +02:00
Oliver Smith 185973fd97
Remove distcc support
With this code path, pmbootstrap would start a distccd + sshd in the
native chroot, and configure it so it runs the cross compiler. The
foreign arch chroots would then call this cross compiler from localhost
by calling the distcc client instead of gcc.

This code has been obsoleted by the much simpler crossdirect in 2019.
Let's finally remove it.

Fixes: issue 2179
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230613161437.570196-4-ollieparanoid@postmarketos.org%3E
2023-06-15 08:31:03 +02:00
Oliver Smith 25b3530c4e
Remove --no-crossdirect argument
With an upcoming patch to remove the legacy distcc code, the
--no-crossdirect argument would do the same as --no-cross: perform the
build entirely in qemu. So remove the argument. I doubt anybody was
using it anyway.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230613161437.570196-3-ollieparanoid@postmarketos.org%3E
2023-06-15 08:31:03 +02:00
Oliver Smith 7f5c87e5dd
Remove workaround for gcc with !tracedeps
Get rid of a workaround that isn't needed anymore. Also this makes use
of the get_gcc_version() function that is otherwise only needed for
the long obsolete distcc code, which I'm about to remove in the next
patch.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230613161437.570196-2-ollieparanoid@postmarketos.org%3E
2023-06-15 08:31:03 +02:00
Oliver Smith cff80f1d76
lint: drop call to pmb.build.init
It is not necessary to install build-base or abuild inside the chroot
before running apkbuild-lint. I've verified that the output of
"pmbootstrap lint" is the same without it. Drop it to make it faster.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230613151807.568708-2-ollieparanoid@postmarketos.org%3E
2023-06-15 08:30:54 +02:00
Oliver Smith 099238525a
aportgen: use pmb.build.init_abuild_minimal
Use init_abuild_minimal instead of init to avoid installing gcc etc.
when generating checksums. This function has been added previously in
c6bcb0da ("Speed up 'pmbootstrap checksum'").

Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230613151807.568708-1-ollieparanoid@postmarketos.org%3E
2023-06-15 08:30:54 +02:00
Clayton Craft d6c6e70933
pmb.helpers.run_core: fix sudo timer when not using sudo
pmb.config.sudo expects a list of commands + args, so when a string is
passed (e.g. "true"), it results in pmb trying to execute the equivalent
of "$ t r u e":

(8/119) Installing linux-purism-librem5 (6.3.4-r0)

doas: t: command not found
doas: t: command not found
doas: t: command not found
doas: t: command not found

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230613141929.15718-1-clayton@craftyguy.net%3E
2023-06-13 17:20:42 +02:00
Pablo Correa Gómez 7671353158
install: run setup-timezone with "-i" when appropriate
This makes sure that the "/etc/localtime" file being created points to
the tzdata directory (/usr/share/zoneinfo), instead of to the custom
"/etc/zoneinfo" created by alpine to save space. This is relevant
because it otherwise will point to a directory that contains
incomplete tzdata, and can produce unexpected results in some circumnstances.

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Tested-by: Clayton Craft <clayton@craftyguy.net>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230611150743.23310-3-ablocorrea@hotmail.com%3E
2023-06-12 08:46:23 +02:00
Pablo Correa Gómez 36d5bcbd3d
install: move setup_timezone to its own function
Some refactoring for the next commit

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Tested-by: Clayton Craft <clayton@craftyguy.net>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230611150743.23310-2-ablocorrea@hotmail.com%3E
2023-06-12 08:46:23 +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
Luca Weiss 7af145fedb
pmb.config: set default UI to console
Weston is since long not a good default choice anymore. Switch it to
console which is a (mostly) unopinionated default choice.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230607204449.84020-1-luca@z3ntu.xyz%3E
2023-06-12 08:46:23 +02:00
Luca Weiss 97eb39f34b
flasher: remove long deprecated flash_system alias
A long long time ago we renamed flash_system to flash_rootfs, and now
it's time to finally remove this alias since nobody should be using it
anymore.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230605220329.14328-4-luca@z3ntu.xyz%3E
2023-06-12 08:46:22 +02:00
Luca Weiss b8d5b9e4e5
treewide: rename _system to _rootfs in various places
A long time ago we renamed the flash_system action into flash_rootfs.
Since we still kept some variables around, it's finally time to clean
that up.

Keep backwards compatibility for now since we cannot update pmaports at
the same time since the new deviceinfo names won't be supported in older
pmbootstrap versions.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230605220329.14328-3-luca@z3ntu.xyz%3E
2023-06-12 08:46:22 +02:00
Luca Weiss dec5f00220
pmb.config: add missing flash_rk_partition* flags
We should have the variables we use in this array. Add the missing
rockchip flags there.

Fixes: 18a16c78 ("pmb: flasher: add support for rk partitions (MR 2165)")
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230605220329.14328-2-luca@z3ntu.xyz%3E
2023-06-12 08:46:22 +02:00
Luca Weiss 0bd5118dd0
flasher: set default fastboot rootfs partition to userdata
Nowadays userdata partition is way bigger than system partition and is
the preferred partition to use for the postmarketOS installation. Change
the default so "pmbootstrap flasher flash_rootfs" uses that partition by
default.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230605220329.14328-1-luca@z3ntu.xyz%3E
2023-06-12 08:46:22 +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
Oliver Smith ec370987fd
pmb.flasher: remove outdated comment
After refactoring the patch, it now directly installs the lk2nd package.

Fixes: 68231d93 ("pmb.flasher: Improve flash_lk2nd action")
2023-06-05 13:17:47 +02:00
Luca Weiss 68231d93e2
pmb.flasher: Improve flash_lk2nd action
* Check that we're not already running lk2nd as flashing boot partition
  inside lk2nd is different to flashing boot partition outside. We could
  improve this in the future to use "flash lk2nd lk2nd.img" as
  documented in the file.
* Grab the lk2nd package from the device package and install that. The
  device package is expected to have a dependency on the correct lk2nd
  package.
* Remove some log message in unusual styles for pmbootstrap.
* Group flash_lk2nd action together with the other flash actions and use
  string comparison.

See also: https://gitlab.com/postmarketOS/pmaports/-/issues/2074

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230605104026.744005-1-luca@z3ntu.xyz%3E
2023-06-05 13:12:58 +02:00
Luca Weiss d68d5fcf20
pmb.qemu.run: replace removed -soundhw option
In the QEMU 7.1 release the deprecated -soundhw option was removed.
Replace it with -audio so we can have audio working again in QEMU.

See also https://www.qemu.org/docs/master/about/removed-features.html

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230605102320.739043-1-luca@z3ntu.xyz%3E
2023-06-05 13:12:58 +02:00
Luca Weiss 1d0eb2792f
pmb.helpers.run: fix sudo timer
The recent changes to the sudo code forgot this usage here which broke
with the sudo timer config option enabled.

Fixes: d31313f7 ("Don't use 'sudo' when running as root")
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230605092217.725218-1-luca@z3ntu.xyz%3E
2023-06-05 13:12:58 +02:00
Newbyte c6a8a2614d
pmb.config.sudo: Use type union compatible with Python 3.7
The Type | OtherType syntax for writing unions was introduced in Python
3.10. We want to support Python 3.7, so use an Optional type hint
instead which declares the same thing and is supported by 3.7.

Fixes: d31313f7 ("Don't use 'sudo' when running as root")
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230605063142.6843-1-newbyte@postmarketos.org%3E
2023-06-05 13:12:52 +02:00
Newbyte 09870a46a0
pmb.helpers.frontend: Also clear testsuite log when running log -c
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230603102910.164433-1-newbyte@postmarketos.org%3E
2023-06-04 11:41:23 +02:00
Hugo Osvaldo Barrera d31313f7dc
Don't use 'sudo' when running as root
This cancels the need to install and configure `sudo` or `doas` on
single-user installations (e.g.: a VM dedicated to running pmbootstrap).

Fixes: https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2224
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230529203922.22161-1-hugo@whynothugo.nl%3E
2023-06-04 11:35:08 +02:00
Hugo Osvaldo Barrera 27618d5ffd
Use ruff for linting
Use ruff instead of flake8. Aside from being substantially faster, ruff
includes a lot of flake's plug-ins built-in, some of which may be useful
to enable as a follow-up.

Also move the relevant configuration out of the script in .ci/ and into
the project-wide settings. A side effect of this is that IDEs should
detect these settings, and ignore the same rules as CI, avoiding false
positives while developing locally.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230529203448.18656-1-hugo@whynothugo.nl%3E
2023-06-04 10:56:22 +02:00
Pablo Correa Gómez ecb7660f15
config: use en_US as default locale
In theory, the en_US locale is supposed to be aimed at people, while the
C locale is aimed as computers. In theory, one of the remarkable
differences is in sorting:

$ printf '%s\n' \| a \0 \^ \& B c C | LC_COLLATE=C.UTF-8 sort
&
0
B
C
^
a
c
|

The non-sense there is obvious, with "^" sorting in between the letters,
"|" afterwards and sorting of capitals and non-capitals split. The reason
is the ordering is based on the ascii table. In theory, an en_US locale
should be able to provide a sensitive ordering, but what takes care of it
is the libc, and musl does not have it properly implemented. So LC_COLLATE=en_US
will still give the same results. However, that's hopefully going to change
at some point, and there's no harm in setting a sensible locale by default.

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
2023-06-03 16:48:12 +02:00
Oliver Smith 0c81679677
aportgen/binutils: set pmOS bugurl
Alpine recently set the bugurl to the Alpine Linux issue tracker. When
rewriting the APKBUILD for cross compiling in postmarketOS, change it
to https://postmarketos.org/issues.

Related: fe73f3a28c
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230522065220.2841-4-ollieparanoid@postmarketos.org%3E
2023-05-25 09:45:07 +02:00
Oliver Smith 6276b2dc68
aportgen/binutils: add more makedepends_host
Adjust to Alpine's APKBUILD where jansson-dev and zstd-dev are only set
if $BOOTSTRAP is empty. The APKBUILD parser in pmbootstrap doesn't
recognize this, and therefore doesn't install the depends unless we
replace makedepends_host= outside of the condition.

Related: fe73f3a28c
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230522065220.2841-3-ollieparanoid@postmarketos.org%3E
2023-05-25 09:45:07 +02:00
Oliver Smith 84c1460e75
aportgen/binutils: order fields alphabetically
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230522065220.2841-2-ollieparanoid@postmarketos.org%3E
2023-05-25 09:45:02 +02:00
Newbyte 40fc6f4fd4
pmb: Remind users to ensure pmbootstrap is updated before reporting errors
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Co-developed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230521070148.8311-1-newbyte@postmarketos.org%3E
2023-05-25 09:24:13 +02:00
Luca Weiss 071dc99f68
pmb.flasher.frontend: Use elif instead of repeated if
Only one action can be provided through the args, so there's no point in
checking subsequent actions if a previous one has matched.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230513120625.1259793-2-luca@z3ntu.xyz%3E
2023-05-17 22:55:01 +02:00
Oliver Smith 6d0aa127d5
Prepare 1.53.0 release 2023-05-17 20:47:32 +02:00
Pablo Correa Gómez acb94beaf9
install: write new file instead of modifying locale.sh from alpine-baselayout
First of all, modifying in-place the file owned by alpine-baselayout has the
consequence of that file never being updated by APK. This is an issue changes
happen upstream. And I just fixed[1] an issue upstream that had to be with
that exact file, so make sure that from now on, we're writing to another file
that sorts before the one from alpine-baselayout. Additionally, equivalently
to the fix in [1] for bug [2], don't set the variable unconditionally, but
instead use its current value if it's already set.

[1] https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/46718
[2] https://gitlab.alpinelinux.org/alpine/aports/-/issues/14862

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Tested-by: Oliver Smith <ollieparanoid@postmarketos.org>
Co-developed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3CDB9P192MB12912380DD72F8A840694B44C7759@DB9P192MB1291.EURP192.PROD.OUTLOOK.COM%3E
2023-05-15 08:35:00 +02:00
Luca Weiss d200414d87
kconfig check: Add USB gadget check to community
Make sure that we disable legacy gadgets like USB_ETH. Our initramfs
uses configfs gadgets instead, currently RNDIS for USB networking.

In the future this can be expanded to more options like mass storage,
MIDI or whatever we're going to integrate into the OS that can be
configured by the user.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230423163438.746054-1-luca@z3ntu.xyz%3E
2023-05-02 08:38:04 +02:00
Caleb Connolly 204419fe49
build: make preferred target arch configurable
When invoking pmbootstrap build most packages default to the host arch,
however depending on your workflow it might be preferrable to default to
the device arch.

Add a new config option "build_default_device_arch" which when set will
make "pmbootstrap build" prioritise the device arch over the native
arch.

Default to False to preserve the old behaviour and don't ask during
pmbootstrap init as this may not be relevant for most folks.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Co-developed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230418-build-default-arch-v5-2-5223fab65867@postmarketos.org%3E
2023-05-01 13:19:14 +02:00
Caleb Connolly 681fcfe775
config: sort config_keys and fix layout
Adjust the layout to match the formatting of other options and sort the
array.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230418-build-default-arch-v5-1-5223fab65867@postmarketos.org%3E
2023-05-01 13:19:09 +02:00
Oliver Smith c6bcb0dacf
Speed up 'pmbootstrap checksum'
Don't install gcc, ccache, git when the user only wants to update the
checksums of a package.

Reviewed-by: Caleb Connolly <kc@postmarketos.org>
Tested-by: Caleb Connolly <kc@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230419192042.3951-3-ollieparanoid@postmarketos.org%3E
2023-04-28 09:23:43 +02:00
Oliver Smith a8ab820015
pmb.build.init: refactor init marker related code
Put it in /tmp and touch it directly from python instead of running
pmb.chroot.root. This way it's slightly faster and doesn't require root
rights. Order the imports alphabetically while at it, and remove very
obvious comments.

Reviewed-by: Caleb Connolly <kc@postmarketos.org>
Tested-by: Caleb Connolly <kc@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230419192042.3951-2-ollieparanoid@postmarketos.org%3E
2023-04-28 09:23:37 +02:00
Oliver Smith a8695833d9
Prepare 1.52.0 release 2023-04-18 21:12:54 +02:00
Caleb Connolly 53d572bc40
build: support new abuild.conf path
abuild.conf got moved to /usr/share/abuild/default.conf and
/etc/abuild.conf is now just for user-changes. Adjust
configure_abuild() to append to /etc/abuild.conf if there is no line
defining JOBS

This should be backward compatible

Signed-off-by: Caleb Connolly <kc@postmarketos.org>
Tested-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
2023-04-18 20:57:26 +02:00
Julian Winkler ad7ec1635a
envkernel.sh: building x86 on x86_64 does not require a cross compiler
Add an exception for this case to use host compiler

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230416100903.53248-1-julian.winkler1@web.de%3E
2023-04-18 09:30:18 +02:00
Oliver Smith d51f31e784
setup.py: adjust path to pmb.__version__
setup.py is on its way out, but it isn't replaced just yet. Adjust the
code that finds the version.

I'm pushing this directly to master as this fix is trivial and unbreaks
packaging current master of pmbootstrap.

Fix for (from pmbootstrap AUR package):
$ pip install build wheel
$ python -m build --wheel --no-isolation
  File "/usr/lib/python3.10/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    {"edge": "2.12.11-r0",
    ^
SyntaxError: '{' was never closed

Fixes: 6352ab9c ("Move version to pmb.__version__")
Fixes: pmbootstrap#2226
2023-04-17 08:11:51 +02:00
Oliver Smith 6352ab9c2d
Move version to pmb.__version__
Move the pmbootstrap version to __version__ in the pmb module, so it can
still be found automatically after setup.py is replaced.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230407233026.1712-4-ollieparanoid@postmarketos.org%3E
2023-04-15 01:44:37 +02:00
Oliver Smith 5d28c5ccf3
pmbootstrap.py: move all features to pmb:main()
Prepare to modernize the python packaging. pmbootstrap.py will not be
part of the packaging, so add a note there and move both features
(python version check, ^C check) to pmb/__init__.py:main().

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230407233026.1712-3-ollieparanoid@postmarketos.org%3E
2023-04-15 01:44:37 +02:00
Oliver Smith 49cd288078
pmbootstrap.py: require at least python 3.7
The minimum python version was already increased to 3.7, but it wasn't
adjusted here yet.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230407233026.1712-2-ollieparanoid@postmarketos.org%3E
2023-04-15 01:44:36 +02:00
Oliver Smith 46b708295a
pmb.config.pmaports: replace aports split msg
When running a pmbootstrap command and the pmaports dir does not exist,
it would print the following error:

  WARNING: Can't create log file in '/home/user/.local/var/pmbootstrap', path does not exist!
  [02:14:37] ERROR: We have split the aports repository from the pmbootstrap repository (#383). Please run 'pmbootstrap init' again to clone it.
  [02:14:37] See also: <https://postmarketos.org/troubleshooting>
  Run 'pmbootstrap log' for details. Alternatively you can use '--details-to-stdout' to get more output, e.g. 'pmbootstrap --details-to-stdout init'.

This is long obsolete. By now the reason for the missing pmaports dir is
not that we had moved it from pmbootstrap.git to a separate git
repository, it's most likely that the user did not run
'pmbootstrap init'. Adjust the message, and quit without link to
troubleshooting etc:

  [02:15:28] ERROR: pmaports dir not found: /home/user/.local/var/pmbootstrap/cache_git/pmaports
  [02:15:28] Did you run 'pmbootstrap init'?

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230408002810.2006-1-ollieparanoid@postmarketos.org%3E
2023-04-15 01:44:36 +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
Newbyte a747aabe33
pmb.helpers.other.validate_hostname: allow periods
According to the linked Wikipedia article, "Hostnames are composed
of a sequence of labels concatenated with dots". As such, allow
periods (dots) in our hostname validation function.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230412125112.55473-1-newbyte@postmarketos.org%3E
2023-04-15 01:44:31 +02:00
Oliver Smith 89cbae6d31
pmb.parse.kconfig.check: fix writing to list arg
Python passes all arguments by reference. For mutable objects such as
a list used here, changing the object will change the original one. If
components_list is not set, this means the default value gets modified.

This lead to kernels getting checked with the wrong required components.
For example, when checking a kernel from community first with the
default component_list, it would get extended with all options needed
for a kernel in community. When checking another kernel from the
testing category, also with the default component_list, it would now
check for the community options in the testing kernel.

Related: https://stackoverflow.com/a/986145
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230402124338.64886-1-ollieparanoid@postmarketos.org%3E
2023-04-05 08:53:05 +02:00
Oliver Smith 3113f354b8
Bump min. required Python version to 3.7
Increase it as 3.6 is EOL.

Related: https://en.wikipedia.org/wiki/History_of_Python#Table_of_versions
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230326164931.2390-2-ollieparanoid@postmarketos.org%3E
2023-04-04 09:13:09 +02:00
Oliver Smith 05675321d6
pmb.parse.arguments: don't use python 3.9 feature
Replace action=argparse.BooleanOptionalAction with action="store_true"
so it still works with Python 3.8 and 3.7. These aren't EOL yet, and
unless we have a good reason to drop support for them, we can still
support them.

The purpose of vermin ("pmbootstrap ci vermin") would be to warn about
this, filed a bug that it didn't catch it:
https://github.com/netromdk/vermin/issues/168

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230326164931.2390-1-ollieparanoid@postmarketos.org%3E
2023-04-04 09:13:09 +02:00
Luca Weiss 7125412f07
pmb.aportgen.device: fix flash method autocomplete
In order to provide tab completion to the "Flash method" question we
need to provide pmb.helpers.cli.ask with the possible options. Do that.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230403163311.927063-1-luca@z3ntu.xyz%3E
2023-04-04 09:13:04 +02:00
Oliver Smith c0b46612c0
kconfig check: ANDROID_BINDER_IPC_SELFTEST not set
Require that this option is disabled for waydroid support, as it slows
it down.

Depends: pmaports MR 3975
Fixes: issue 2222
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230324085138.2198-1-ollieparanoid@postmarketos.org%3E
2023-04-02 14:57:11 +02:00
Newbyte bdbc7b3eb3
pmb: Set PMBOOTSTRAP_CMD to argv[0] in environment
This allows for scripts run by pmbootstrap to figure out how pmbootstrap
was invoked, and with that invoke pmbootstrap even in unconventional
setups where "pmbootstrap" isn't an available command in $PATH.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230325205337.105795-1-newbyte@postmarketos.org%3E
2023-04-02 14:57:04 +02:00
Oliver Smith 06949ae870
test/test_zzz_keys.py: move from test/test_keys.py
Rename the file so it runs last, as it's currently failing a lot of
times on sourcehut. When I looked into it last time, it seemed to be
related to CDN caching and then it worked again so I didn't look further
into it at the time. Move it to the end until this is figured out
properly, so at least we see if all other tests are passing.
2023-03-24 09:14:18 +01:00
Petr Hodina 51afc91c7d
pmb.parse.kconfig: Pass background color for menuconfig
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C167921525774.11921.2504628563068466377-1@git.sr.ht%3E
2023-03-24 09:11:48 +01:00
Clayton Craft 2ec285aa1e
install/partition: set esp flag for /boot when using GPT
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Caleb Connolly <kc@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230316192838.21431-4-clayton@craftyguy.net%3E
2023-03-24 09:11:48 +01:00
Clayton Craft d957710b49
qemu/run: add support for EFI boot
This add support for EFI boot in pmb qemu, it can be enabled by
specifying the --efi option.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Caleb Connolly <kc@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230316192838.21431-3-clayton@craftyguy.net%3E
2023-03-24 09:11:48 +01:00
Clayton Craft 6c66bfb8aa
parse/arguments: add qemu --efi option
This will be used to support EFI boot in qemu

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Caleb Connolly <kc@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230316192838.21431-2-clayton@craftyguy.net%3E
2023-03-24 09:11:48 +01:00
Oliver Smith 1dfce9d342
kconfig_options_waydroid: enable PSI
Ensure that PSI support is built, and that it is not disabled by
default. That way we don't need to pass psi=1 during boot to enable it.

Related: pmaports MR 3901
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-19-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:48 +01:00
Oliver Smith 796e402ff9
kconfig_options_waydroid: update to android 11
Require BPF_SYSCALL and CGROUP_BPF.

Related: pmaports MR 3901
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-18-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:48 +01:00
Oliver Smith 63c61c1cb9
kconfig_options_waydroid: order alphabetically
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-17-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith 65ee265e84
pmb.build.kconfig: split extract_and_patch_sources
Move it into an extra function, so it can be used by
"pmbootstrap kconfig merge" code too in a future patch.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-16-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith 97e21fa876
parse.arguments.add_kernel_arg: add nargs param
Prepare for a future patch that will set it to None to make sure we get
exactly one kernel argument.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-15-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith 54266f7bfa
pmb/build/kconfig.py: rename from menuconfig.py
Prepare to add more kernel config handling code to that file, that is
not related to running menuconfig.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-14-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith 032296b7ab
test: rework kconfig check tests
Replace the old kconfig check tests with new ones, that do not rely on:
* any kernel config in pmaports
* the currently required kconfig options set in pmb/config/__init__.py

This will make it much easier to change the required options, and moves
the testsuite a bit more towards making it completely independent from
current pmaports state.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-13-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith 3b1ec76395
kconfig check: extract_arch: support riscv64
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-12-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith 905ccbb840
kconfig check: extract_version: replace - with _
Replace the dash in rc kernels with an underscore, so the resulting
version of e.g. 6.1.0-rc3 becomes a valid alpine pkgver (6.1.0_rc3).
This is needed so pmbootstrap can properly parse and compare the
version.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-11-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith f393bbdab1
kconfig check: less errors for non-detailed mode
Don't print more than one non-detailed error per component, as it
results in the same message. Adjust the description of the details
parameter to reflect this.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-10-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith dffb8614bc
kconfig check: add --no-details argument
Provide a fast way to go through the no-details mode for kconfig check,
which is otherwise only triggered after running "kconfig edit". This is
useful for development.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-9-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith 9bbb1c11fc
kconfig check: add descriptions to more functions
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-8-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith 23014ef76f
kconfig check: move check_config_options_set up
In this file and throughout most of the rest of the pmbootstrap code,
functions that get called by other functions are defined on top of them
if they are in the same file. check_config_options_set gets called by
check_config, so put it above.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-7-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith fd1b4e5d19
kconfig check: drop "necessary_"
Rename necessary_kconfig_options_* variables to kconfig_options_*. It's
clear that these are necessary to pass the check, so let's shorten them.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-6-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith a568cf4520
kconfig check: config_file -> config_path
Rename config_file to config_path for consistency with the rest of the
file. Both are used to point to the full path of the config file.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-5-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:46 +01:00
Oliver Smith 1a124ec2b6
kconfig check: remove redundant component lists
Components are the sets of kernel config options in
pmb/config/__init__.py, such as the ones for waydroid, nftables, etc.

Generate the list of components dynamically and refactor the code, so we
can add/remove components in just one place.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-4-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:46 +01:00
Oliver Smith d14dbd49de
pmb.parse.kconfig: remove config_path_pretty
Don't set the config_path_pretty variable and pass it through various
functions until it ends up being used in check_option. This was just the
directory name of the kernel config and the kernel config filename (or
in case of pmbootstrap kconfig check --file, just the same as the
config path).

Instead we can just print the filename of the kernel config, for example
"config-postmarketos-qcom-sdm845.aarch64". It is shorter and already
obvious to which package it belongs.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-3-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:46 +01:00
Oliver Smith dbe13fa812
pmb.parse.kconfig.check_option: refactor
Deduplicate the code for printing warnings and tweak it slightly:
* Shorten ".See <$url> for details." to ": $url".
* Include the component in the detailed output too.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-2-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:41 +01:00
Jami Kettunen 2f9bdb7a66
pmb.parse.arch: Include comma after last dictionary items
See https://lists.sr.ht/~postmarketos/pmbootstrap-devel/patches/39643#feedback-272128:1018-1194

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C167883228237.9452.6945199441942129608-0@git.sr.ht%3E
2023-03-16 08:58:34 +01:00
Jami Kettunen 0230f4def2
pmb.config.apkbuild_attributes: Add _depends_dev
Fixes building of linux-edge (from "pmbootstrap aportgen --fork-alpine
linux-edge")

  ERROR: Package '$_depends_dev': Could not find aport, and could not find this package in any APKINDEX!

See also: https://gitlab.alpinelinux.org/alpine/aports/-/issues/14250

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Tested-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C167858994438.8366.14589100885556224988-0@git.sr.ht%3E
2023-03-12 17:21:02 +01:00
Jami Kettunen 7186673d59
pmb/parse/arch.py: add riscv64 -> riscv to kernel carch mapping
This fixes both the default riscv64 kernel APKBUILD "_carch" selection and
"pmbootstrap kconfig edit" functionality even after manually corrected
"_carch" variable.

  (native) make menuconfig
  ../Makefile:609: ../arch/riscv64/Makefile: No such file or directory

See also https://github.com/torvalds/linux/tree/master/arch with search
for "riscv"

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C167858205621.22796.14648808830656459528-0@git.sr.ht%3E
2023-03-12 17:21:02 +01:00
Jami Kettunen 90ae7f3a79
pmb.aportgen.linux: Depend on findutils
Without this on newer kernels the following is emitted during kernel
build (though it still appears to build a package fine):

  find: unrecognized: -printf
  BusyBox v1.36.0 (2023-03-03 16:36:18 UTC) multi-call binary.
  ...

See also: https://gitlab.com/postmarketOS/pmaports/-/issues/910

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C167855488981.11771.14125941910883500913-0@git.sr.ht%3E
2023-03-12 17:20:55 +01:00
Oliver Smith 60901ac462
pmb.helpers.run: don't pass stdin to output=stdout
When looking at the table for possible output modes, it only makes sense
to pass stdin to "interactive" and "tui". The output mode "stdout" is
for non-interactive commands.

This fixes apk going interactive (asking for confirmation) when running
pmbootstrap with --details-to-stdout and building a package that depends
on postmarketos-base.

Fixes: issue 2208
Tested-by: Clayton Craft <clayton@craftyguy.net>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230301204112.4351-1-ollieparanoid@postmarketos.org%3E
2023-03-02 08:10:34 +01:00
Oliver Smith a26e203f53
partition_cgpt: use pmb.chroot.apk.install
Be consistent with the rest of the pmbootstrap codebase and install
packages through this function.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230301204311.4456-1-ollieparanoid@postmarketos.org%3E
2023-03-02 08:10:29 +01:00
Pablo Correa Gómez bf820f442d
install: make cached remote repositories available on first install
This allows the usage of APK (and apk-polkit-rs) on first boot without
the need to establish an internet connection.

Closes https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2206

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Tested-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3CPAXP192MB1293A82207F0983ED6C8665EC7AE9@PAXP192MB1293.EURP192.PROD.OUTLOOK.COM%3E
2023-02-27 08:35:20 +01:00
Pablo Correa Gómez 014509b427
install: run alpine-appstream-downloader if available
This makes sure that the AppStream data is available on the built
image. To avoid unnecessary downloads on multiple invocations of
install, create a new cache chroot.

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Tested-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3CPAXP192MB12938C6B570CA56AA162E8A6C7AE9@PAXP192MB1293.EURP192.PROD.OUTLOOK.COM%3E
2023-02-27 08:35:20 +01:00
Oliver Smith f296dc62e5
ci/pytest.sh: check if pmaports dir is clean
Verify that the pmaports dir is clean before starting the testsuite, as
some tests will fail if it is not. It's annoying when this is the reason
that you have to restart the testsuite run after it already spent some
time, so rather check for it beforehand.

Ideally the testsuite wouldn't depend on the state of pmaports, see
issue 2105 for that.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230226184731.6989-1-ollieparanoid@postmarketos.org%3E
2023-02-27 08:35:20 +01:00
Oliver Smith f208bba4f2
qemu: warn that network won't work with ui=none
The other day I spent way too long trying to find a regression that
caused network inside qemu not to work anymore, before I realized it was
caused by selecting UI=none instead of anything else.

Print a warning and link to a wiki page describing this in more detail.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230226184546.6869-1-ollieparanoid@postmarketos.org%3E
2023-02-27 08:35:14 +01:00
Newbyte 162867a08c
config: Add BINFMT_ELF and BINFMT_SCRIPT
pmOS cannot boot without these two. There was recently someone in the
unofficial postmarketOS Telegram group who used some minimal config and
couldn't figure out why the initramfs couldn't start up, and these
options being disabled turned out to be the culprit. As such, let's
ensure these are enabled to make life easier for people setting up new
kernel configurations.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Tested-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230128203716.152281-1-newbyte@postmarketos.org%3E
2023-02-26 19:42:05 +01:00
Oliver Smith a0cea6255a
pmb.config: mount go caching directories
Always set GOCACHE during build and let it point to pmbootstrap's work
dir. This has a similar effect as using ccache for C/C++.

Set GOMODCACHE conditionally: this is for caching the go modules (git
repositories) that get cloned during a build if they are not bundled
with the source. Usually APKBUILDs should cache them, but when using
pmbootstrap build --src, they would get downloaded over and over again.
Set GOMODCACHE automatically for --src and allow enabling/disabling this
manually with new --go-mod-cache / --no-go-mod-cache.

This speeds up multiple iterations of building the same package
significantly. I'm using it for:

$ pmbootstrap build postmarketos-mkinitfs --src=...

I've verified that using the same GOCACHE dir for multiple architectures
doesn't result in build artifacts for the wrong arch getting used.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230223064743.1773-1-ollieparanoid@postmarketos.org%3E
2023-02-26 19:37:30 +01:00
Oliver Smith 3ad159f98d
Prepare 1.51.0 release 2023-02-19 16:13:52 +01: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 e8a2ab2e98
check_binfmt_misc: print more helpful error
Instead of letting the mount -t binfmt_misc … command fail, and simply
telling the user that the command failed: rely on the following check
that prints a better error message on error. If it fails at this point,
the kernel option isn't enabled. Add two comments explaining why
check=False is used in this function while at it.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230123064516.1607-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
Oliver Smith faccbdc2eb
qemu: ssh hostfwd on 127.0.0.1 instead of 0.0.0.0
Make it accessible over localhost only. The idea is that users can login
into the VM on their own PC while developing, not that it's exposed over
the network. If somebody needs to have hostfwd on another IP, send a
patch to make this configurable via argparse.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221221220305.1809-1-ollieparanoid@postmarketos.org%3E
2023-01-20 15:28:07 +01:00
Clayton Craft 917ff92f63
pmb.qemu.run: fix 3d accel on amd64
Recent changes to qemu and Alpine packaging now require using the
virtio-vga-gl device and installing -gl packages to get virglrenderer
support.

Without this, wlroots fails to get an EGL context (among other problems
you'd expect by not having a useful GPU around...)

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Tested-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221210185021.3546-1-clayton@craftyguy.net%3E
2023-01-20 15:28:07 +01:00
Jane Rachinger 42feaf0d49
pmb.build.other: do not copy leftover abuild dirs
Running abuild on the host directly creates directories in the
aport where it gets built. Interrupting abuild results in those
working-dirs not getting deleted.
We don't want to copy those entries to our builder.

It's only really noticeable if pmbootstrap tries to copy a broken
symlink in src/ and thus fails.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221207205201.22139-1-jane400@bingo-ev.de%3E
2023-01-20 15:28:02 +01:00
Oliver Smith 9d93d34b65
Prepare 1.50.1 release 2022-12-05 08:19:27 +01:00
Weijia Wang a56838fb45
pmb/parse/arch.py: add arm64 -> aarch64 to mapping
This allows pmbootstrap to work on aarch64-darwin systems.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C167000939722.18650.8735853729695007724-0@git.sr.ht%3E
2022-12-05 08:19:27 +01:00
Oliver Smith bb5399d6d5
pmb.config.apk_tools_min_version: add alpine 3.17 2022-11-27 19:10:05 +01:00
Sicelo 4b339763db
pmb.parse.kconfig: update version for MEMCG_SWAP change
Without the `_rc1` tag, building kernel results in
"linux-nokia-n900/config-nokia-n900.armv7: CONFIG_MEMCG_SWAP should be set. See
<https://wiki.postmarketos.org/wiki/kconfig#CONFIG_MEMCG_SWAP> for details"
message.

See also https://gitlab.com/postmarketOS/pmbootstrap/-/merge_requests/2220#note_1146219177

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
2022-11-22 07:43:35 +01:00
Oliver Smith 757d2a0bff
Prepare 1.50.0 release 2022-11-20 16:43:03 +01:00
Oliver Smith aeeeb826fb
CI: fix typo in pmOS CI url 2022-11-20 16:38:59 +01:00
Oliver Smith 147b3ce4b9
pmb ci: fix typo in URL
Fix a typo in the URL https://postmarketos.org/pmb-ci that is being used
to detect if a script is compatible with 'pmbootstrap ci' or not.
2022-11-20 16:38:37 +01:00
Luca Weiss 0f6c6238f9
pmb.qemu.run: stop forcing bios for riscv64
We decided now not to force the bios firmware being used for riscv64 but
instead just use the one built into QEMU.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221118203424.106861-1-luca@z3ntu.xyz%3E
2022-11-20 15:35:11 +01:00
Oliver Smith 315621d5b8
pmb ci: add --fast argument
Make it easy to only run the fast tests.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221111072354.3431-3-ollieparanoid@postmarketos.org%3E
2022-11-20 15:35:11 +01:00
Oliver Smith 3fd22104a8
pmb ci: error on using --all with script names
You can either say you want all scripts, or give a list of script names,
not both. Add it this way and not with an add_mutually_exclusive_group,
as I'll add a add_mutually_exclusive_group in the next patch to only
specify --all or --fast, but having --fast with script names is fine.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221111072354.3431-2-ollieparanoid@postmarketos.org%3E
2022-11-20 15:35:11 +01:00
Oliver Smith 9a84ad20b1
pmb ci: fix arg desc for --all
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221111072354.3431-1-ollieparanoid@postmarketos.org%3E
2022-11-20 15:35:05 +01:00
vaino ed7b0273f5
flasher: heimdall: take depends from pmaports.cfg
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Co-developed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221114115705.1107886-1-vaino@vke.fi%3E
2022-11-16 09:01:32 +01:00
Caleb Connolly ab0aa7f956
pmb: sideload: wait for apk database lock
When installing the APK wait for a while for the APK database lock,
services like apk-polkit-server sometimes hog it for a while but there's
no point bailing out immediately.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221111212251.1360612-1-kc@postmarketos.org%3E
2022-11-12 14:28:41 +01:00
Luca Weiss 4a6c5657d5
pmb.parse.kconfig: don't enforce non-core checks for testing devices
Currently when any device does not conform to the options they declare,
we fail the whole kconfig check.

Now that we start requiring more options, especially with
pmb:kconfigcheck-community it makes sense to relax these restrictions so
we're more free to edit kconfig options and don't have to adjust all
testing devices that may or may not be properly maintained.

As a side effect this patch makes it practically impossible to make
kconfig check actually fail for any testing device which might not be
optimal. If these use cases appear in the future we will want to adjust
pmbootstrap to allow for that.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221105074432.13804-2-luca@z3ntu.xyz%3E
2022-11-12 14:28:41 +01:00
Luca Weiss 381a1ca907
pmb.parse.kconfig: add wireguard, filesystems & more to community check
Add wireguard options, supported file systems and some extra options to
the community kconfig check.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221105074432.13804-1-luca@z3ntu.xyz%3E
2022-11-12 14:28:40 +01:00
Oliver Smith 6f45a5d5fb
Prepare 1.49.0 release 2022-11-09 09:19:33 +01:00
Oliver Smith 30055c14d2
flasher: fastboot: take depends from pmaports.cfg
Adjust to avbtool now being part of android-tools in alpine edge.
Instead of trying to install both (which fails on edge), take the
dependencies from a new pmaports.cfg variable
supported_fastboot_depends, which only contains android-tools in
pmaports.git master branch.

Related: https://postmarketos.org/pmaports.cfg
2022-11-09 09:19:33 +01:00
Oliver Smith b64641bb1c
pmb.flasher.init.install_depends: new function
Move logic to install depends into one shared function.
2022-11-09 09:19:32 +01:00
Oliver Smith 04f8f59208
pmb.config.required_programs: add tar
Add tar as it is required for 'pmbootstrap ci' to get the source into
the pmbootstrap chroot.

Reviewed-by: Caleb Connolly <kc@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221031111614.1377-2-ollieparanoid@postmarketos.org%3E
2022-11-09 09:19:32 +01:00
Oliver Smith f8d186e776
pmbootstrap ci: fix error with deleted files
Check if each file listed by the two git ls-files commands still exists,
and only add the existing ones to the tarball. Otherwise it would crash
when a file has been deleted without having the change commited yet.

Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221031111614.1377-1-ollieparanoid@postmarketos.org%3E
2022-11-09 09:19:26 +01:00
Newbyte 397225667f
helpers/envkernel.sh: rename yaml-lint to yamllint
There's no package called yaml-lint in Alpine. Presumably, the intent
was to install yamllint here.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221105132937.34008-1-newbie13xd@gmail.com%3E
2022-11-05 17:55:21 +00:00
Oliver Smith e8b0b4ba78
aportgen: don't fail if binary ver < APKBUILD ver
The typical workflow for upgrading cross/gcc-* is:

$ cd pmaports/cross
$ pmbootstrap aportgen gcc-*

Currently this is failing because the APKBUILD has been updated in
Alpine for gcc, but gcc has not been built for all arches yet. This
shouldn't prevent us from generating the proper updated APKBUILDs in
pmaports so just print a note and don't fail here.

I'm committing this directly to master as this currently breaks
test/test_aportgen.py::test_aportgen.
2022-11-02 21:09:28 +01:00
Dzmitry Sankouski 6a21898ce4
envkernel: add dependencies for running 'make dtbs_check'
Mainline device-tree patches development require linting.
Install needed packages to be able to perform dtbs_check task.

Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com>
Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221102160913.1896756-1-dsankouski@gmail.com%3E
2022-11-02 21:09:27 +01:00
Oliver Smith 57359bfd51
CI: flake8: remove ignore for W605
This was for 'invalid escape sequence' (even though the comment has W604
instead of W605). After removing it, flake8 runs through fine. We
probably fixed whatever invalid escape squence we had earlier while
doing f-string related refactoring.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221028074119.3309-1-ollieparanoid@postmarketos.org%3E
2022-11-02 21:09:27 +01:00
Luca Weiss 4771fbac65
pmb.qemu.run: support riscv64
We're using the standard virt machine, adding virtio-gpu-pci for
graphics and are using the bios firmware that is installed from the
device package, instead of the one built-in to QEMU.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221029114536.100268-2-luca@z3ntu.xyz%3E
2022-11-02 21:09:27 +01:00
Luca Weiss 0624a1ae33
pmb.qemu.run: replace -nic option with -netdev and -device
On qemu-system-riscv64 the -nic option doesn't seem to work correctly.

  qemu-system-riscv64: warning: requested NIC (anonymous, model virtio-net-pci) was not created (not supported by this machine?)

Using -netdev and -device provides the same functionality and also works
on riscv64.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221029114536.100268-1-luca@z3ntu.xyz%3E
2022-11-02 21:09:27 +01:00
Oliver Smith 38f850161c
b4-config: linkmask: encode < and > chars
Encode < as %3C and > as %3E in the linkmask. This gets used in the
"Link: ..." line written to commit messages. Reasoning is that at least
gnome-terminal will break the link at the < otherwise, making it harder
to right click and copy the link to paste it into another VM to open it
in a browser. That's how everybody does it, right?

Use %% instead of % for proper escaping with python's %-formatting.
2022-11-02 21:09:22 +01:00
Oliver Smith 094bf38abb
b4-config: new file
Add a config, so the 'b4' tool from kernel tools can be used to get
Reviewed-By: etc. trailers into the commit messages. The tool only
supports lore.kernel.org, however I've written a proof of concept for
using this with SourceHut mailing lists too. See the wiki page for
details: https://postmarketos.org/patch-review
2022-11-01 15:14:31 +01:00
Martijn Braam 5042a947e5
README: Document git commands for setting the git-send-email defaults
It's possible to set the default To: address and subject prefix in the
git config of the local checkout. This makes the workflow a bit easier
and makes sure the subject starts with [PATCH pmbootstrap] instead of
the regular [PATCH].
2022-10-29 15:36:20 +01:00
Oliver Smith c1e4790947
build.yml: add missing sources line
Add the sources line, so CI should work for patches submitted to the
mailing list.
2022-10-28 09:06:18 +02:00
Oliver Smith 1ef933e3be
README: add ML subscribe link 2022-10-26 00:36:34 +02:00
Alexander Martinz 89c2ff0926
pmb.parse.kconfig: explicitly add dependency on SWAP
Commit d8f2f20186 removed
the requirement of selecting MEMCG_SWAP for Kernels >= 6.1.

However, it did not fully account for the behavior change,
as MEMCG_SWAP depends on both MEMCG and SWAP.

Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
2022-10-25 23:18:47 +02:00
Oliver Smith 3bee7222d8
README: add link to issues 2022-10-25 22:49:23 +02:00
Oliver Smith d61afe99eb
README: add new line
Just a detail, but given that the rest of this section is organized like
title: (new line) information, it looks more consistent.
2022-10-25 22:45:35 +02:00
Oliver Smith 1df2160129
README: update development section
* Mention that upstream is on SourceHut now
* Move it to the top, so people see this immediatelly
* Modernize instructions for running CI
2022-10-25 22:30:29 +02:00
Oliver Smith 39d75445b5
README: add line breaks
Get rid of very long lines, break them at 80 characters except if there
is a link or command-line output that is longer.
2022-10-25 22:30:29 +02:00
Oliver Smith 7914c11d1c
README: remove outdated information
* Links in the top row point to some very old blog posts and to the
  devices wiki page. Remove them, the first line has a link to
  postmarketos.org where the user should be able to get all relevant
  information about postmarketOS if they don't know this project.

* "Package build scripts live in the pmaports repository now.", this
  was useful shortly after we made the change, but it has been like this
  for years now. Again, the postmarketOS homepage lists where other
  related source code is, in case the user doesn't know.

* 2 GB of RAM recommened for compiling: this was a rule of thumb for
  when all postmarketOS packages had to be compiled from source. This is
  not the case anymore, we have a binary repository. Depending on which
  package you want to compile, you don't need as much RAM. And some
  users who just want to run 'pmbootstrap install' don't need to build
  anything at all. I think this is more confusing than helpful, so
  remove it.

* Kernels based on grsec patchset are not supported. I don't think
  anyone will try this, this was more relevant when the patchset was
  still distributed freely and you could actually use it in Alpine
  Linux (by default even?) and Arch Linux. An artefact of the past.
2022-10-25 22:30:28 +02:00
Oliver Smith 81f0d669c8
CI: add note about running scripts locally 2022-10-25 20:31:19 +02:00
Oliver Smith 0bcd58765c
pmbootstrap ci: new command
Add a new command that makes running CI scripts easy. The user goes to
the git repository of choice, which has CI scripts written in a certain
format, and then runs 'pmbootstrap ci' to get an interactive selection
of which of the available scripts to run (or "all"). Specifying one or
multiple scripts on the command-line is also possible, e.g.

$ pmbootstrap ci flake8
$ pmbootstrap ci shellcheck flake8 pytest
$ pmbootstrap ci --all

pmbootstrap then either runs the selected scripts in a chroot (and
installs dependencies as defined at the beginning of the CI scripts), or
natively (with checks inside the scripts for having dependencies
installed). Running natively is needed for .ci/pytest.sh in this
pmbootstrap.git repository, as pmbootstrap can't run inside pmbootstrap.
Running natively or in chroot is defined in an "# Options: " comment
inside the script file.

Documentation for this command and how script files look like:
https://postmarketos.org/pmb-ci
2022-10-25 20:31:19 +02:00
Oliver Smith 6ac39d17e7
pmb/helpers/frontend: order imports alphabetically 2022-10-25 20:31:19 +02:00
Oliver Smith 4b8a0db5bc
CI: replace gitlab CI with sourcehut CI
Replace .gitlab-ci.yml with a minimal .build.yml that runs a script in
the .ci dir for each task. Each of these scripts runs as root first,
installs dependencies, and then drops rights to the testuser and runs
the actual test. I went with this design, so we can add a
'pmbootstrap ci' command in following patches that run these in a
pmbootstrap chroot (see pmaports#2169).

Looking at flake8, we currently ignore W504 and W604. Would be nice to
fix these instead, but let's do that in another patch.

I've added a minver package to Alpine, so we don't need to install it
form pip anymore. Use minver's new --lint argument to simplify the
script, and as recommended by minver itself, use --no-parse-comments as
speed optimization since we don't have minver specific comments.

Using doas instead of sudo in build.yml would be nice, but this doesn't
work out of the box. Can be changed in the future.

Add a note to the pytest script, that 'pmbootstrap log' can be used to
follow the log while tests are running.
2022-10-25 20:31:19 +02:00
Oliver Smith 4428c7bcdc
pmbootstrap log: show testsuite log too
When running the testsuite, most logging gets written to a separate
log_testsuite.txt file. Check if it exists, and if so, instruct tail to
print its output as well. This allows immediatelly figuring out what the
testsuite is doing without manually attaching to log_testsuite.txt
(which I often did while running the testsuite).
2022-10-25 20:31:14 +02:00
Newbyte 8770aba287
helpers/envkernel.sh: return 0 from fish_compat if --fish is not present (MR 2221)
Right now this returns 1 when envkernel.sh is sourced for some reason. I
don't understand why exactly, but this seems like a sensible solution to
me.

Closes https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2133
2022-10-25 08:50:06 +02:00
Alexander Martinz 2ca4518799
pmb.parse.kconfig: drop remaining "_rc1" references (MR 2220)
As discussed at: https://gitlab.com/postmarketOS/pmbootstrap/-/merge_requests/2220#note_1146631834

Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
2022-10-24 17:36:34 +02:00
Alexander Martinz d8f2f20186
pmb.parse.kconfig: fix container check for kernels >= 6.1 (MR 2220)
Kernel 6.1 dropped CONFIG_MEMCG_SWAP[1].

[1] - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e55b9f96860f6c6026cff97966a740576285e07b

Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
2022-10-24 11:14:47 +02:00
Minecrell 3b5492d91e
pmb: build: envkernel: Fix bind mount detection (MR 2217)
At the moment the "envkernel.sh hasn't run, assuming the kernel was
cross compiled on host and using current dir as source" code path
triggers even when using envkernel.sh, which works somewhat but
requires sourcing envkernel.sh again after each invocation of
"pmbootstrap build --envkernel ...".

The reason is that os.path.ismount() does not work for bind mounts
(see https://bugs.python.org/issue29707). There is a workaround for
that already in pmbootstrap but it is not used here for some reason.
2022-10-20 11:41:27 +02:00
Luca Weiss dfada2a522
pmb: enable riscv64 architecture (MR 2215)
Enable pmbootstrap to work on riscv64 packages, and at the same time
also expand the alpine_to_hostspec list to match upstream (adding
riscv32 and loongarch*).
2022-10-19 09:11:54 +02:00
Luca Weiss 61ce6069ed
pmb.config: add missing pmb:kconfigcheck-* for lint (MR 2214)
While introducing multiple pmb:kconfigcheck-* APKBUILD options we missed
adding them to this array leading to potential apkbuild-lint failures.

This hasn't been noticed much because the check in apkbuild-lint is
relatively buggy, see https://gitlab.alpinelinux.org/Leo/atools/-/issues/48
2022-10-18 21:10:56 +02:00
Caleb Connolly 66706f896d
pmb.parse.build: mention host compiled kernels in envkenel help (MR 2175) 2022-10-18 20:08:41 +02:00
Caleb Connolly 6502d8aa28
build: envkernel: support packaging kernels that were built on the host (MR 2175)
Add support for packaging a kernel that was compiled outside of
envkernel. The envkernel.sh wrapper is great for someone new to kernel
development, but it makes it difficult to do things like "make
dt_binding_check". This lets you avoid the wrapper and build on your
host machine but still use pmbootstrap to package your kernel for easier
testing.
2022-10-18 20:08:36 +02:00
Oliver Smith d2c39ce5d8
Prepare 1.48.0 release 2022-10-16 18:22:31 +02:00
Oliver Smith f41659d4ae
pmb.build._package: update isl workaround (MR 2213)
The plan was to drop this workaround, once alpine releases a new gcc
version, and we regenerate our cross compilers against that version
_and_ drop options="!tracedeps", as latest pmbootstrap aportgen would
do. However !tracedeps wasn't dropped in the latest upgrade. This was
too easy to miss, I'll add a comment to the gcc-cross APKBUILDs so we
see it next time. Let's just update the workaround for this version.
2022-10-16 18:02:26 +02:00
Oliver Smith 35784a5fd7
pmb.aportgen.device: no depend on mesa-dri-gallium (MR 2210)
Device packages shouldn't depend on it anymore, in order to end up with
a smaller installation for ui=none this package only gets pulled in by
postmarketos-base if mesa is installed.

Related: pmaports MR 3478
2022-10-12 08:24:53 +02:00
Oliver Smith 248fe447bd
pmb.chroot.root: set PYTHONUNBUFFERED=1 (MR 2209)
Set the env var, so python programs running inside pmbootstrap chroot
don't buffer their output and only end up printing everything when they
are done. I've seen this with meson. This is bad for usability because
we don't see output, but also a problem because pmbootstrap kills
commands if they don't print any output for some time (default: 15 min).
2022-10-07 09:02:53 +02:00
Oliver Smith 40679f7126
pmb.chroot.root: order env vars alphabetically (MR 2209) 2022-10-07 09:02:53 +02:00
Oliver Smith aaeff96d23
Prepare 1.47.1 release 2022-10-06 07:59:42 +02:00
Oliver Smith 54268b72e1
pmb.build.package: add workaround for missing isl
Install isl25 for the specific gcc versions we currently have in
pmaports master that are missing it; this is easier than building new
packages and going out of sync with Alpine's versioning. This can be
reverted as soon as there is a newer gcc.

Related: pmaports issue 1732
2022-10-05 20:44:36 +02:00
Oliver Smith 550b9b3466
pmb.aportgen.gcc: remove !tracedeps option
abuild traces shared library dependencies for binaries in built
packages, and adds all of them to depends. This is needed for the cross
gcc builds, as otherwise it will not add the isl dependency (currently
isl25).

With the crossdirect compilation method we mount the cross-gcc from the
native chroot in the foreign arch chroot. Due to the missing dependency,
isl was not installed in the native chroot, and so when attempting to
use that native cross gcc from the foreign arch chroot, it would try to
load the foreign arch isl instead of the native one. Resulting in lots
of the following errors (and of course not a working gcc):

  Error relocating /usr/lib/libisl.so.23: unsupported relocation type 1026

I had probably added '!tracedeps' because abuild complains about it
otherwise... but as noted in [1] these complaints are safe to ignore.

Keep !strip for now even though it's not in Alpine's APKBUILD. I've
tried to build without and the build fails with:
  strip: Unable to recognise the format of the input file `./usr/aarch64-alpine-linux-musl/lib/libgcc_s.so.1'

[1]: 0415ebf6f9
Related: pmaports issue 1732
2022-10-05 20:44:31 +02:00
Oliver Smith dac8b27738
Prepare 1.47.0 release 2022-10-04 09:00:44 +02:00
David Wronek 8385e8db8f
testdata/gcc: upgrade to 12.2.1_git20220924-r1 (MR 2208) 2022-09-30 22:05:15 +02:00
David Wronek b9e7a98c07
pmb.config.apkbuild_attributes: Add _pkgbase and _pkgsnap (MR 2208)
Parse _pkgbase and _pkgsnap variables in pkgver for gcc.
2022-09-30 22:04:16 +02:00
Oliver Smith b262609199
pmb.aportgen.gcc: add subpkg libstdc++-dev-$arch
Add the subpackage, because g++-$arch depends on it since
12.1.1_git20220630-r6. This fix was already applied to pmaports, thanks
to ungeskriptet! Adjust the aportgen code to make sure this is added in
the future as well.

Related: pmaports MR 3464
Related: f1044b1dae
2022-09-30 22:02:31 +02:00
Oliver Smith 22e0f64095
pmb.aportgen.gcc: set libgcc=false (MR 2203)
Do not build the foreign arch libgcc. We are using the one provided by
Alpine's binary repository instead, and when building it here and trying
to use it, we actually run into a conflict.

I tried setting BOOTSTRAP="nolibc" first since there is already logic to
then disable libgcc in the APKBUILD. But that also disables g++ which we
do want to build, so we can't use this.

Fixes: issue 2168
2022-09-13 23:42:15 -07:00
Oliver Smith 4c7d2459f5
pmb.aportgen.gcc: remove isl from depends (MR 2203)
Remove it from depends, as the package has been removed in Alpine and
since quite some time we shouldn't have depended on it anyway.

Related: issue 2167
2022-09-13 23:42:15 -07:00
Oliver Smith b9ab935e42
testdata/gcc: upgrade to 12.1.1_git20220630-r5 (MR 2203)
Upgrade to current gcc APKBUILD in Alpine edge, as the old one doesn't
have the _libgcc variable I'm about to set in a future patch.
2022-09-13 23:42:15 -07:00
Luca Weiss d20fc49170
test_kconfig_check: modify nokia-n900 test (MR 2204)
We'll be enabling the kernel options for waydroid which would break this
test. Change it to UEFI check instead which will probably really never
be used on N900.
2022-09-13 09:30:23 +02:00
Luca Weiss f7fb1fe078
pmb.parse.kconfig: rename anbox check to waydroid (MR 2204)
Change the naming to fit what software is actually used in postmarketOS.
2022-09-13 09:30:23 +02:00
Luca Weiss e468fc518e
pmb.parse.kconfig: add 'community' option (MR 2204)
Add the new option that will be mandatory for all devices in
community/main category. This is just a combination of anbox + iwd +
nftables + containers + zram + netboot.

While the existing options could be removed we're keeping it for now
given that also some devices with downstream kernel might find some
options useful.
2022-09-13 09:30:23 +02:00
Luca Weiss 1fee644dce
pmb.parse.kconfig: fix containers check for x86 (MR 2204)
Options in this list are not supposed to have CONFIG_ prefix, remove it.
2022-09-13 09:30:18 +02:00
Oliver Smith 0c18c664aa
pmb.config.apkbuild_package_attributes: + triggers (MR 2202)
Do not only parse triggers, but also emit them in the packages dicts in
pmb.parse.apkbuild. This is the first half to fix pmaports issue 1690,
the other is in pmaports MR 3386.
2022-09-11 13:49:24 +02:00
Song Fuchang d650ed4a14
pmb.chroot.root: preserve proxy environment variables (MR 2201)
This fixes #457.
2022-09-08 18:11:54 +08:00
Luca Weiss 52530caaf8
pmb.parse.kconfig: remove apparmor check (MR 2200)
Remove the check as apparmor is not the way we want to go for privilege
separation anymore.
See https://gitlab.com/postmarketOS/pmaports/-/issues/1596
2022-09-04 19:10:48 +02:00
Oliver Smith 0132af72b5
test/testdata/aportgen: upgrade binutils to 2.39 (MR 2199) 2022-08-24 08:38:54 +02:00
Oliver Smith b41e4a418f
aportgen binutils: modernize (MR 2199)
Set CTARGET and CTARGET_ARCH on top of the generated APKBUILD and use
the existing code in the APKBUILD for build(), package(), makedepends,
subpackages. This is now possible, because the pmbootstrap parser for
APKBUILDs has been improved a lot since this was originally written and
because the Alpine APKBUILD does everything that was hacked in here,
like removing man, info directories and bfd-plugins if doing a cross
build.

This is now very similar to bootstrapping binutils for another
architecture via scripts/bootstrap.sh in aports.git.

Most importantly this sets --disable-gprofng, which fails to build
against musl and is the reason why our cross/binutils-* packages
generated from binutils 2.39.x didn't build anymore.

Related: https://git.alpinelinux.org/aports/tree/main/binutils/APKBUILD
Related: https://sourceware.org/bugzilla/show_bug.cgi?id=29477
2022-08-24 08:38:49 +02:00
Raymond Hackley e5d580e98a
pmb: sideload: Handle ssh_install_apks() errors (MR 2195)
Even add_cmd has exited with code 99, it will be overwritten by clean_cmd
later. Exit with code returned by add_cmd to raise a runtime error when
an error occurs.
2022-08-22 09:45:30 +02:00
Salvatore Stella 3567b7c123
Fix wrong output of pmbootstrap bootimg_analyze (MR 2198) 2022-08-21 14:25:11 +02:00
Oliver Smith 21b86f7f64
pmb.helpers.run: only pass stdin where useful (MR 2197)
Don't pass stdin to commands that aren't supposed to be used
interactively (output: log, background, pipe).

This fixes an inconsistency between building packages in CI on gitlab
and building them via bpo on sourcehut or locally. In gitlab, apparently
there is no stdin for the entire build job and so unanswered kernel
config prompts will just use the default. In local builds and on
sourcehut stdin is available and so it just hangs at the prompt until
pmbootstrap kills the build job due to no output being written.

I considered adding an additional check to pmaports to ensure that there
are no unanswered kernel config prompts just in case users run abuild
manually on the kernel APKBUILD with stdin available. But I think
forcing the users to answer all the prompts even if it's not really
needed just creates additional work / makes the workflow worse without
real benefit.

Related: https://builds.sr.ht/~postmarketos/job/824373#task-pmbootstrap_build-432
Fixes: pmaports issue 1225
2022-08-19 10:40:25 +02:00
Oliver Smith c88a18d3f6
treewide: fix various lint errors (MR 2197)
Fix errors found by new flake8 version
2022-08-19 10:40:25 +02:00
Oliver Smith 8d736c5fcc
Prepare 1.46.0 release 2022-08-15 19:32:12 +02:00
Newbyte b9485902cf
pmb.qemu.run: drop removed depedency (MR 2196)
mesa-dri-gallium provides all available drivers in Mesa nowadays.

Closes https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2157
2022-08-11 21:17:20 -04:00
Jami Kettunen bd4a7d5d3f
test: Add boot.img header v2 testcase (MR 2194) 2022-07-18 14:49:42 -07:00
Jami Kettunen 5b3cd7a7a6
pmb.aportgen.linux: Install DTBs on header v2 (MR 2194)
A single DTB is required for "mkbootimg --dtb ..."
2022-07-18 14:49:38 -07:00
Jami Kettunen de890c83e7
pmb.aportgen.device: Generate appropriate header v2 deviceinfo (MR 2194)
Here's an example of the properties this could generate:

  deviceinfo_header_version="2"
  deviceinfo_append_dtb="false"
  deviceinfo_flash_offset_dtb="0x0bc08000"
2022-07-18 14:49:33 -07:00
Jami Kettunen 255e69be5e
pmb.parse.bootimg: Add preliminary support for header v2 (MR 2194)
This includes setting header_version="2" as well as dtb_offset
according to the input boot.img when header v2 is detected.

Also adds the following previously missed deviceinfo_attributes:

* "header_version"
* "bootimg_custom_args"

And fixes failing tests now that header_version is always parsed from
boot.img files.
2022-07-18 14:49:16 -07:00
alikates c36e4a43ac
Revert "helpers/envkernel.sh: add gawk when initialising chroot (MR 2186)" (MR 2188)
This reverts commit 22117de4bd.

Closes: #2145

As of linux 5.19-rc2 and linux-next-20220614 this is not needed because
the script was fixed with [1].

[1]: https://lore.kernel.org/all/20220609204220.12112-1-atafalla@dnyon.com/
2022-07-16 11:53:29 +02:00
Newbyte fe28a39f79
helpers/envkernel.sh: disable ccache (MR 2189)
Not extensively tested, but this shouldn't be necessary given that
you get incremental builds with envkernel and may reduce build
times.
2022-07-16 11:37:46 +02:00
Oliver Smith e527a159ad
Prepare 1.45.0 release 2022-07-03 17:51:32 +02: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
Shinjo Park 87f7520e51
pmb/export: Fix Odin export filenames (MR 2191)
Since pmaports@50ee94d8 the kernel filename won't contain the flavor
information, but this is not correctly synchronized with the Odin
export. This fixes Odin export.
2022-06-23 17:45:47 +02:00
Jami Kettunen c0cec06df8
pmb/config: vndbinder ANDROID_BINDER_DEVICE is required for Waydroid (MR 2190)
Fixes 'ERROR: Binder node "vndbinder" for waydroid not found' during
'waydroid init'.
2022-06-15 20:26:05 +03:00
Newbyte 22117de4bd
helpers/envkernel.sh: add gawk when initialising chroot (MR 2186)
The Awk implementation from BusyBox cannot run the
arch/arm64/tools/gen-sysreg.awk script, and results in the
following error:

  GEN     arch/arm64/include/generated/asm/sysreg-defs.h
Error at 51: unhandled statement
make[2]: *** [../arch/arm64/tools/Makefile:24: arch/arm64/include/generated/asm/sysreg-defs.h] Error 1
make[2]: *** Deleting file 'arch/arm64/include/generated/asm/sysreg-defs.h'
make[1]: *** [../arch/arm64/Makefile:176: archprepare] Error 2
make[1]: Leaving directory '/mnt/linux/.output'
make: *** [Makefile:228: __sub-make] Error 2
make: Leaving directory '/mnt/linux'

Add gawk (GNU Awk) to work around this issue.
2022-06-10 22:20:40 +02:00
Anton Bambura dc1433ead0
Rename Chrome OS kernel partition to pmOS_kernel (MR 2187)
Make it consistent with pmOS_boot and pmOS_root and
make itmore pmOS-specific to prepare for automatic
kernel upgrades in the future.
2022-06-08 23:16:17 +03:00
Minecrell f1cbcb7b3b
pmb: flasher: frontend: don't fail if kernel config cannot be found (MR 2184)
When using a kernel from Alpine the kernel configuration cannot be
found in pmaports. We cannot check the kernel config for missing
options in that case, but that's no reason to break the flasher
entirely.
2022-06-06 09:52:17 +02:00
Oliver Smith cc90bc81f0
pmb.chroot.apk.install: move pkgname sanitization (MR 2185)
Check if the pkgnames are sane in install_run_apk, right before running
apk. This makes sure that we really run it on all arguments that are
supposed to be packages / files and not options to apk.
2022-05-30 19:09:01 +02:00
Oliver Smith 7b09cc7546
pmb.chroot.apk.install: fix empty install messages (MR 2185)
Previously pmbootstrap would only show the packages that are about to be
installed. In case all packages were already installed, this would lead
to weird empty install messages:

  (rootfs_asus-me176c) install

Show all packages that we want to install, even if they are already
installed in the given chroot.

  (rootfs_asus-me176c) install device-asus-me176c
2022-05-30 19:09:01 +02:00
Oliver Smith 6a74109154
pmb.chroot.apk.install: let apk figure out depends (MR 2185)
Previously to this patch, pmbootstrap would pass a full dependency tree
to "apk add". It would use a virtual package to ensure only the right
packages get added to /etc/apk/world. For example:
  apk add -u --virtual .pmbootstrap postmarketos-base device-asus-me176c \
  postmarketos-ui-sxmo-de-sway device-asus-me176c-nonfree-firmware w3m \
  sfeed clickclack firefox-esr font-noto font-noto-emoji gnome-icon-theme \
  imv megapixels mobile-config-firefox ttyescape postmarketos-base-nofde \
  eudev openssh postmarketos-mkinitfs postmarketos-mvcfg postmarketos-keys \
  ...

Instead of doing that, only pass the packages we want to install and let
apk figure out the dependencies. Most of the time we can even avoid
using the virtual package now.

== Remaining edge case: locally built packages
apk will only upgrade a package with the same pkgver + pkgrel but a
different build date if the full path to an apk file gets passed as
argument. So if the user built a package locally that will be installed,
or one of its dependencies then we still need to use a virtual package
and possibly pass a dependency to apk. Replace
replace_aports_packages_with_path() with packages_get_locally_built_apks()
to get a list of such packages and adjust install() and
install_run_apk() to use it.
2022-05-30 19:09:00 +02:00
Oliver Smith 903ed4ee30
pmb.chroot.apk.packages_split_to_add_del: new func (MR 2185)
Make the code easier to read by moving split_to_add_del() to a separate
function and do some related refactoring. A future patch will use it
twice in install().

Move "arch = ..." to the top of the function while at it, since it's
needed later in the function in 2 places and is not needed for figuring
out packages_with_depends, to_add and to_del.

Remove "# Add depends to packages" because it's obvious from the
packages_with_depends variable name, and getting to_add/to_del is a
different action that stood under the same comment.
2022-05-30 19:09:00 +02:00
Oliver Smith 682ee74ea6
pmb.chroot.apk.install_run_apk: new func (MR 2185)
Split out the part that builds the apk commands and runs them out from
install() to a new function install_run_apk(). This makes install()
easier to read.
2022-05-30 19:09:00 +02:00
Oliver Smith 12948eeb3d
pmb.chroot.apk.install: move empty packages check (MR 2185)
Since the previous commit that adds install_build(), all packages either
end up in to_add or to_del. Move the check for empty packages to the top
of the function, and directly check the packages variable.

I think it's worth keeping this check because it's shorter to add this
check once here than having it a few times in other place where we may
have or may not have something to install. And so we can avoid printing
an empty "install" message with no packages.
2022-05-30 19:09:00 +02:00
Oliver Smith e91dbefd16
pmb.chroot.apk.install_{is_necessary -> build} (MR 2185)
install_is_necessary used to do the following things:

1. Error out if there's no binary package but pmb was invoked as
   "pmbootstrap install" and build_pkgs_on_install is disabled.
2. Build the package if necessary.
3. Return if a package "needs to be installed" (Boolean or Float).

The only caller of the function is pmb.chroot.apk.install. It would not
add the package to the long "apk add" command if according to 3. it does
not need to be installed.

When I implemented this a few years ago, I probably thought it would be
useful to not unnecessarily pass packages to apk. But this actually
makes it more complicated and doesn't have a benefit, apk is perfectly
capable of recognizing which packages it had already installed.

Replace the function with a much simpler pmb.chroot.apk.install_build,
which only does 1. and 2. Change the order of the package, arch
arguments to match called functions pmb.parse.apkindex.package and
pmb.build.package.
2022-05-30 19:09:00 +02:00
Oliver Smith c898b13296
pmb.chroot.apk.install: rename to{add,del} vars (MR 2185)
Put underscores between the words for consistency with other variable
names. Since the whole function is about dealing with packages, remove
the "packages_" prefix to make them shorter.

	packages_toadd -> to_add
	packages_todel -> to_del
2022-05-30 19:09:00 +02:00
Oliver Smith 6b520d2d26
pmb.chroot.apk.install: update func desc (MR 2185) 2022-05-30 19:09:00 +02:00
Oliver Smith 03303ef7bc
Prepare 1.44.1 release
Tag 1.44.0 was done without bumping pmb.config.version, so tag another
one.
2022-05-24 20:16:07 +02:00
Bart Ribbers 741be5f521
Prepare pmbootstrap for pmOS v22.06 release (MR 2183) 2022-05-24 08:59:13 +02:00
Oliver Smith 8c7e99acd9
Prepare 1.43.1 release 2022-05-15 18:47:46 +02:00
David Wronek be9aab895b
pmb.install: Check for alpine-conf version (MR 2182)
Upstream Alpine change the way how `setup-timezone` works, it no longer
uses the `-z` argument to change the timezone.
2022-05-15 16:51:53 +02:00
Clayton Craft 9901cb31ea
pmb.parse.depends: ignore conflict dependency that no longer exists (MR 2181)
So it looks like some packages might be mentioned in the "depends=" of
other packages and marked as conflict, for example:
    depends="!foo"

..and the conflicting package can be dropped from the repo entirely if
it is no longer needed, however the reference to it in `depends=` still
exists. This handles that situation by just ignoring the missing package
if it is only a conflicting dependency.

fixes https://gitlab.com/postmarketOS/pmaports/-/issues/1525
2022-05-12 22:26:53 -07:00
Oliver Smith 6fbe916e0d
Prepare 1.43.0 release 2022-04-14 09:33:20 +02:00
Oliver Smith 7abb281296
partitions_mount: fix finding the partition (MR 2178)
Instead of trying both "${dev}1" and "${dev}p1" as partition paths, only
try one of them depending on if "${dev}" ends in a number or not. This
fixes getting a wrong /dev/loop11 partition by accident if there are
many loop devices, instead of only looking for the correct path
/dev/loop1p1. People reported this happening with snaps on ubuntu.
2022-04-14 09:09:46 +02:00
Minecrell faf523911a
pmb.install: Treat empty "flash_sparse_samsung_format" as disabled (MR 2180)
Deviceinfo variables are empty strings by default if they are unset
in the deviceinfo file, so the "is not None" check currently enables
the sm_sparse_image_tool for all existing devices using sparse format.

Simplify the check to convert the string to a bool. Empty strings
evaluate to False so this should work as originally intended.
2022-04-13 21:01:20 +02:00
Enrico Lumetti dee8e34298
pmb.config, pmb.install: add option to handle Samsung sparse image format (MR 2177) 2022-04-13 08:59:29 +02:00
Newbyte ff569ece14
config: Move ASHMEM into conditional (MR 2176)
Option was dropped and is no longer available.

See https://lore.kernel.org/all/20220315123457.2354812-1-hch@lst.de
And 721412ed3d
2022-04-05 21:04:22 +02:00
Newbyte 9a74848f19
pmb.parse.kconfig: print a helpful error message on invalid kconfig name (MR 2172)
Currently pmbootstrap prints a stacktrace if there's no . in the
kernel configuration name. Let's make it more helpful.
2022-04-02 16:36:17 +02:00
Alexey Min 0bab8ab6d2
install: fix alignment of information messages (MR 2174)
Make it in line with other information messages in this section.
Otherwise lk2nd flashing info paragraph looks shifted to the right.
2022-03-29 20:06:40 +03:00
Alexey Min fd74b54001
config: allow using flash_lk2nd with heimdall too (MR 2174)
One of the main purposes of lk2nd is to have a replacement for
the stock bootloader "Odin mode" on many Samsung devices with
sane fastboot implementation, which supports many more features
like live booting and many others.

This is done by using heimdall to flash lk2nd to device's boot
partition. Allow this method to be used with this flash action.
2022-03-29 15:36:08 +03:00
Newbyte 5389543c1a
helpers/envkernel.sh: use "$pmbootstrap" in cross_compiler_version() (MR 2173)
This fixes an issue where if pmbootstrap is accessed via a
different command than pmbootstrap on the user's system (I have it
set to pmb for example), cross_compiler_version() would try to use
a command that doesn't exist. On my system, this results in it
always asking if I want to install pmbootstrap every time I run
envkerenl.sh.
2022-03-24 00:25:01 +03:00
Bart Ribbers 1eef7fbdeb
pmb.parse.kconfig: implement UEFI kconfig check (MR 2169) 2022-03-16 09:25:00 +01:00
Oliver Smith 8c429f74ca
test_kconfig_check: note: don't add device tests (MR 2169)
Add a comment that we shouldn't add more tests relying on devices in
currently checked out pmaports.git (see issue 2105).
2022-03-16 09:25:00 +01:00
Oliver Smith 301f0995fb
pmb.parse.kconfig.check_file: fix broken f-string (MR 2169) 2022-03-16 09:24:55 +01:00
Laszlo Molnar 2e39912790
pmb.parse.arguments: add zap --all flag (MR 2117)
Fixes: #1692
2022-02-28 17:09:21 +03:00
Luca Weiss 5252d8de78
config: Move NFT_COUNTER into conditional (MR 2171)
The option has been removed and is now always enabled with nftables
core.

See also https://git.kernel.org/torvalds/c/023223d
2022-02-24 08:54:50 +01:00
Oliver Smith e45e8f932c
Prepare 1.42.0 release 2022-02-20 15:29:40 +01:00
Clayton Craft a367e0d95b
pmb.chroot.mount: create /dev/fd (MR 2170)
Specifically, this fixes issues with process substitution in bash in the
chroot.

For example, the following lines from a NetworkManager build script:

    ... |
        grep -Fx -f <(get_symbols_explicit) -v |
        grep -Fx -f <(get_symbols_nm)

fail with:
     ninja: job failed: /home/pmos/build/src/NetworkManager-1.35.92/tools/create-exports-NetworkManager.sh --called-from-build /home/pmos/build/src/NetworkManager-1.35.92
     grep: /dev/fd/63: No such file or directory
     grep: /dev/fd/63: No such file or directory
2022-02-20 15:03:09 +01:00
jenneron 7b2ffc3e5f
Support ChromeOS partition table and kernel partition (MR 2163)
Stock bootloader on these devices boots kernel (it is intended to boot
kernel, but i place secondary bootloader there) from special ChromeOS
kernel partition on special GPT which is created with cgpt utility.
This MR adds initial support for it introducing new deviceinfo options:

- cgpt_kpart - path to file to be flashed to ChromeOS partition;
- cgpt_kpart_start - offset from the start in sectors;
- cgpt_kpart_size - partition size in sectors.

For example:

deviceinfo_cgpt_kpart="/usr/share/u-boot/google-peach-pit/u-boot-dtb.img.kpart"
deviceinfo_cgpt_kpart_start="8192"
deviceinfo_cgpt_kpart_size="32768"

cgpt requires start and size values of partition, so these values
are calculated for each partition.

Reserved size and on-device installer are not yet supported.

Reference: https://archlinuxarm.org/platforms/armv7/samsung/samsung-chromebook
2022-02-20 14:49:56 +01:00
Anton Bambura 2363732645
pmb.install: add get_partition_layout() (MR 2163)
"Keeping track of which partition number is what is hard to understand now.
 I think this should be refactored, so we have it defined only in one
 place, and easy to read. Since this merge request increases the complexity
 of the partitions again, let's do it here before merging." - Oliver

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2022-02-20 14:48:18 +01:00
Caleb Connolly 0d5ff8f520
flake8: increase the line length limit (MR 2168)
80 is quite conservative, to the point where it often impacts code
   readability rather than improving it.
2022-02-13 20:27:47 +01:00
Caleb Connolly 18a16c7899
pmb: flasher: add support for rk partitions (MR 2165) 2022-02-13 19:54:29 +01:00
Martijn Braam 884174ce3c
config: use partition names for rkdeveloptool (MR 2165) 2022-02-13 19:54:23 +01:00
Clayton Craft 100fd332df
pmb.qemu.run: add option to set serial to mon:stdio (MR 1980)
This makes QEMU trap signals like Ctrl-C and send it to the guest
instead of terminating QEMU.

To quit QEMU with this option you can use [Ctrl-A] [x]
  or
[Ctrl-A] [c] and type 'quit' at the prompt.

This behavior is disabled by default, and can be enabled by setting a
new option in the pmbootstrap.cfg (using "pmbootstrap config
qemu_redir_stdio true")

Co-authored-by: Luca Weiss <luca@z3ntu.xyz>
2022-02-13 19:22:49 +01:00
Tony Garnock-Jones dfe8129640
Allow override of SSH key glob: documentation (MR 2167) 2022-02-13 16:26:49 +01:00
Tony Garnock-Jones 3c5effa0e7
Allow override of SSH key glob (MR 2167) 2022-02-08 12:29:27 +01:00
Oliver Smith 5d3cbbdb86
pmb.helpers.pkgrel_bump: !-deps are not missing (MR 2166)
Do not assume that conflicting dependencies are missing.

Fix for:
  Increase 'unl0kr' pkgrel (0 -> 1), missing depend(s): !osk-sdl

Related: https://gitlab.com/postmarketOS/monitoring/-/jobs/2058087076
2022-02-05 11:54:32 +01:00
Caleb Connolly 47410eafb9
config: fix missing comma in flash methods (MR 2164)
o/ hi Martijn
2022-02-02 21:20:11 +00:00
Marian Stramm 80c988236f
pmb.install: add support for creating btrfs root filesystem (MR 2155)
in preparation for reversible upgrades, this change adds the option of
creating a btrfs root filesystem
2022-01-29 11:47:29 +03:00
Bart Ribbers 9e63d5820c
Support generating GPT partition tables (MR 2160)
The PPP will, in combination with tow-boot, boot with GPT on the
internal storage. We need to support that on postmarketOS and as a first
step, let's make it possible to generate GPT images and boot from that
2022-01-28 10:01:46 +01:00
Bart Ribbers 36aabcc4fe
Print return code when subprocess fails (MR 2161)
It can be very useful to figure out why a particular subprocess might be
failing ;)
2022-01-22 15:45:12 +01:00
Mark Hargreaves ff0942b12d
pmbootstrap kconfig check: add netboot check (MR 2064)
Allow checking for the necessary kernel option for netboot.

Co-authored-by: Luca Weiss <luca@z3ntu.xyz>
2022-01-20 22:29:46 +01:00
Mark Hargreaves 47539f1bef
pmb/netboot: new feature (MR 2064)
pmbootstrap netboot command exposes the generated vendor-codename.img
rootfs through nbd interface so that device can mount it and boot
postmarketOS without having any storage medium at all.

Co-authored-by: Luca Weiss <luca@z3ntu.xyz>
2022-01-20 22:29:41 +01:00
Rudraksha Gupta 997e3fb1f5
pmb.install: Remove pass to conform to code style (MR 2159) 2022-01-20 21:01:46 +01:00
Rudraksha Gupta bea18e03f3
pmb.install: password for root is already locked (MR 2159)
When running `pmbootstrap install`, pmbootstrap does not unlock root
when it completes. This patch allows `pmbootstrap install` to run two or
more times (without zap).

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2022-01-20 21:01:41 +01:00
Oliver Smith d698aa15ad
Prepare 1.41.0 release 2022-01-18 21:46:34 +01:00
Johannes Marbach 6d7d113040
pmb.chroot.apk: Delete conflicting dependencies (MR 2157)
When installing dependencies for a package, conflicting (!) dependencies
are now deleted (with `apk del pkg`) whereas before a constraint for
their _absence_ was added (with `apk add !pkg`). Doing it the new way
around prevents creating deadlocks because a `!pkg` constraint will
prevent pkg from ever being installed without an explicit `apk del`
call.

Fixes: #2092
2022-01-18 20:06:23 +01:00
Newbyte 614cb72a2a
pmb.install: update UID 10000 explanation (MR 2158) 2022-01-11 00:17:55 +03:00
Johannes Marbach 2ad5427126
pmb.install: automatically pick unlocker package (MR 2154)
This removes the hard-coded installation of osk-sdl when specifying
--fde (or using the on-device installer) and instead determines the
unlocker package by taking the most suitable provider of
postmarketos-fde-unlocker (factoring provider priority and packages
selected for installation).

With this change applied, one can manually select an unlocker package to
be installed via

    pmbootstrap install --fde --add other-unlocker

Relates to: postmarketOS/pmaports#1309
2022-01-02 22:40:23 +01:00
Oliver Smith 6f6a3b0408
Happy new year 2022! 2022-01-02 22:39:14 +01:00
Andreas Kemnade 8ca71ed3a0
install: do not choke on blockdevices without fs (MR 2153)
when blkid returns 2 while searching for existing pmos installations,
do not abort. That might happen if there is a block device without a
filesystem.

Error given:
(1653851) [21:39:19] (native) % blkid -s LABEL -o value /dev/sdcardp1
(1653851) [21:39:19] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(1653851) [21:39:19] NOTE: The failed command's output is above the ^^^ line in the log file: /home/andi/.local/var/pmbootstrap/log.txt
(1653851) [21:39:19] ERROR: Command failed: (native) % blkid -s LABEL -o value /dev/sdcardp1
(1653851) [21:39:19] See also: <https://postmarketos.org/troubleshooting>
(1653851) [21:39:19] Traceback (most recent call last):
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/__init__.py", line 49, in main
    getattr(frontend, args.action)(args)
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/helpers/frontend.py", line 314, in install
    pmb.install.install(args)
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/install/_install.py", line 944, in install
    install_system_image(args, 0, f"rootfs_{args.device}", step, steps,
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/install/_install.py", line 586, in install_system_image
    pmb.install.blockdevice.create(args, size_boot, size_root,
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/install/blockdevice.py", line 138, in create
    mount_sdcard(args, sdcard)
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/install/blockdevice.py", line 51, in mount_sdcard
    if previous_install(args, path):
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/install/blockdevice.py", line 27, in previous_install
    label = pmb.chroot.root(args, ["blkid", "-s", "LABEL", "-o", "value",
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/chroot/root.py", line 76, in root
    return pmb.helpers.run_core.core(args, msg, cmd_sudo, None, output,
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/helpers/run_core.py", line 343, in core
    check_return_code(args, code, log_message)
  File "/home/andi/.local/lib/python3.9/site-packages/pmb/helpers/run_core.py", line 219, in check_return_code
    raise RuntimeError("Command failed: " + log_message)
RuntimeError: Command failed: (native) % blkid -s LABEL -o value /dev/sdcardp1
2022-01-02 22:14:06 +01:00
Johannes Marbach a9d1049a3c
build: add support for conflicting dependencies (MR 2146)
This adds support for the depends="!conflict ..." syntax for explicitly
marking another package as conflicting with the current one.

Fixes: #2085
2021-12-30 20:25:02 +01:00
Clayton Craft 8a14d366ef
helpers/envkernel.sh: fix shellcheck failure (MR 2151)
A recent update to shellcheck made this line start failing:
In ./helpers/envkernel.sh line 59:
        export pmbootstrap_dir=$(realpath "$script_dir/..")
                               ^--------------------------^ SC2046 (warning): Quote this to prevent word splitting.
2021-12-19 18:16:56 +01:00
Oliver Smith 3e5f27d5e3
pmb.parse.depends.recurse: tweak message (MR 2151)
Fix the lint error. While at it, change the wording so it's clear it's
looking in pmaports instead of aports, use '' around the source package
just as the message does about the pkgname_depend, remove <> from the
link URL.

New message:
  Could not find dependency 'so:libPocoData.so.80' in checked out pmaports dir or any APKINDEX. Required by 'nymphcast'. See: https://postmarketos.org/depends

Fixes: 81dc4c ("pmb.parse: show which package require the missing package")
2021-12-19 18:16:51 +01:00
Martijn Braam 81dc4c17f6
pmb.parse: show which package require the missing package (MR 2150)
When a dependency is not found it now shows all the pacakges that
require that dependency in the error message.
2021-12-17 17:17:25 +01:00
Oliver Smith fd7050835f
Prepare 1.40.0 release 2021-12-12 19:07:21 +01:00
Anjandev Momi c1407f921b
Use doas instead of sudo if installed (MR 2091)
Prefer using doas over sudo if both are installed. Let the user override
the sudo tool with PMB_SUDO.
2021-12-12 18:46:17 +01:00
Tim Zimmermann 2801b5d687
kconfig-check: only check TZDEV/SAMSUNG_TUI on kernels older than 4.14 (MR 2148)
* On newer samsung devices disabling these does the exact opposite of
  what's mentioned in 50cdf04760
* With these enabled the device boots up just fine
2021-12-12 17:23:21 +03:00
Alexey Min 66d11d6d34
pmb.helpers.ui: clarify "none" UI purpose
And suggest users to use "console" UI instead.
2021-12-12 16:51:39 +03:00
Alexey Min 89350b69b6
tests: test single-line comment for unquoted attribute (MR 2149) 2021-12-12 16:16:55 +03:00
Clayton Craft 58e4e86b6b
pmb.parse.parse_attribute: strip off trailing comment on attrib line (MR 2149)
The apkbuild parser could not handle cases where a line ends in a
comment but the value is not quoted.

E.g. this:

    pkgver=1.0 # I'm a comment, look at me

was being parsed to a value like this:

    1.0 # I'm a comment, look at me

... which is obviously wrong. This strips off any trailing comment on
the line, so it's parsed to the correct value.

fixes #2087
2021-12-12 16:16:30 +03:00
Oliver Smith 672ebe797b
Revert "CI: download shellcheck (MR 2142)"
It's back in Alpine edge.

This reverts commit 3987d2f764.
2021-11-27 15:32:15 +01:00
Anjandev Momi 8563efb9da
aportupgrade: if $pkgver=9999, use $_pkgver variable instead (MR 2127)
fixes #2071
2021-11-27 15:05:25 +01:00
Oliver Smith 54fade131c
Fix 'kconfig edit linux-...' (MR 2143)
Properly assemble the required pkgname to fix:

  $ pmbootstrap kconfig linux-postmarketos-allwinner
  ERROR: Could not find aport for package: postmarketos-allwinner

Fixes: 6557e6 ("kconfig argcomplete: support full pkgname")
2021-11-27 14:45:09 +01:00
BO41 3f2bd03d33
remove unused args argument (MR 2136) 2021-11-27 14:13:33 +01:00
BO41 379991aa62
pmb.parse.apkindex.parse: remove unused args argument (MR 2136) 2021-11-27 14:13:33 +01:00
BO41 99bed38272
pmb.parse.apkbuild: remove unused args argument (MR 2136) 2021-11-27 14:13:33 +01:00
BO41 ce0f1c2d4a
args.cache: remove (MR 2136)
Replace "args.cache" with a global variable in order to
avoid passing "args" to all functions. This is a step to get rid of this
args-passed-to-all-functions pattern in pmbootstrap.
2021-11-27 14:13:27 +01:00
Oliver Smith f30b1cc3f2
pmb.config.apk_tools_min_version: add alpine 3.15 (MR 2144)
Prepare for postmarketOS v21.12 release.
2021-11-26 00:51:11 +01:00
Jami Kettunen b3d91f274d
pmb/config: check CROSS_MEMORY_ATTACH config required for Waydroid (MR 2140)
Without this syscall zygote keeps constantly crashing in the container.
2021-11-18 19:43:51 +02:00
Oliver Smith 3987d2f764
CI: download shellcheck (MR 2142)
Similar fix as in pmaports MR 2673.
2021-11-11 22:50:28 +01:00
Caleb Connolly 4c4bd77c87
install: support password as cmdline arg (MR 2125)
So I can finally run `pmbootstrap install --password 147147` and go and
make a cup of tea.

Based on MR 1919.

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2021-11-06 22:45:00 +01:00
Oliver Smith 498738abcc
Prepare 1.39.0 release 2021-11-06 21:06:53 +01:00
Ultracoolguy 54afa35d70
Add 'flasher flash_lk2nd' command (MR 2089)
Many Qualcomm devices need this second bootloader for booting a mainline
kernel. Add an option to flash one if it exists.
2021-11-06 20:51:58 +01:00
Luca Weiss f4990cfc7a
aportupgrade: support gitlab.gnome.org (MR 2119)
Also sort the gitlab hosts alphabetically
2021-11-06 20:31:25 +01:00
Luca Weiss f996f3ed5a
aportupgrade: prefer explicit package mapping (MR 2119)
This solves some edge cases with packages like 'date', 'fmt' and others.
2021-11-06 20:31:19 +01:00
Oliver Smith 6557e6892a
kconfig argcomplete: support full pkgname (MR 2134)
Support full linux-* package names in argument completion for
"pmbootstrap kconfig ..." command-lines and get rid of related PROTIP
messages:
  PROTIP: You can simply do 'pmbootstrap kconfig check postmarketos-allwinner'

This improves consistency, as in other places we expect the user to
supply full package names as well (e.g. pmbootstrap build).
2021-11-06 15:23:37 +01:00
Oliver Smith 152bd6753c
arguments: fix compat with argcomplete 1.8 (MR 2134)
When running pmbootstrap on debian bullseye with the distro's
python3-argcomplete 1.8 from 2017, tab completion was broken. After
disabling stderr redirect to /dev/null, the error appeared:
  TypeError: package_completer() missing 1 required positional argument: 'parser'

Support this ancient version of argcomplete too by setting None as
default value for parser (we don't use it anyway).

Related: https://wiki.postmarketos.org/wiki/Pmbootstrap_development_guide#Debugging_tab_completion_.28argparse.29
2021-11-06 15:23:31 +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 47645f41b1
pmb.parse._apkbuild: parse provider_priority as int (MR 2132) 2021-11-06 15:04:25 +01:00
Minecrell 19b232969d
pmb.helpers.pmaports: search for provides in both root and subpackages (MR 2132)
At the moment, "provides" are only checked in the root package and not
in subpackages of APKBUILDs. Fix this by looking through the subpackages
as well.
2021-11-06 15:04:25 +01:00
Minecrell 5ed807c064
pmb.helpers.pmaports: parse guessed APKBUILD first for speed up (MR 2132)
At the moment we have to parse all APKBUILDs to find subpackages,
even if they are guessed easily shortly after. To speed this up,
let's guess first but verify the guess by only parsing that particular
APKBUILD. If the subpackage/provides is in there we seem to have found it.
2021-11-06 15:04:25 +01:00
Minecrell eb3e38d15c
pmb.helpers.pmaports: separate finding pkg in APKBUILD to function (MR 2132)
Make it possible to call this in a different place as well by placing
it in a separate function.
2021-11-06 15:04:25 +01:00
Minecrell 7246c32539
pmb.install: move install_recommends check into _install.py (MR 2132)
The current install code looks a bit confusing, there is an existing
if statement for the ui and ui-extras package but the recommended
packages are already installed before with a check in a completely
different file. Make this a bit more clear by moving this to the
ui if statement instead.
2021-11-06 15:04:25 +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
Oliver Smith 05f257295d
pmb.config: add comment: kconfig check value types (MR 2133) 2021-11-06 14:28:54 +01:00
Oliver Smith aead36d5ac
pmbootstrap kconfig check: add iwd check (MR 2133)
iwd seems like a promising alternative to wpa_supplicant. It uses crypto
implementations from the kernel, so let's make kconfig check aware of
the options it needs.
2021-11-06 14:28:53 +01:00
Oliver Smith d856e21673
pmb.config.necessary_kconfig_*: tweak comments (MR 2133)
Improve the comments for consistency and to give a little more info than
just repeating the variable name.
2021-11-06 14:28:53 +01:00
Oliver Smith 93e7a1d876
pmbootstrap kconfig check: add apparmor check (MR 2133)
SECURITY_APPARMOR_BOOTPARAM_VALUE was required to enable it by default
until 5.1 where the option was removed.

Related: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0102fb83f90050b86ce37aec810ea17bb4448e0c
Related: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/security/Kconfig?id=fe91c4725aeed35023ba4f7a1e1adfebb6878c23#n285
2021-11-06 14:28:53 +01:00
Oliver Smith dcedc4bc1f
kconfig check: support strings too (MR 2133)
Extend the kconfig check code to not only support booleans and arrays,
but also strings. This will be used for CONFIG_LSM with apparmor where
it's important that "apparmor" has a certain spot in the list.
2021-11-06 14:28:53 +01:00
Oliver Smith 6b8fa93d37
pmb.parse.kconfig.check: git friendly arguments (MR 2133)
Put each component argument into a separate line, as these get changed
whenever adding a new kernel config check. I'm about to add two new
ones.
2021-11-06 14:28:49 +01:00
Alexey Min 0664a38190
pmb.qemu.run: workaround for new mkinitfs requirements (MR 2138)
It's been 3 months since we switched to new mkinitfs
and we are still fixing consequences.

linux-lts and linux-virt used by qemu-amd64 device package
install vmlinuz-lts (vmlinuz-virt). And qemu run cmdline
passed -kernel vmlinuz which makes it impossible to run
qemu without this change.

With this change proper kernel arg is passed to qemu.

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
Signed-off-by: Alexey Min <alexeymin@postmarketos.org>
2021-11-06 13:36:34 +01:00
博麗霊夢 7541a0ca36
helper/envkernel.sh: fix for running envkernel on aarch64 host (MR 2135)
aarch64 is not recongised as arm64, and envkernel thinks that
cross-compiler is needed, while it shouldn't be.

Fixes #2075
2021-11-02 16:23:33 +03:00
Jami Kettunen 931675450d
pmb/config: check CRYPTO_AES and INPUT_EVDEV configs required for FDE (MR 2137)
AES is needed on top of XTS to unlock a disk with FDE enabled and evdev
is used in osk-sdl to input the passphrase.
2021-11-01 23:07:05 +03:00
bo41 caf7973e24
args.arch_native: remove (MR 2130)
Replace "args.arch_native" with the direct function call in order to
avoid passing "args" to all functions. This is a step to get rid of this
args-passed-to-all-functions pattern in pmbootstrap.
2021-10-24 14:34:30 +02:00
Oliver Smith f2966e62ae
pmb.parse.arch.alpine_native: remove unused ret (MR 2130) 2021-10-24 14:34:30 +02:00
bo41 a8d425554c
remove unused args argument (MR 2130) 2021-10-24 14:34:26 +02:00
Martijn Braam 896879e89a
pmb: data: keys: sync with Alpine (MR 2131)
Alpine has new keys for the riscv64 builder and new 4096 bit
builder keys. This fixes CI again.
2021-10-19 01:44:35 +02:00
Martijn Braam ea70d3205e
pmb/config: add rkdeveloptool support (MR 2103)
Needed for flashing some rockchip platforms
2021-10-17 18:41:52 +02:00
Caleb Connolly 8bc5366e60
parse: deviceinfo: arch is required (MR 2124)
The deviceinfo_arch property is required but not checked, this leads to
weird errors if not caught.
2021-10-17 17:44:18 +02:00
Pablo Correa Gómez 4f793125d1
Allow to set mirror_alpine with pmbootstrap config command (MR 2129)
There is a double reason for this:
 * Better performance when developers/users choose local mirrors
 * Allows to continue developing if a mirror is down
2021-10-17 14:40:37 +02:00
Oliver Smith a676bdef0c
pmb.install.partition: fix mb_reserved calculation (MR 2123)
Calculate the end of the reserved space properly. Instead of:
	from size_boot to size_reserve
it is:
	from size_boot to (size_reserve + size_boot)

The reserved space is used by the on-device installer. Without this
patch, the reserved space could easily end up being too small, resulting
in no space left errors during the installation.
2021-10-17 14:27:44 +02:00
Alexey Min 97f59ffe93
pmb/config: fixup zram check options (MR 2126)
The main option - CONFIG_ZRAM - was not checked.
Add it and its direct requirement - CONFIG_ZSMALLOC.

The other two (ZSMALLOC_STAT, ZRAM_MEMORY_TRACKING) are
for debugging information only.
2021-10-15 21:48:18 +03:00
BO41 58922142ac
pmb.qemu.run.which_qemu: remove args argument (MR 2114)
Drop the argument, as it is not used.
2021-10-10 16:59:21 +02: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
Oliver Smith 313c9611c8
Prepare 1.38.0 release 2021-10-10 16:31:58 +02:00
Alexey Min ad491bc121
pmb.chroot.initfs: adapt to new mkinitfs (MR 2112)
Follow-up to 09794ef832 -
initfs file does not have flavor now, too.

Without this 'pmbootstrap initfs extract' fails with:

 (rootfs_samsung-klte) % cp /boot/initramfs-postmarketos-qcom-msm8974 /tmp/initfs-extracted/_initfs.gz
 cp: cannot stat '/boot/initramfs-postmarketos-qcom-msm8974': No such file or directory
2021-10-10 16:09:29 +02:00
Alexey Min 48c85cdc1f
kconfig migrate: new option to migrate kernel configs (MR 2111)
With this option you can run

$ pmbootstrap kconfig migrate --arch <arch> linux-postmarketos-xxx-xxx

to perform safe kconfig upgrades between kernel releases.

"make oldconfig" will ask question for every new/renamed kconfig option,
so you have no chance to miss anything.
2021-10-10 15:38:45 +02:00
Bart Ribbers 37c390aeed
pmb/parse/arguments: add aportupgrade to --help (MR 2121)
I keep forgetting this command exists, for one because it doesn't appear
(besides in a big, hard-to-read, one-line list) in the --help output
2021-10-10 13:55:02 +02:00
Newbyte 446a8fc430
pmbootstrap.py: Check which version of Python pmbootstrap is run with (MR 2118)
This prevents people from getting strange syntax errors if they
accidentally run pmbootstrap with e.g. Python 2.
2021-10-01 22:46:23 -07:00
Alexey Min 5761a29f07
pmb.aportgen.binutils: fix for new binutils file conflict (MR 2116)
Newly generated binutils package has file conflicsts with
non-cross binutils.

  ERROR: binutils-2.37-r3: trying to overwrite usr/lib/bfd-plugins/libdep.so
         owned by binutils-aarch64-2.37-r3.

Fix the generator to produce package that does not include these plugins.
2021-09-29 23:41:58 +02:00
Newbyte 2d23849aa3
pmb, test: remove redundant commas (MR 2115) 2021-09-26 17:58:40 +02:00
Bart Ribbers 4675def8e6
pmb/config: add required option for Waydroid support (MR 2109) 2021-09-13 21:10:05 +03:00
Alexey Min 374d7379ab
pmb.parse.bootimg: make boot.img readable for all after copying (MR 2105)
This prevents rare errors when source file didn't have the
correct permissions.
2021-09-13 14:40:15 +03:00
Oliver Smith bf02c72da7
test: add test_bootimg_mtk_mkimage_recovery (MR 2105)
Verify that using a Mediatek recovery boot.img file works with
bootimg_analyze. The mtk_mkimage-boot.img file is the twrp boot.img file
posted in pmbootstrap issue 2066.
2021-09-13 14:40:15 +03:00
Boris Lysov d559db062f
pmb.parse.bootimg: accept Mediatek recovery images too (MR 2105)
Some Mediatek recovery images have headers named
"RECOVERY". Accept those too.

Signed-off-by: Boris Lysov <arzamas-16@mail.ee>
Co-Authored-By: Alexey Min <alexeymin@postmarketos.org>
Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2021-09-13 14:40:02 +03:00
Oliver Smith 881a3a03bc
pmb.parse.bootimg: refactor mtk_bootimg code (MR 2105)
Move all code that verifies the labels of the kernel and ramdisk inside
the boot.img file into a separate function, so it is easier to extend it
to allow recovery images too.
2021-09-12 22:02:52 +02:00
Oliver Smith cd366859de
testdata: replace mtk_mtkimage-boot.img (MR 2105)
Replace the previous mtkimage-boot.img file, which were only the first 4
KiB of a mediatek boot.img file, with a full one. I made this full image
with pmbootstrap install for fairphone-fp1, it contains the kernel
packaged in pmaports.git master.

Reason for the replacement is, that the previous image did not contain
the label for the ramdisk. The current code ignored this, but upcoming
refactoring will test this more strictly and the dummy image will not
pass the test anymore.
2021-09-12 22:02:47 +02:00
Oliver Smith 6fde1f0851
build --strict: use pmb.chroot.init_keys (MR 2110)
Fix the issue of having the postmarketOS binary repository key deleted
from the chroots after "abuild undeps" removes the postmarketos-keys
package. This happens if e.g. building two device packages in a row (as
they depend on postmarketos-base, which depends on postmarketos-keys in
current pmaports.git master).

I've also considered installing the postmarketos-keys next to
alpine-base in new chroots. But this would introduce a bootstrap
problem, since you can't install the postmarketos-keys package unless
it already exists in the repository. We'd run into that when building
the next release.
2021-09-10 21:27:20 -07:00
Oliver Smith 9b7feadca6
pmb.chroot.init_keys: split into own function (MR 2110)
Move code to install Alpine and postmarketOS keys into its own function,
so it can be called outside of pmb.chroot.init too (next patch).

Describe why this is needed in the first place and, while at it, tweak
the function to only copy the key if it does not exist in the target
directory.
2021-09-10 21:27:19 -07:00
BO41 77d39ecdf1
lint: enforce max line length (MR 2097) 2021-09-10 03:18:27 +02:00
Henrik Grimler 51bfdc9784
pmb.aportgen: prefix $_outdir to dtbTool-sprd -p arg (MR 2107)
The -p arg is suppose to point to the folder where the dtc program
resides (if it is not found in PATH). If we use an _outdir, which the
template currently does, then the arg needs to be -p
$_outdir/scripts/dtc/, and not -p scripts/dtc/, as scripts/dtc/ only
contains the dtc source code.
2021-09-05 15:56:52 +02:00
Henrik Grimler c524926295
pmb.aportgen: rm -p scripts/dtc arg from dtbTool cmd (MR 2107)
The python variant of dtbTool, that we currently use, does not use
this arg as it does not run dtc in a shell.  I suppose the argument
was added only for compatibility with other dtbtools.
2021-09-05 15:54:43 +02:00
Clayton Craft 393184672d
pmb/config/flashers/heimdall: support a single kernel flavor (MR 2106)
This was missed in 05c9fb78
2021-09-05 00:50:01 -07:00
Johannes Marbach ac4c967e18
pmbootstrap lint: avoid looping and copying files (MR 2100)
Before this commit, package folders were copied into the chroot one by
one in order to run apkbuild-lint on them. This logic is replaced by
mounting pmaports.git into the chroot and using a single apkbuild-lint
invocation to lint the supplied packages.

Both of these changes result in a performance improvement, especially
when linting multiple packages at once.

Before this change:

    $ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
        > /dev/null

    real    0m5,261s
    user    0m7,046s
    sys     0m1,842s

Using the pmaports.git mount but calling apkbuild-lint in a loop:

    $ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
        > /dev/null

    real    0m4,089s
    user    0m6,418s
    sys     0m1,219s

After this change:

    $ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
        > /dev/null

    real    0m3,518s
    user    0m5,968s
    sys     0m0,959s

Additionally, running apkbuild-lint from the pmaports.git mount point
has the benefit that every printed violation contains a nice source
identifier à la "./cross/grub-x86/APKBUILD". This makes it possible to
differentiate between different packages even though only a single
apkbuild-lint invocation is used.

Relates: postmarketOS/pmaports#564
2021-09-03 10:52:50 -07:00
Oliver Smith 0b95779e30
Prepare 1.37.0 release 2021-09-03 19:28:07 +02:00
Clayton Craft 45ce639aca
pmb/qemu: add support for single kernel 'flavor' (MR 2093) 2021-09-02 18:18:14 -07:00
Clayton Craft 453ce35b8c
pmb/export/symlinks: add support for a single 'flavor' (MR 2093) 2021-09-02 18:18:13 -07:00
Clayton Craft 91bb682755
pmb/install/recovery: add support for single kernel 'flavor' (MR 2093) 2021-09-02 18:18:13 -07:00
Clayton Craft 05c9fb784f
pmb/config/flashers: add support for single kernel 'flavor' (MR 2093) 2021-09-02 18:18:13 -07:00
Clayton Craft 09794ef832
chroot/other/kernel_flavor_installed: support generic kernel name (MR 2093)
kernel is named /boot/vmlinuz now, looking at the filename will no
longer tell us what flavor it is. This now will look at
/usr/share/kernel, which has always contained the kernel 'flavor', and
since we currently only install 1 kernel these days, guarding this with
pmaports.cfg should be unnecessary. In the worst case (if there are
multiple kernel 'flavors' installed), it'll just grab the first one and
return it.
2021-09-02 18:18:13 -07:00
Clayton Craft 184ac91ec5
pmb/install: use kernel pkg for device when printing firewall info (MR 2093)
multiple 'flavor' support will be going away
2021-09-02 18:18:13 -07:00
Clayton Craft 1d5030738c
pmb/helpers/frontend: drop all --flavors args (MR 2093) 2021-09-02 18:18:13 -07:00
Clayton Craft ca7ac4c704
pmb/chroot/initfs: change invocation to support the new mkinitfs (MR 2093)
The new mkinitfs does not have options for kernel flavor or version

A new pmaports.cfg variable, "supported_mkinitfs_without_flavors" is used to
determine how to invoke mkinitfs
2021-09-02 18:18:05 -07:00
Clayton Craft 9ae2eef0f0
pmb/config: add missing option for flash_heimdall_partition_dtbo (MR 2104)
This fixes a regression introduced by pmb!2099
2021-08-31 19:45:25 -07:00
afeuerstein 2d3cfbcbb4
pmbootstrap flasher: add flash_dtbo (MR 2099) 2021-08-29 22:51:56 +02:00
Oliver Smith 468d313790
Prepare 1.36.0 release 2021-08-22 21:45:59 +02:00
Alexander Krotov f853ec18e5
helpers/envkernel.sh: support `aports` configuration variable (MR 2096) 2021-08-22 20:36:24 +02:00
BO41 87dd1d0961
pmbootstrap: add color support (MR 2090)
Can be disabled by setting the $NO_COLOR environment variable
2021-08-19 11:00:04 +02:00
BO41 e1aef47271
pmbootstrap: make use of consistent casing (MR 2090) 2021-08-12 17:06:11 +02:00
Alexey Min a6c63f9580
pmb.aportgen.gcc: use more f-strings (MR 2092) 2021-08-10 01:18:22 +03:00
afeuerstein 83c4f142e2
pmb.aportgen.gcc: sync makedepends of gcc aportgen to upstream (MR 2092)
Remove paxmark dep. Follow up to
1c6ba9f907,
which happened 5 months ago.

Fixup testdata too.
2021-08-10 01:16:54 +03:00
Oliver Smith d01027fe2c
pmb.config.apk_tools_min_version: update
Require an apk-tools version that has the recent CVE fixed.

Related: https://security.alpinelinux.org/vuln/CVE-2021-36159
2021-08-07 17:12:03 +02:00
Petr Vorel ba07c4cf14
pmbootstrap init: Fix regexp for int (MR 2086)
This improves handling input in pmbootstrap init.

Various config options in "Additional options" are int, thus whole input
must be checked:

This fixes obvious error:
Jobs [9]: 5e

and less obvious errors:
Extra space size: 600.5
Extra space size: 600m
...
$ pmbootstrap install
[17:28:23] *** (3/4) PREPARE INSTALL BLOCKDEVICE ***
[17:28:23] ERROR: invalid literal for int() with base 10: '600.5'

NOTE: I suppose moving ^ $ to ReadlineTabCompleter.ask() would break
some of already defined regexes.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
2021-08-01 16:12:04 +02:00
Clayton Craft db12e987d0
pmb/chroot/binfmt: always install qemu- binary (MR 2088)
gitlab runners seem to be registering binfmt now (?), so this fixes an
issue where register() might return immediately because the OS (or ??)
took care of registration, but the qemu-<arch> binary wasn't added to
the chroot.
2021-07-28 15:27:59 -07:00
Clayton Craft 8447629f3c
pmb/chroot/binfmt: don't register arch if OS does it automatically (MR 2088)
It seems like the gitlab runners will now automatically register archs
when binfmt is mounted (I'm not completely sure, it's really
hard/annoying to confirm using gitlab CI jobs and no direct access to
the runner)

In any case, checking if it's already registered fixes a problem where
CI fails with "File exists" when it tries to register the arch.
2021-07-28 14:39:07 -07:00
Petr Vorel f3b6534b69
pmbootstrap init: Fix project in issue reference (MR 2087)
It's in https://gitlab.com/postmarketOS/pmbootstrap/-/issues/1904,
not in https://gitlab.com/postmarketOS/pmaports/-/issues/1904.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
2021-07-28 10:51:21 -07:00
Newbyte 3c98cae230
kconfig check: require CONFIG_SWAP for zram (MR 2085)
While zram has uses outside of swap-on-zram, I would believe that the
main use of zram in postmarketOS is swap-on-zram. In addition to that,
I imagine many probably expect swap-on-zram to work if the zram kconfig
succeeds.
2021-07-17 18:11:50 -07:00
Oliver Smith 68fe7df046
pmbootstrap install: support new ondev boot label (MR 2083)
In order to support FAT32 as boot partition, the label is shortened from
pmOS_inst_boot to pmOS_i_boot. Read the value from pmaports.cfg and fall
back to the old value, so both are supported (-> building v21.06 and
v21.03 will use the old label).

Remove the old codepath that would set "pmOS_boot" as label for the
install partition, if the postmarketos-ondev package was older than
0.4.0. This is only the case on the long unsupported v20.05 branch.
2021-07-13 19:57:08 +02:00
Minecrell f62242aeb1
helpers/envkernel.sh: Try harder to not generate Git version suffix (MR 2084)
The Git version suffixes usually generated automatically by the Linux
build system break packaging in Alpine because the flavor (e.g.
"-postmarketos-qcom-msm8916") will no longer match the module and
zImage path. So far setting LOCALVERSION= and disabling
CONFIG_LOCALVERSION_AUTO was sufficient to avoid the Git version
suffixes but this is no longer enough in Linux 5.14.

Instead, add a better fix by creating an empty .scmversion file
that will be used by the kernel instead of checking the Git status.
The advantage is that this works on Linux 5.14 and it should even
work when CONFIG_LOCALVERSION_AUTO is set.

The .scmversion code can be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/setlocalversion?h=v5.14-rc1#n38
2021-07-12 10:56:36 -07:00
Oliver Smith a34db4c8fd
Prepare 1.35.0 release 2021-07-11 22:47:27 +02:00
Oliver Smith a0ca7d9a14
install --ondev: no postmarketos-base-nofde (MR 2082)
Install osk-sdl in the installer OS's boot partition for now. I forgot
about a code path earlier, which could render an encrypted target OS
without osk-sdl in the initramfs (and being unable to boot).

The target OS gets embeded in the installer OS as image file. This can
happen in two formats:

a) a full image with partition header and the boot and root partition
This is what bpo is doing when building the official, pre-built images,
as this method allows having the exact same image available separately
without the installer. Basically:
	pmbootstrap install \
		--ondev \
		--no-rootfs \
		--cp path/to/rootfs:/var/lib/rootfs.img

b) an image with just the root partition, no partition header and no
boot partition. This is what you get when running regular
"pmbootstrap install --ondev". It's slightly smaller, as there is no
duplicate boot partition.

If b) was done, the installer will copy the contents of the installer's
boot partition to the target OS. And that means: if osk-sdl is missing
from the installer's boot partition (the initramfs generated there), it
will also be missing in the boot partition of the target OS!

I think we should get rid of the b) code path to avoid confusion in the
future/make maintenance. But until that is done, always install osk-sdl
into the installer OS.
2021-07-11 20:18:41 +02:00
Oliver Smith 9bef0a815a
pmbootstrap init: fix question for locale (MR 2082)
Remove the "(y/n) " in the question:
  Choose default locale for installation (y/n) [C.UTF-8]:
So it becomes:
  Choose default locale for installation [C.UTF-8]:
2021-07-11 17:12:31 +02:00
Oliver Smith 9e03034b28
Fix pmbootstrap -h for --mirror-pmOS (MR 2082)
Fix this weird help output:
  -mp URL, --mirror-pmOS URL
                        postmarketOS mirror, disable with: -mp='', specify
                        multiple with: -mp='one' -mp='two', default: h, t, t,
                        p, :, /, /, m, i, r, r, o, r, ., p, o, s, t, m, a, r,
                        k, e, t, o, s, ., o, r, g, /, p, o, s, t, m, a, r, k,
                        e, t, o, s, /
2021-07-11 17:12:31 +02:00
Oliver Smith 7616803207
pmb.chroot.shutdown: clean up chroot marker here (MR 2082)
Remove /in-pmbootstrap inside chroots in "pmbootstrap shutdown" instead
of having it at a specific part of "pmbootstrap install".

Reasoning:
* With current approach, it didn't get removed in the on-device
  installer chroot.
* This is less error prone than calling it multiple times in
  "pmbootstrap install"
2021-07-11 17:12:26 +02:00
Anri Dellal c347b27f69
pmb/config/init.py: use f-strings, fix E501 (MR 2043) 2021-07-06 18:55:41 -07:00
Anri Dellal 08617722a4
init: Hide unsupported UIs (MR 2043)
Hides user interfaces which require GPU acceleration
for unsupported devices. Device support is identified
by deviceinfo property `deviceinfo_gpu_accelerated`.
UI which has GPU acceleration as requirement,
must have `pmb:gpu-accel` in APKBUILD's options.
2021-07-06 18:55:34 -07:00
Anri Dellal d764b0de58
bootimg_analyze: Add support for boot header version 3 (MR 2073) 2021-07-07 04:43:24 +03:00
Clayton Craft 9d22989a88
kconfig: add missing options for nftables support to kconfig check (MR 2076)
I missed these when collecting the required kconfig options for
nftables, and it was a happy coincidence that the kernels I enabled the
nftables stuff on already had these enabled so that the initial kconfig
check passsed

test/kconfig: add missing nftables options
2021-07-07 04:24:07 +03:00
Newbyte 73d242485a
pmbootstrap.py: Don't print stacktrace when KeyboardInterrupt is caught (MR 2078)
This looks obnoxious and I cannot think of a single time I found it
useful, so let's make it prettier.
2021-07-05 12:19:35 +02:00
Oliver Smith 8a371cd18f
CI: remove stages (MR 2080)
It's more annoying than useful to have to wait for the first stage
before the second stage (pytest) starts. I'd rather have the whole
pipeline run through quicker and see if there are python errors too even
if linting errors are not resolved yet.

In pmaports.git this makes more sense: there we have "lint" and "build"
and in the worst case "build" may take up to three hours. So it makes
sense to only start it if there are no cosmetic errors. But that's not
the case here.
2021-07-04 22:51:54 +02:00
Oliver Smith 6c2b72ca13
CI: .gitlab/vermin.sh -> .ci/vermin.sh (MR 2080) 2021-07-04 22:51:53 +02:00
Oliver Smith d7e22e4993
CI: check_mr_settings: use version from ci-common (MR 2080) 2021-07-04 22:51:53 +02:00
Oliver Smith d38bd6be2b
CI: drop support for cached venv + ci runner (MR 2080)
CI started failing with:
/builds/ollieparanoid/pmbootstrap/venv/bin/python3: No module named pytest

I've briefly tried to fix this with the existing scripts. However,
instead of investing more time into that, do the long overdue
refactoring of the scripts that involve dropping the venv logic and
support for a custon gitlab-ci-runner using some python docker image as
base. This configuration hasn't been used for a long time and is
probably broken anyway.

Refactor the logic to skip the qemu test case in gitlab CI by using
pytest markers. The new script is now similar to bpo's .ci/pytest.py.
2021-07-04 22:51:53 +02:00
Maxim Karasev 3d651af763
README: update requirements (MR 2077)
Alpine no longer provides linux-hardened, and also no additional
packages are required to run pmbootstrap on Alpine.
2021-07-02 04:06:49 +03:00
Maxim Karasev 90529a0518
CI: don't install procps (MR 2077)
After MR 2074 it's not a hard-dependency anymore.
2021-07-02 04:06:13 +03:00
Maxim Karasev 479b51cfb6
CI: use Alpine for testing (MR 2074) 2021-06-28 02:07:55 +03:00
Maxim Karasev 1bb15765ed
pmb.helpers.run_core.kill_commands: use minimal subset of ps parameters (MR 2074)
again, busybox ps supports only -o option (-e is ignored, because
busybox always shows all processes).
2021-06-28 02:07:55 +03:00
Maxim Karasev 31e7a0006d
pmb.helpers.other.folder_size: use kilobytes (MR 2074)
busybox du doesn't support bytes or custom block sizes.
2021-06-28 02:07:55 +03:00
Anri Dellal 5c1da79634
pmbootstrap init: Add mirror choice (MR 2035)
Allows user to choose one of the mirrors from
https://mirrors.postmarketos.org.

Example:
[1] Mirror 1 (Location 1)
[2] Mirror 2 (Location 2)
[3] Mirror 3 (Location 3)
Select a mirror [1]: 2

Co-Authored-By: Alexey Min <alexey.min@gmail.com>
2021-06-27 18:38:01 +02:00
Alexey Min c5bd07e3ae
pmb.helpers.http: add missing parameter doc (MR 2035) 2021-06-27 18:37:57 +02:00
Dylan Van Assche 834cc7f877
install: allow to use last block for embedding (MR 2069)
Devices such as ODROIDs have binaries use which every single block for
embedding. Do not raise an error when binaries are touching, but not
overlapping, each other when embedding these binaries during installation.

Add a test for this scenario, which fails when reverting the change.

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2021-06-26 20:11:42 +02:00
Dylan Van Assche e900ee169a
install: refactor embed_firmware and add test (MR 2069) 2021-06-26 20:11:36 +02:00
Clayton Craft 31e36e195c
install: explicitly install osk-sdl when needed (MR 2066)
This adds osk-sdl to the rootfs when --fde is set, or when building a
rootfs for the ondev installer. Ideally the ondev installer would
selectively install osk-sdl if the user opted for fde at runtime, but
I haven't found a straight forward way to enable that yet, and this
behavior here is no different than the current behavior (where osk-sdl
is always installed in the rootfs by way of depends= in pmos-mkinitfs).

For images that are built without --fde, osk-sdl won't be installed at
all in the rootfs, once the dependency is dropped from pmos-mkinitfs.
Instead, a dummy package postmarketos-base-nofde will be installed
instead to satisfy the dependency that postmarketos-mkinitfs has on the
virtual package "postmarketos-fde-unlocker"
2021-06-25 12:28:36 -07:00
Clayton Craft 6afd35eb11
kconfig check: add support for checking zram options (MR 2075)
Device kernels that enable zram support can use `pmb:kconfigcheck-zram`
to protect against kconfig regressions that disable support for zram.
2021-06-23 21:17:41 -07:00
Alexey Min 687807fa73
Add kconfig check for containers (MR 2060)
Usage: pmbootstrap kconfig check --containers linux-postmarketos-qcom-msm8974
2021-06-23 01:12:47 +02:00
Oliver Smith 716336e30b
kconfig check: allow range of kernel versions (MR 2060)
Make it possible to specify rules as range, e.g. ">=4.0 <5.0".
2021-06-23 01:12:43 +02:00
Martijn Braam 475377fbfc
Prepare 1.34.0 release
* Update so v21.06 can be built
2021-06-20 11:02:04 +02:00
Clayton Craft 76489653df
helpers/envkernel.sh: fix shellcheck disabled tests (MR 2072)
Shellcheck 0.7.2 has a change that gives many error conditions their own
SC30** codes, instead of including them in SC2039. This updates the
scripts in this package that "disable SC2039" to disable the new code.

New codes added in shellcheck: cfd68ee0c2ebfd0ab08a1d4bf628162b454dc207

[ci:skip-build] already built successfully in CI
2021-06-18 20:22:31 -07:00
Oliver Smith 5afc2e626f
pmb.config.apk_tools_min_version: add alpine v3.14 2021-06-16 22:15:49 +02:00
Oliver Smith 53dfe85956
Prepare 1.33.0 release 2021-06-15 00:09:42 +02:00
Alexey Min fbffee3645
test: fix crossdirect rust test (MR 2071)
Currently running test_crossdirect locally may fail if selected device
does not exist on stable branch. Fix it by switching to qemu-amd64 before
running this test.

While at it, switch to more recent stable branch, v20.05 is now
unmaintained.
2021-06-14 23:07:03 +02:00
Clayton Craft f8fa80e20e
install: add --no-firewall / print firewall status (MR 2042)
The option, --no-firewall, will disable nftables on boot in the image,
and print a warning message if it's being disabled in a device image
where the device's kernel should support running the firewall.

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2021-06-14 21:51:36 +02:00
Anri Dellal 21c9e38162
kconfig: Refactor check_config (MR 2042)
Support force-checking multiple components. Fixes #2034.

Co-Authored-By: Clayton Craft <clayton@craftyguy.net>
2021-06-14 21:50:56 +02:00
Clayton Craft 599d74ec25
kconfig check: add support for nftables (MR 2042) 2021-06-14 21:50:45 +02:00
Alexey Min df9c61a868
pmb.config.aportgen_mirror_alpine: use working mirror (MR 2067)
The dl-2 mirror is missing required .apk files now.
Use dl-4 instead.
2021-06-13 23:49:55 +02:00
Antoine Fontaine c30540d13c
README: add some documentation on how to run tests (MR 1973) 2021-06-13 17:43:51 +02:00
Luca Weiss b18281ab26
pmb.aportgen: fix architecture autocomplete (MR 2054)
Previously hitting the tab key wouldn't actually complete the
architecture field.
2021-06-13 15:05:27 +03:00
Luca Weiss edf43916a5
pmb.aportgen: don't suggest armhf (MR 2054)
New ports shouldn't use that architecture; and devices whose CPU only
supports armhf aren't really useful for anything anyways.

This will also make the suggested/default architecture be armv7
(architectures[0]).
2021-06-13 15:05:27 +03:00
Alexey Min 21b9449813
test/test_helpers_package: use armv7 instead of armhf (MR 2054) 2021-06-13 15:05:27 +03:00
Clayton Craft 80cc09a84d
test/aportgen_device_wizard: use armv7 in test instead of armhf (MR 2054)
armhf isn't valid for new devices anymore
2021-06-13 15:05:24 +03:00
Alexey Min 4a8fac6c6e
pmb.aportgen: use correct arch for gcc aportgen (MR 2068)
Previously it always used native (x84_64) arch for apkindex
version check.

As pmb.aportgen.core.alpine_apkindex_path() already has arch
parameter, use it to look up correct APKINDEX.

Also fixup test.
2021-06-13 02:17:28 +03:00
Clayton Craft aa2c740810
config: fix config file path when XDG_CONFIG_HOME is set (MR 2065)
fixes a regression from f3b3fe906 where the file name was not being
appended to the path in the case where `XDG_CONFIG_HOME` was set.
2021-06-06 23:41:40 -07:00
Caio Fontes 1704851468
test/static_code_analysis.sh: update E501 check (MR 2058)
Change from checking some files for E501 to excluding some files from
checking.
2021-06-06 19:21:31 +02:00
Caio Fontes 27746db188
enforce E501 in test/ (MR 2058) 2021-06-06 19:21:31 +02:00
Caio Fontes f3b3fe906b
enforce E501 in pmb/config (MR 2058) 2021-06-06 19:21:31 +02:00
Caio Fontes fb98ad5329
enforce E501 partially in pmb/aportgen (MR 2058) 2021-06-06 19:21:31 +02:00
Caio Fontes cfa5bc2cf7
enforce E501 in pmb/flasher (MR 2058) 2021-06-06 19:21:30 +02:00
Caio Fontes aaece05bb7
enforce E501 in pmb/__init__.py and pmb/qemu (MR 2058) 2021-06-06 19:21:30 +02:00
Caio Fontes 039552f5b7
enforce E501 in pmb/helpers (MR 2058) 2021-06-06 19:21:30 +02:00
Caio Fontes 2b8efb996b
enforce E501 in setup.py (MR 2058) 2021-06-06 19:21:25 +02:00
Caleb Connolly e27bb82252
allow detecting when in chroot (MR 2063)
Touch the file /in-pmbootstrap in chroots so that we can avoid
performing automated actions that should only happen on a real device
(like flashing the kernel).
2021-06-04 15:01:00 -07:00
Caleb Connolly 7145ab2e50
config: add deviceinfo_flash_kernel_on_update (MR 2061)
Add new deviceinfo variable to explicitly support flashing the new
kernel when updated on Android devices.
2021-06-03 01:32:36 +02:00
Oliver Smith b0a49a72b7
pmb.parse.bootimg: adjust to new mkbootimg-osm0sis (MR 2062)
Adjust to mkbootimg-osm0sis 2021.04.27, where the output files have been
renamed:
	"use correct output names matching mkbootimg args
	 (zImage=Image.gz=kernel, ramdisk.gz=ramdisk)"

Related: 5a01ae54a9
2021-06-03 01:13:55 +02:00
Oliver Smith 0e2c3a853e
envkernel.sh: fix integer compare used for string (MR 2059)
Prevent stricter shells from crashing there if
$POSTMARKETOS_ENVKERNEL_ENBALED is an empty string. It was reported that
it crashes in ksh93, and busybox sh also complains about it.
2021-05-29 12:23:38 +02:00
Robin de Rooij 1ea0ce6ef4
Remove unnecessary symlink (MR 2057)
In the new initramfs creation for Nvidia blob files, we
move the newly created blob to be the normal boot image.
Therefore, no seperate boot image exists, it just overwrites
the old one and does not need a seperate symlink.
2021-05-19 23:57:32 +02:00
Oliver Smith 1481e69981
pmb.aportgen.binutils: adjust to subpackages in if (MR 2048)
Adjust the code so subpackages="" stays empty even with the latest
version of Alpine's APKBUILD.
2021-05-19 22:15:36 +02:00
Oliver Smith 2a0128d48a
test/testdata/aportgen: update binutils APKBUILD (MR 2048)
Put Alpine's current binutils APKBUILD there, with the subpackages line
that currently breaks the generated pmaport.
2021-05-19 22:15:31 +02:00
Ignacy Kuchciński 4eba7f62b1
kconfig check: require DEVPTS_MULTIPLE_INSTANCES (MR 2051)
Check for CONFIG_DEVPTS_MULTIPLE_INSTANCES, as it's required by bwrap
and therefore flatpak and epiphany.

See pmaports!2145
2021-05-09 19:42:01 +02:00
Oliver Smith 0ea0ced7fd
build: make warning about rebuilt pkgs a -v msg (MR 2047)
Let warnings like the following not get displayed in the regular
pmbootstrap output anymore, only in 'pmbootstrap log' if -v / --verbose
was used. This message informs the user that a package's dependencies
are newer than the package itself. But the WARNING makes it sound like
this is something to be concerned about, whereas in reality this is
fine. In this example, postmarketos-mkinitfs has gotten a new feature /
fix after postmarketos-base and there's no need to rebuild
postmarketos-base.

  [18:02:59] WARNING: postmarketos-base depends on rebuilt package(s)
  postmarketos-mkinitfs (use 'pmbootstrap build postmarketos-base --force'
  if necessary!)

[skip ci] already built in CI, change is trivial
2021-05-09 01:05:33 -07:00
Luca Weiss c42cd93610
pmb.helpers.cli: set empty completer for no completion (MR 2055)
The default completer suggests files from the file system which we
really don't want here.
This can be tested with the 'Manufacturer' field for new devices.

Setting it to a custom lambda instead of None disables the completion
instead of using the default completer.
2021-05-09 00:52:50 -07:00
Oliver Smith 81dbabc1ed
Prepare 1.32.0 release 2021-05-02 20:48:32 +02:00
Oliver Smith 59736b601f
pmb.qemu.run: get rid of -show-cursor (MR 2053)
Qemu has been upgraded to 6.0.0 in Alpine edge. This version doesn't
only warn about -show-cursor, it refuses to start up with the option
set.

Fixes: issue 1995
2021-05-02 19:13:35 +02:00
Alexander Stillich caeb991af6
Fix abuild-keygen aborting because pmbootstrap does not supply a packager email to it (MR 2052)
[ci:skip-build] already built successfully in CI
2021-05-01 15:50:25 -07:00
Caio Fontes 5144195091
fix long lines (E501) in pmb/build (MR 2050) 2021-04-26 23:56:42 -03:00
Alexey Min 2b620a0fdd
pmb.sideload: support non-standard SSH port (!2046)
This can be used for example to sideload packages to
pmbootstrap's QEMU which is running on the port 2222
by default, as follows:

  pmbootstrap sideload --host localhost --port 2222 --user user <pkg>

This adds a `--port` parameter to sideload subcommand.
If not specified, port defaults to 22.
2021-04-25 21:04:49 +03:00
Mark Hargreaves 57c830c410
pmbootstrap qemu: change default frontend to GTK (MR 2044)
Fix issues occurring when using pmbootstrap qemu with proprietary
Nvidia drivers as well as mouse misalignment issues on Phosh UI.

Signed-off-by: Mark Hargreaves <clashclanacc2602@gmail.coM>
2021-04-25 13:28:45 +02:00
Oliver Smith 303e7cd648
Prepare 1.31.0 release
Require latest apk-tools, which fixes CVE-2021-30139.

Related: https://gitlab.alpinelinux.org/alpine/aports/-/issues/12606
2021-04-14 20:50:53 +02:00
Oliver Smith 8df7514b8e
install: verify pmaports branch supporting fs (MR 2011)
Do not attempt to install with a filesystem that is not supported by the
initramfs code in the checked out pmaports branch.

Previously we would have increased the pmaports.cfg version and require
that new version by pmbootstrap, however this will break compatibility
with release branches where we won't roll out this feature (v20.05).
Therefore don't change the version, but add a new
"supported_root_filesystems" key to pmaports.cfg, which defaults to
"ext4".

Related: https://postmarketos.org/pmaports.cfg
2021-04-11 20:10:28 +02:00
Bobby The Builder 807d7019f8
install: add --filesystem to handle ext4 or f2fs (MR 2011)
Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2021-04-11 20:10:28 +02:00
Bobby The Builder 958ecc6c72
install: add install_fsprogs (MR 2011)
Install specific filesystem tools right before they are needed, instead
of installing all filesystem tools that we might need beforehand. This
is in preparation to support f2fs.

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2021-04-11 20:10:24 +02:00
Mark Hargreaves f758812f64
pmbootstrap qemu: fix on systems with more than 8 CPUs (MR 2045)
Fix error when CPU count is more than 8 while emulating a non-native
platform:
  qemu-system-aarch64: Number of SMP CPUs requested (12) exceeds max CPUs supported by machine 'mach-virt' (8)

Signed-off-by: Mark Hargreaves <clashclanacc2602@gmail.coM>
2021-04-04 20:43:40 +02:00
Oliver Smith a440556a0a
pmb.build.menuconfig: fix for native arch case (MR 2041)
Don't try to install and use a cross compiler if none is needed.

Fixes: 2406597f ("menuconfig: use cross-compiler for configuration (MR 2023)")
2021-03-30 16:47:23 +02:00
Anri Dellal 88ec1d1106
pmb.chroot: fix E501, switch to f-strings (MR 2040) 2021-03-30 15:13:26 +02:00
Shubham Naik 87c7859b40
Enforce E501: Limit the line length to 79 for files in pmb/install (MR 2031)
Made changes to limit the line length in following files for #1986,
 - pmb/install/_install.py
 - pmb/install/blockdevice.py
 - pmb/install/losetup.py
 - pmb/install/partition.py

Added the above files in E501 flake8 command list.
Substitute f-string for string concatenation.
2021-03-30 14:51:53 +02:00
Oliver Smith a9e100ebcc
Prepare 1.30.0 release 2021-03-30 14:26:14 +02:00
Oliver Smith 03e9fb0570
pmb.config.init.boot_size: set to 256 MiB (MR 2037)
Increase the boot partition size from 128 MiB to 256 MiB, as we are
already close to reaching the current limit. By having twice the size,
it should be possible to have atomic replacements of all initramfs
related files.
2021-03-23 22:14:29 +01:00
MightyM17 c3526f3271
envkernel.sh: Add yaml-dev and g++ dependency. (MR 2039) 2021-03-23 12:41:32 +03:00
Luca Weiss 2406597f3c
menuconfig: use cross-compiler for configuration (MR 2023)
Not using the cross compiler for kconfig leads to some differences to
the actual compilation later.
2021-03-19 17:54:28 -07:00
Luca Weiss 29823eec3e
pmb.build._package: split out init_compiler function (MR 2023)
In preparation for using it outside of init_buildenv
2021-03-19 17:54:19 -07:00
Luca Weiss 485b81e96e
menuconfig: remove unused variable assignment (MR 2023)
The variable is set further down anyways.
2021-03-19 17:54:02 -07:00
Oliver Smith 278dfced61
Replace pmaports channels stable, stable-next (MR 2032)
Translate the pmaports channels "stable" to "v20.05" and "stable-next"
to "v21.03", so these have the same channel name as the pmaports.git
branch name.

The original plan was to switch the "stable" channel from the "v20.05"
branch to the "v21.03" branch when the release is done. However, now
that we are close to that, I'm realizing that this would not be useful.
It would lead to conflicts in the dir with locally built packages
(default: ~/.local/var/pmbootstrap/packages/$CHANNEL). And it would make
it awkward to go back to a previous branch (we may name it old-stable
for the time being, but what after that, old-old-stable?).
2021-03-18 18:58:13 +01:00
JuniorJPDJ 5c1c126647
kconfig edit: removed gconfig support (MR 2034)
alpine removed [1] support for libglade, which is needed for gconfig to work
[1] a2d7250043
2021-03-13 19:10:46 +01:00
JuniorJPDJ 2b17e6ab71
kconfig edit: nconfig support (MR 2034) 2021-03-13 15:31:19 +01:00
JuniorJPDJ 8db2ab71b2
kconfig edit: fix xconfig dependencies (MR 2034) 2021-03-13 15:05:15 +01:00
Martijn Braam ed0bbf6069
install: don't try to embed firmware in split images (MR 2033)
Split images have /dev/installp1 and /dev/installp2 but no
/dev/install to place the firmware, so it will actually create that file
in devfs where it might run out of space since it's only 1MB big
2021-03-12 16:52:15 +01:00
Oliver Smith af2b2b5933
install: output empty line before flash/sshd info (MR 2030)
Leave some visual space before the flashing and ssh daemon information
blocks, so they don't get overlooked by the user:

[12:50:31] *** (4/4) FILL INSTALL BLOCKDEVICE ***
[12:50:31] (native) copy rootfs_qemu-amd64 to /mnt/install/
[12:50:36]
[12:50:36] *** FLASHING INFORMATION ***
[12:50:36] Refer to the installation instructions of your device, or the generic install instructions in the wiki.
[12:50:36] https://wiki.postmarketos.org/wiki/Installation_guide#pmbootstrap_flash
[12:50:36]
[12:50:36] *** SSH DAEMON INFORMATION ***
[12:50:36] SSH daemon is disabled (--no-sshd).
[12:50:36]
[12:50:36] NOTE: chroot is still active (use 'pmbootstrap shutdown' as necessary)
[12:50:36] Done
2021-02-17 02:06:36 +01:00
Oliver Smith 2b2ede95e5
install: get rid of redundant suffix line (MR 2030)
It is already filled with the same value at the beginning of the
function.
2021-02-17 02:06:35 +01:00
Oliver Smith 5b01a18cba
install: add --no-sshd argument (MR 2030)
Allow to disable the sshd service in the target OS, and note at the end
of the installation whether sshd is enabled or not.
2021-02-17 02:06:35 +01:00
Michael Kupfer 94544b8435
Prevent RuntimeError if there is no module binfmt_misc (MR 2029)
In case the kernel is compiled with CONFIG_BINFMT_MISC=y,
there is no module but binfmt_misc is still mountable.
2021-02-13 21:58:42 +01:00
Oliver Smith 748d9ce2c7
pmb install: make invalid kernel message clear (MR 2027)
Change "configured" to "valid" in the error message:
  Selected kernel (mainline_modem) is not configured for device bq-paella.
  Please run 'pmbootstrap init' to select a valid kernel.

"configured" makes one think of "pmbootstrap init", but the valid
kernels are defined in the APKBUILD. Therefore I think "not valid" fits
better here.
2021-02-12 11:33:06 +01:00
Oliver Smith 1b67c11396
install --ondev: run setup_login for installer OS (MR 2026)
Run setup_login() while creating the installer OS too, in order to
disable passwordless root login.

Note that this may sound like a security flaw, but it isn't.
* setup_login already ran for the target OS, meaning after the
  installation is done, one is not be able to login as root without
  password
* root login without password was only possible via serial console (or by
  attaching a keyboard), not via SSH
* getting root rights via serial in the installer OS is actually desired
  for debugging, we add a debug user with sudo set up by default:
  https://wiki.postmarketos.org/wiki/On-device_installer#Debug_user

So even though this isn't a problem, disable it to avoid confusion.
2021-02-12 11:15:25 +01:00
Oliver Smith 7320caead0
test_parse_depends: adjust to hello-world bump (MR 2028)
Adjust to pkgrel bump of the hello-world package in pmaports. Of course
it would be best if the tests did not depend on specific versions in
pmaports.git, but as long as they do, we need to keep them in sync.
This fixes the currently failing CI.
2021-02-11 23:36:46 +01:00
nybbled 5f485b8ad3
pmb.aportgen: put dependencies on separate lines (MR 2024)
Generate APKBUILDs with dependencies sorted and placed one per line.
The dependency lists changed are
 - depends in pmb/aportgen/device.py
 - makedepends in pmb/aportgen/linux.py

Sort dependency lists in test/test_aportgen_device_wizard.py
assertions.
2021-02-10 00:08:22 +01:00
Luca Weiss df58d35e27
kconfig check: require TMPFS_POSIX_ACL (MR 2025)
See pmaports!1939 and pmaports#904.
2021-02-09 23:11:31 +01:00
Minecrell 7dc2e197d3
pmb: Introduce support for "unmaintained" devices (MR 2018)
Unmaintained devices are device packages that:
  - Are known to be broken in some way without an active maintainer
    who can investigate how to fix it, or
  - Have not received any updates for a very long time, or
  - Are discouraged from using because they are just intended for testing.
    An example for this are ports using the downstream kernel for devices
    which have a mainline port that is working quite well.

Unmaintained devices are still built by bpo (otherwise it would not make
sense to keep them), but they do not show up in "pmbootstrap init".
However, it is possible to manually select them by entering the name.
pmbootstrap will warn in that case.

Unmaintained packages should have a # Unmaintained: <reason> comment
in the APKBUILD, this comment is displayed in "pmbootstrap init"
so that the user knows why the device should not be used unless they
know what they are doing.
2021-02-05 00:39:16 +01:00
Minecrell 03b3b250a5
pmb.parse._apkbuild: Add function to parse maintainers of APKBUILD (MR 2018)
This can be used for CI checks in pmaports to ensure that:
  - Devices in main have >= 2 maintainers
  - Devices in community have at least one maintainer
2021-02-05 00:39:12 +01:00
Oliver Smith 552246b228
Prepare 1.29.2 release 2021-02-04 23:16:40 +01:00
Shubham Naik 684cb3e1fb
Enforce E501: Limit the line length to 79 for files in pmb/parse - part 2 (MR 2020)
Made changes to limit the line length in following files,
 - pmb/parse/bootimg.py
 - pmb/parse/depends.py
 - pmb/parse/kconfig.py
 - test/test_parse_depends.py

Added the above files in E501 flake8 command list.
Substitute f-string for string concatenation.
2021-02-04 22:54:00 +01:00
Shubham Naik d1fadba5b4
Enforce E501: Limit the line length to 79 for files in pmb/parse - part 1 (MR 2019)
Made changes to limit the line length in following files,
 - pmb/parse/_apkbuild.py
 - pmb/parse/apkindex.py
 - pmb/parse/binfmt_info.py
 - pmb/parse/deviceinfo.py
 - test/test_parse_apkbuild.py

Added the above files in E501 flake8 command list.
Substitute f-string for string concatenation.
2021-02-04 22:32:35 +01:00
Clayton Craft 4474927141
pmb/config: use uuu package from Alpine (MR 2021) 2021-02-03 09:03:01 -08:00
Alexey Min 69b7543243
pmb.chroot.shutdown: be more user friendly when unmounting SD card (MR 2012)
When unmounting SD card after `pmbootstrap install --sdcard=...`
it takes a lot of time for kernel to sync filesystem cache
before actual umounting happehs. This looks like pmbootstrap is
stuck, so before doing unmount print a message to inform user of
what's happening, in case `--sdcard` was used.
2021-01-30 23:13:26 -08:00
Oliver Smith bc51a1c605
pmb.config.mirror_alpine: use CDN again (MR 2016)
The CDN was disabled, as packages from there often resulted in 'BAD
signature' after Alpine's big musl-1.2 rebuild for 32-bit arches. This
was almost half a year ago, so the CDN should have recovered.

This reverts commit 78f43d254e.
2021-01-27 23:55:33 +01:00
Oliver Smith 34d6b3edb3
Prepare 1.29.1 release 2021-01-27 23:02:24 +01:00
Oliver Smith 69cd7895e2
pmb.config.apk_tools_min_version: support branches (MR 2015)
Support branches, so pmbootstrap won't fail if v20.05 is selected:
  ERROR: You have an outdated version of the 'apk' package manager installed
  (your version: 2.10.5-r1, expected at least: 2.12.1-r0).

Move the logic for this check to pmb.helpers.apk.check_outdated and
adjust the test.

This fixes the CI failure in test_crossdirect_rust, which uses the
stable channel. (My bad for not creating this patch earlier, while at
the same time explaining in the creating pmbootstrap release instructions,
that this minimum apk version should be adjusted.)
2021-01-27 22:05:25 +01:00
Oliver Smith e9947f42de
pmb.config.apk_tools_static_min_version: rename (MR 2015)
Remove "_static" from the variable name, as this version isn't just
used to compare apk-tools-static's version (used to set up chroot), but
also for regular apk-tools before entering chroots.
2021-01-27 22:05:20 +01:00
Martijn Braam 9d6e0ec4d8
Prepare 1.29.0 release 2021-01-27 15:14:51 +01:00
Oliver Smith 51c01f384f
pmb/install/format.py: fix too long line (MR 2008) 2021-01-27 15:01:57 +01:00
Oliver Smith 39ad7246f7
install: add comments: logic in postmarketos-ondev (MR 2008)
Add comments to two functions, that if they are changed, the logic also
needs to be updated in ondev-preapre-internal-storage.sh of
postmarketos-ondev.git.
2021-01-27 15:01:56 +01:00
Oliver Smith d9682be771
install --ondev: set boot label: pmOS_inst_boot (MR 2008)
With postmarketos-ondev >= 0.4.0, have a different label for the boot
partition in the installer OS, so the postmarketOS initramfs can find
the proper partition to boot. Even if the boot partition is available
twice (once installed on eMMC, once as part of installer OS on SD card).

pmOS_inst_boot instead of pmOS_install_boot because of character limit.
2021-01-27 15:01:55 +01:00
Oliver Smith 34f5a12c21
pmb.install: split get_ondev_pkgver to own func (MR 2008) 2021-01-27 15:01:54 +01:00
Oliver Smith b07ff9444c
pmb.install: add boot label arg to several funcs (MR 2008)
Allow to set a different label for the boot partition than "pmOS_boot".
2021-01-27 15:01:54 +01:00
Oliver Smith 7d1c8d29df
pmbootstrap qemu: add --second-storage (MR 2008)
Create a second storage to test installing from SD card to eMMC with the
on-device installer.
2021-01-27 15:01:53 +01:00
Oliver Smith 61f5c20ebb
pmbootstrap qemu: tweak resize_image messages (MR 2008)
Replace "rootfs" with generic image, because the function will be used
for a second storage too. Refer to IMAGE_SIZE, as it is shown in the
help output.
2021-01-27 15:01:52 +01:00
Dylan Van Assche dd61d57b0e
pmbootstrap install: support _pmb_groups (MR 2010) 2021-01-27 08:38:53 +03:00
Dylan Van Assche e357ee885e
install: create groups regardless of existing user (MR 2010) 2021-01-24 16:18:38 +01:00
Dylan Van Assche 8455c82eee
install.ui: move get_recommends to new file (MR 2010) 2021-01-24 16:18:33 +01:00
Oliver Smith 10abb10dcf
Prepare 1.28.0 release 2021-01-07 23:30:51 +01:00
Oliver Smith 1c791da482
treewide: bump copyright to 2021 2021-01-07 23:30:47 +01:00
Martijn Braam 3d00888f2e
pmb.install.file: remove in favor of packaged os-release (MR 1970)
Don't install /etc/os-release with pmbootstrap, this is handled by
postmarketos-base instead.
2021-01-07 15:28:50 +01:00
Henrik Grimler e14a823fda
envkernel.py: don't search for kbuild_out if _outdir is set (MR 2012)
Patch by Oliver, fixes https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2000
2021-01-07 16:21:45 +03:00
Oliver Smith 6a4f012bf9
pmb.run.qemu.install_depends: fix with v20.05 (MR 2009)
Don't try to install the recently split up packages if the pmaports
branch is based on Alpine 3.12.

Fixes: 61845c93 ("pmb.run.qemu.install_depends: add new depends (MR 2007)")
2021-01-02 11:23:51 +01:00
Oliver Smith 8e3196a42a
CI: enforce python 3.6+ with vermin (MR 2002)
Make sure that features requiring a higher python version don't sneak in
by accident.

It would be nice to add this to test/static_code_analysis.sh, so it is
easy to run it locally. But vermin is not packaged in Alpine right now,
and given that this should be a rather rarer error, it doesn't seem
worth the effort right now.

Run silently by default and only in verbose mode if there are errors,
because if vermin isn't silent, it will not just point out errors, but
describe required python versions for everything it sees. (Copied that
part from the bpo CI script, where I had used it as pre-commit hook as
it was stuck on 3.5 for some time.)
2020-12-22 00:33:08 -08:00
HenriDellal 196186df24
pmbootstrap init: add locale selection (MR 2004)
Adds a list of locales user can choose from on init step.
If locale isn't default, then "lang" package is installed
and LANG is changed to the chosen locale.
2020-12-21 08:30:08 +03:00
Oliver Smith 2247fc5aad
pmbootstrap install: add --ondev --no-rootfs (MR 1995)
Skip building the postmarketOS rootfs, and allow either installing a
pre-built pmOS rootfs, or even another operating system.
2020-12-19 13:41:23 +01:00
Oliver Smith 74d71c1b6c
pmbootstrap install: add --ondev --cp (MR 1995)
Allow to copy one or more files to the install chroot. It will be
possible to use this to put a non-pmOS image into the generated
installer OS.
2020-12-19 13:41:23 +01:00
Oliver Smith 2660360293
Prepare 1.27.0 release 2020-12-16 23:40:16 +01:00
Oliver Smith 61845c934b
pmb.run.qemu.install_depends: add new depends (MR 2007)
Alpine's qemu packaging has been split up into more subpackages, so
install them too.

Related: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/15554
2020-12-16 23:20:51 +01:00
Oliver Smith c140912eed
pmb.run.qemu.install_depends: put each on new line (MR 2007) 2020-12-16 23:20:50 +01:00
Oliver Smith a9d4ba32a2
cli: --details-to-stdout: no progress bars (MR 2007)
Hide progress bars if --details-to-stdout is used, which redirects all
output that would land in the pmbootstrap log to stdout. This caused the
progress bar output to get mixed with the apk output. A new progress bar
would get drawn whenever a new package was installed, without removing
the previous progress bar.
2020-12-16 23:20:46 +01:00
Johannes Marbach 1eac61bcf7
Add option to run sudo -v in a loop to prevent repeated password entries (MR 1997)
Many of pmbootstrap's actions require root rights. When after requesting
sudo access pmbootstrap takes longer than the sudo timeout interval to finish
execution, the password will have to be entered again on the next sudo
action.

This change adds an opt-in feature to run sudo -v in a background loop
in order to prevent having to enter the password more than once for a single
pmbootstrap run. The loop runs as a daemon timer which automatically gets
canceled when pmbootstrap exits.

Closes: #1677
2020-12-14 19:14:14 +01:00
Johannes Marbach 8842a7d5c0
pmb.helpers.run_core: change kill_as_root to sudo (MR 1997)
Replace the "kill_as_root" argument with a much simpler "sudo" argument
and remove the now obsolete check for the output mode of "kill_as_root".

"kill_as_root" would only get set to True if both conditions are met:
a) command is running with sudo
b) command is running with an output mode ("log" or "stdout") where
   pmb.helpers.run_core would kill it if it does not output anything
   before a timeout is reached

The new "sudo" argument just indicates if the command is running with
sudo (a), regardless of the output mode (b).
2020-12-14 19:08:07 +01:00
Martijn Braam 27127f1cae
pmb.build._package: Clean up and expand documentation (MR 2003)
Fix typo introduced in earlier commit and expand on force=True behavior
2020-12-09 16:24:54 +01:00
Martijn Braam 1921fc5f27
Add sideload command
The sideload command runs the supplied names through the pmbootstrap
buildsystem to make sure they're up-to-date, then uses scp from the host
to copy the built apks to /tmp on the phone and installs them through
ssh.

If the --install-key option is set then it will also copy over the apk
key that's used for signing the packages built by pmbootstrap in case
the postmarketOS install on the device isn't build by the same machine
as you're sideloading from.
2020-12-08 17:42:30 +01:00
Oliver Smith 5cbde81842
pmbootstrap install: properly count install steps (MR 1978)
Get rid of hardcoded step numbers, even for the currently common steps.
With the upcoming --ondev --no-rootfs, we will need to skip the
hardcoded step 2 (create device rootfs).
2020-12-07 22:42:24 -08:00
Oliver Smith b6dce2486c
pmbootstrap install: new func create_device_rootfs (MR 1978)
Move related code from pmb/install/_install.py:install() to a new
create_device_rootfs() function in the same file, so it can be skipped
with the upcoming --no-rootfs parameter.
2020-12-07 22:42:24 -08:00
Johannes Marbach e058841709
pmb.helpers.repo: Show progress bar when downloading APKINDEX files (MR 1996)
Run pmbootstrap update to test
2020-12-07 12:41:28 +01:00
Johannes Marbach bbf0a70e5b
Add progress bar when running apk commands (MR 1996)
This adds a progress bar when running apk commands both inside and
outside of the chroot.

Closes: #1700
2020-12-07 12:41:28 +01:00
Johannes Marbach 705b71d89e
pmb.helpers.run_core: move error to extra func (MR 1996)
Extract the error check to a separate function so that it can be
reused.
2020-12-07 12:41:28 +01:00
Johannes Marbach 45dbeca587
pmb.helpers.run_core: add output=pipe (MR 1996)
This adds a new output mode "pipe" that is identical to the existing
"background" mode except for that its stdout is redirected into a
pipe so that it can be retrieved.
2020-12-07 12:41:28 +01:00
Johannes Marbach 82d149c85d
Make pmb.helpers.run.root support non-timeout output modes (MR 1996)
Before this commit, pmb.helpers.run_core.sanity_checks would raise
a runtime error when pmb.helpers.run.root was called with an output
mode that did not support timeouts (like background).
2020-12-07 12:41:28 +01:00
Johannes Marbach de175bfb1f
pmb.helpers.run_core.background: tweak log msg (MR 1996)
This makes the output mode apparent
2020-12-07 12:41:28 +01:00
Johannes Marbach 97a9633af4
pmb.chroot.root: set LANG=UTF-8 (MR 1996)
This makes apk use the pretty character for printing progress
2020-12-07 12:41:23 +01:00
Oliver Smith c7e7d24458
Prepare 1.26.0 release 2020-12-07 11:24:17 +01:00
HenriDellal 50cdf04760
kconfig check: add Samsung-specific options (MR 2000)
Adds checks for following kernel config options:
SAMSUNG_TUI:
    TUI HW Handler - related to Samsung's security measures
    Creates "secure frame buffer", results in bootloop
SEC_RESTRICT_ROOTING:
    blocks gaining root permissions
TZDEV:
    Samsung TZ Based Secure OS interface driver
    (results in bootloops)
2020-12-07 09:26:19 +01:00
Oliver Smith 2401423e2b
install: fix crash if /etc/skel is missing (MR 2001)
Create an empty home dir if /etc/skel does not exist in the target
rootfs. Due to changes in packaging, this can happen now, previously
/etc/skel would always have existed.
2020-12-07 09:06:59 +01:00
Alexey Min 799f4b925b
pmbootstrap status: fix typo
Closes #1991
2020-12-04 17:12:36 +03:00
Bart Ribbers 5b831d899d
Automatically mount binfmt_misc if not mounted already (MR 1923)
This is needed at least on Alpine Linux, and probably on distros like NixOS as well.

Fixes: https://gitlab.com/postmarketOS/pmbootstrap/-/issues/1135
2020-12-03 21:03:13 +01:00
HenriDellal e8e560e18e
kconfig edit: make package name a positional argument (MR 1998)
Makes argument "package" positional instead of required.
Uses codename from deviceinfo as default value.
2020-12-03 12:36:48 +03:00
HenriDellal 2d496d983e
pmb/aportgen/linux.py: Fix bad substitution error (MR 1999) 2020-12-02 21:32:43 +03:00
Oliver Smith 7683b80541
pmb/parse/arguments.py: refactor 'install' args (MR 1977)
Move the numerous "install" arguments into an own function (as it was
done with actions added later). Categorize the options and update the
help output, so the options are easier to understand.
2020-11-23 20:35:40 +01:00
Oliver Smith a1d9f66d96
install: embed_firmware: use correct suffix (MR 1979)
Embed the firmware from the right chroot suffix. Previously it would
always use the rootfs_{args.device} chroot, which does not work anymore
with upcoming 'pmbootstrap install --ondev --no-rootfs' as there will
only be the installer_{args.device} chroot.
2020-11-23 20:20:40 +01:00
HenriDellal 6793612a7e
pmb/aportgen/linux.py: add different QCDT implementations (MR 1992)
Adds QCDT templates for Spreadtrum and Exynos SoCs
When "pmbootstrap init" is executed, after the boot image analysis,
if the device is QCDT, then the user is asked about the SoC vendor.
Example:
[HH:MM:SS] SoC vendor (spreadtrum/exynos/other) [other]: exynos
After that, the corresponding template is picked.
2020-11-23 11:48:19 +01:00
Oliver Smith 5ff0bbe4b2
test/static: enforce E501 length check iteratively (MR 1993)
Enforce the E501 length check of max 79 characters for all files where
this test passes already. We can add more to the list as we adjust them
and eventuelly require the check for all files.
2020-11-23 11:31:57 +01:00
Johannes Marbach e2d4678fb7
pmb.aportgen.device Reformat to 79 characters per line (MR 1993) 2020-11-23 11:30:56 +01:00
Johannes Marbach 1e51376b7f
pmb.helpers.aportupgrade Reformat to 79 characters per line (MR 1993) 2020-11-23 11:30:56 +01:00
Johannes Marbach fc7e39d301
pmb.parse.arguments Reformat to 79 characters per line (MR 1993) 2020-11-23 11:30:51 +01:00
Oliver Smith 383bad9e93
Prepare 1.25.0 release 2020-11-23 10:13:36 +01:00
Oliver Smith 20aa4a01a1
install: FDE: use /dev/random, not /dev/urandom (MR 1994)
Change 'cryptsetup luksFormat' arguments to use --use-random instead of
--use-urandom. urandom is not recommended for the generation of long-term
cryptographic keys, as it may generate weak keys in low entropy
situations.
2020-11-23 08:57:09 +01:00
Johannes Marbach 74931b9b93
install: fix CREATE DEVICE ROOTFS message (MR 1991)
This converts the 1st step message to use a format string as well and
fixes two small typos in the 2nd step message.
2020-11-20 11:48:33 +01:00
Johannes Marbach 751524b5b4
install: tweak flash information output (MR 1991)
This adds generic advice when no flashing method is configured and
remove deprecated angle brackets.

Closes: #1948
2020-11-20 11:48:33 +01:00
Johannes Marbach ed2175546c
install: print_flash_info: make non-step (MR 1991)
This doesn't actually do anything else besides printing
advice so it doesn't need to be a processing step.
2020-11-20 11:48:33 +01:00
Johannes Marbach c31bf38409
install: install_recovery_zip: add step args (MR 1991)
This replaces the inline step numbers with arguments passed down
from the install method.
2020-11-20 11:48:33 +01:00
Johannes Marbach 126a299c43
install: install_system_image: no step defaults (MR 1991)
With the default argument values removed, the step logic is more
centralized in the install method which makes the code a bit less
brittle and easier to follow.
2020-11-20 11:48:33 +01:00
Johannes Marbach 5dea31058d
Add option to specify extra free space in pmbootstrap init (MR 1989)
This adds a new commandline flag -E / --extra-space for
specifying the amount of additional space to be added to
the image size to work around cases where the automatically
determined size turns out to not actually be enough.

The value is also asked for in the "Additional options"
section of the interactive mode.

Fixes: #1904
2020-11-17 20:07:01 +01:00
Luca Weiss e6543332de
pmb/config/__init__.py: parse more APKBUILD attributes (MR 1990)
This will be required for an upcoming CI test
2020-11-16 21:46:43 +01:00
Oliver Smith fe6db08069
Prepare 1.24.0 release 2020-11-11 11:10:01 +01:00
Oliver Smith 108ed0f28b
pmbootstrap install: fix cryptsetup warning (MR 1984)
Create /run/cryptsetup before running "cryptsetup luksFormat" to fix:
	WARNING: Locking directory /run/cryptsetup is missing!
2020-11-11 10:43:26 +01:00
Oliver Smith 06d91897da
pmb/install/format.py: refactor luks related code (MR 1984)
format_and_mount_root() => format_luks_root():
* Rename to reflect what it's actually doing
* Move the FDE check from format_luks_root to the only caller
* Make arguments to "cryptsetup luksFormat" more readable

format_and_mount_pm_crypt() => format_and_mount_root():
* Rename to reflect what it's actually doing
* Don't overwrite device if doing FDE; instead provide the proper device
  in the caller

The old function names were for historic reasons, early on it was only
possible to create encrypted installations with pmbootstrap.
2020-11-11 10:43:21 +01:00
Oliver Smith 77a5dd1910
pmb.aportgen.linux: add gcc10 extern YYLOC patch (MR 1987)
Most downstream kernels need this patch to build with GCC-10, so add it
by default in the linux aport generator.
2020-11-10 12:06:36 +01:00
timbz 5e01477d64
test: add deviceinfo kernel suffix parsing (MR 1986)
Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2020-11-10 09:15:52 +03:00
timbz d0b32b3b05
pmbootstrap deviceinfo_parse: new action (MR 1986)
Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
2020-11-10 09:15:52 +03:00
Oliver Smith 4d3c14f6c1
flasher: heimdall-isorec: use kernel+dtb (MR 1986)
Use the dtb-appended kernel file, e.g. postmarketos-exynos4-dtb instead
of postmarketos-exynos4, if it is available. This is needed to flash a
mainline kernel with appended dtb to isorec devices.
2020-11-10 09:15:51 +03:00
Oliver Smith ac796121e2
pmb.flasher.run: proper check for None (MR 1986)
Change the 'not value' condition raising the '...value for this variable
is None!' error to 'value is None' so it doesn't raise when the value is
something else that evaluates to boolean False, like an empty string.

Remove the special treatment for $KERNEL_CMDLINE here by making it
default to empty string.
2020-11-10 09:15:51 +03:00
Oliver Smith fae2379d6b
pmb.parse.deviceinfo: parse kernel suffix (MR 1986) 2020-11-10 09:15:49 +03:00
Eyal Sawady 741b0f298f
pmbootstrap log: don't depend on non-POSIX getopt (MR 1988)
Signed-off-by: Newbyte <newbie13xd@gmail.com>
2020-11-09 14:29:25 -08:00
Oliver Smith 173f90d796
Support arch="" in APKBUILD to skip builds (MR 1985)
Alpine indicates with arch="", that a package should temporarily not be
built for any architecture. Support this in postmarketOS too by not
complaining in the APKBUILD parser if arch is empty.

Adjust pmb.build.autodetect.arch and pmb.build.menuconfig.get_arch, so
both don't fail with an IndexError when encountering a disabled package.

Co-Authored-By: Luca Weiss <luca@z3ntu.xyz>
2020-10-30 17:33:33 +01:00
Oliver Smith 112e72b068
menuconfig: refactor get_arch() (MR 1985)
Simplify the logic by not even calling get_arch() if args.arch is set.
2020-10-30 17:33:33 +01:00
Oliver Smith e43ef5c22e
menuconfig: don't require --arch to match APKBUILD (MR 1985)
Do not verify that the architecture passed with --arch is part of the
arch variable in APKBUILD. This prepares to set 'arch=""' to temporarily
disable building packages. Users will still be able to run "pmbootstrap
menuconfig" on them by manually specifying the architecture.
2020-10-30 17:33:33 +01:00
Oliver Smith 13b96df350
pmbootstrap install: refactor: install_pkgs block (MR 1981)
Put all install_packages related lines into one block and fix up the
comments:
* The list of packages to be installed is not listed at this point (and
  it does not make sense there, if we would want to list it, it should
  be done in the next block at 'if args.build_pkgs_on_install).
* Remove "including the ones specified by --add", as it doesn't add any
  value.
2020-10-27 17:56:46 +01:00
Oliver Smith 340329599b
pmbootstrap install: refactor: move set_user() up (MR 1981)
Don't have the set_user() call weirdly between multiple commands
building the install_packages list. Move it up, together with the log
message announcing that the device rootfs is being built.

Update the comment above set_user(): there is no 'build' user anymore,
and at this point we only call it before actually installing the
packages for legacy reasons.
2020-10-27 17:56:46 +01:00
Oliver Smith fc1ba9ba7b
pmbootstrap install: don't screw up /etc/apk/world (MR 1981)
Do not attempt to upgrade packages in the rootfs chroot when running
"pmbootstrap install".

This was responsible for placing every single package in /etc/apk/world
(which should only hold the packages explicitly installed), because the
upgrade function was literally implemented as getting a list of
installed packages and explicitly running pmb.chroot.apk.install on each
of them. The intention was to rebuild these packages if they were outdated,
I guess I didn't realize that this makes /etc/apk/world unusable when I
introduced this three years ago in 51bdc243 ("Properly rebuild/install
packages when something changed").

Remove pmb.chroot.apk.upgrade altogether, because:
1) pmb.install.install builds and upgrades outdated pmaports
2) pmb.install.install is the only user of pmb.chroot.apk.upgrade
3) 'pmbootstrap init' is warning that the chroots do not get upgraded
   automatically, so let's not go against that expectation. users who
   want an updated rootfs chroot can simply run zap and install again.

Replace it with a call to pmb.helpers.repo.update, because we still need
to update the APKINDEX files before attempting to build/install the
generated list of packages.
2020-10-27 17:56:45 +01:00
yarl 864469531c
pmbootstrap qemu: add aarch64 big/little hack (MR 1983)
Workaround for qemu failing with:
  kvm_arm_vcpu_init failed: invalid argument.

Related: https://bugs.linaro.org/show_bug.cgi?id=1443
2020-10-20 22:34:08 +02:00
Oliver Smith 3f10399db3
pmbootstrap log: use tail -F, not -f (MR 1982)
Let tail attempt to open the file again, if it becomes inaccessible.
This is useful, when writing a reproducer that deletes pmbootstrap's
log.txt while at the same time running 'pmbootstrap log'.

(027724) [17:57:34] Done
tail: '/home/user/.local/var/pmbootstrap/log.txt' has become inaccessible: No such file or directory
tail: '/home/user/.local/var/pmbootstrap/log.txt' has appeared;  following new file
(003493) [17:57:35] % cd /home/user/.local/var/pmbootstrap/cache_git/pmaports; git remote -v
2020-10-07 20:50:14 +02:00
Oliver Smith 496be6f593
Prepare 1.23.0 release 2020-09-24 11:20:42 +02:00
Oliver Smith 0dfe489b78
pmbootstrap aportgen: replace arch=all with native (MR 1965)
Packages like binutils-*, busybox-static-*, gcc-*, grub-efi-*, musl-*
are only needed for the native architecture during cross compilation.
Don't bother with trying to build them for other arches to save time and
to avoid getting stuck frequently at "armv7/binutils-aarch64" etc.

A few people like to use pmbootstrap on aarch64 hosts (e.g. PineBook
Pro), so let's make it available for aarch64 again when we can build
aarch64 packages natively in CI and bpo. (They do get stuck there right
now, because of qemu user emulation.)

Related: https://gitlab.com/postmarketOS/build.postmarketos.org/-/issues/75
2020-09-21 17:48:34 +02:00
Oliver Smith 5b55abd4d2
pmbootstrap aportgen: don't use CDN alpine mirror (MR 1963)
Use a deterministic mirror URL instead of CDN for aportgen. Otherwise we
may generate a pmaport that wraps an apk from Alpine (e.g. musl-armv7)
locally with one up-to-date mirror given by the CDN. But then the build
will fail if CDN picks an outdated mirror for CI or BPO.
2020-09-18 03:20:25 +03:00
Oliver Smith a870a69151
pmbootstrap kconfig edit: list all arches in error (MR 1957)
If a kernel is available for multiple architectures, let the user know
which architectures are available in the error message.
2020-09-16 21:38:16 +02:00
Luca Weiss 9815f81742
aportupgrade: use f-strings (MR 1964) 2020-09-16 20:31:31 +03:00
Luca Weiss 93f13277b9
aportupgrade: add support for specifying git ref (MR 1964)
This adds support for specifying an arbitrary git ref (e.g. commits,
tags, branches) to upgrade to. This can be useful if a specific commit
needs to be packaged instead of the latest available. Alternatively you
can also specify a branch to be used if the default branch is 'stable'
but 'develop' should be packaged.

This also removes old code to use the 'bionic' branch for UBports Lomiri
(formerly Unity 8) packages.
2020-09-16 20:31:04 +03:00
Henrik Grimler efd64f7714
Check if workpath/ is empty and in that case create workpath/version (MR 1975)
Fixes https://gitlab.com/postmarketOS/pmbootstrap/-/issues/1965
2020-09-14 19:01:19 +02:00
Antoine Fontaine 1b5120e24f
test/testcases_fast.sh: correct pmaports location (MR 1974)
This makes the script ask pmbootstrap what is the correct directory
instead of hardcoding the default value.
2020-09-12 10:35:37 +02:00
Linus Walleij be41c94c57
pmb.install.setup_keymap: Fix up keymaps for Nokia n900 (MR 1972)
The Nokia n900 XkbLayout is a bit peculiar and sometimes
join two keymaps into one, for example:

    Option "XkbLayout" "fise"

For the combined finnish/swedish layout. Add the common
joined keymaps, even if not all of these countries are
yet supported.

For details see:
https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/master/symbols/nokia_vndr/rx-51

I also include this link in the code so no-one gets confused.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-08-31 16:02:04 +02:00
Martijn Braam 5d540ad4fb
pmb/install: warn if the target disk is larger than expected (MR 1956) 2020-08-31 13:05:20 +02:00
Ralf Rachinger 72e24f7f96
Use $XDG_CONFIG_HOME instead of hardcoded path (MR 1969) 2020-08-23 13:51:42 +02:00
Luca Weiss 86d61b8012
pmb.parse.bootimg: detect mediatek header (MR 1955)
Some Mediatek devices have a special 512-byte header around the zImage
which must be generated so the device boots.

Support for that exists for a while in postmarketOS but detection was
missing. Add that.
2020-08-21 18:33:30 +02:00
Oliver Smith 9718fd294a
pmb.install.setup_keymap: fix fail on X11 setup (MR 1968)
Do not fail in "pmbootstrap setup" if a keymap was selected, but no
/etc/X11/xorg.conf.d path exists in the rootfs chroot. The grep output
is not empty in that case (it would be empty if the directory exists and
there are no matches), so we need to add this extra check:

	(rootfs_nokia-n900) % grep -rl XkbLayout /etc/X11/xorg.conf.d/
	grep: /etc/X11/xorg.conf.d/: No such file or directory
2020-08-12 01:16:09 +02:00
Oliver Smith e233b73949
pmb.config.mirrors_postmarketos: update URL (MR 1967)
Official pmOS binary package mirror is now mirror.postmarketos.org. The
old URL will stay functional as redirect.
2020-08-08 21:16:39 +02:00
Oliver Smith a498c3afab
Prepare 1.22.2 release 2020-08-05 11:02:08 +02:00
Oliver Smith 7c26c1e9e5
test_crossdirect_rust: run on stable channel (MR 1966)
This test is failing with Alpine edge, because x86_64 has a different
rustc version than armv7:
	found crate `std` compiled by an incompatible version of rustc

Run the test with the latest Alpine stable version instead, where it is
more likely that rustc has the same version across all arches.
2020-08-05 10:38:23 +02:00
Oliver Smith 554dbd73ba
pmb.chroot.apk_static.download: fix mirrordir (MR 1966)
When selecting the stable channel in "pmbootstrap init", do not attempt
to download apk-tools-static from the "edge" mirrordir. This stopped
working, because the version in the APKINDEX of v3.12 is different than
the one in edge now.

Fixes:
	Download http://dl-2.alpinelinux.org/alpine/edge/main/x86_64/apk-tools-static-2.10.5-r1.apk
	ERROR: HTTP Error 404: Not Found

Related: https://builds.sr.ht/~postmarketos/job/272760#task-pmbootstrap_build-123
2020-08-05 10:04:48 +02:00
Oliver Smith 505425491f
Prepare 1.22.1 release 2020-08-03 11:37:08 +02:00
Oliver Smith 78f43d254e
pmb.config.mirror_alpine: don't use CDN
Replace dl-cdn mirror with dl-2 temporarily to avoid "BAD signature"
errors.

This is related to the rebuild of Alpine edge x86, armhf, armv7 packages
against musl-1.2, that is currently going on. The packages are rebuilt
without a version change and therefore have the same resulting file
name, but a different checksum. Due to caching of the CDN and due to the
same file name, users may get an old package from before the rebuild.
The APKINDEX has a checksum of the new package, and so the download will
fail with a "BAD signature" error.

Alpine developers clear the cache every now and then, but this issue
will happen over and over again, until all packages are rebuilt (some
packages are still not rebuilt and have been disabled).

Let's switch back in two months or so.
2020-08-03 11:23:04 +02:00
Alexey Min aa88721b75
pmb.helpers.cli: fix TAB-completion of items with '-' (MR 1960)
Before this fix tab completion of names with hyphens were not done:
try for example to complete UI package name in 'pmbootstrap init' with
hyphen, like "plasma-mobile" / "plasma-desktop". Now this is handled
correctly (hyphen is not considered as delimeter).
2020-07-20 16:47:33 +02:00
Oliver Smith 44e099acc7
Prepare 1.22.0 release 2020-07-20 14:44:00 +02:00
Oliver Smith d8615a9cae
pmbootstrap install: support _pmb_recommends (MR 1962)
Let UI meta-packages specify apps in "pmb_recommends" to be explicitly
installed by default, and not implicitly as dependency of the UI
meta-package ("depends"). Therefore make these apps uninstallable,
without removing the meta-package.

Add pmbootstrap install --no-recommends to disable this feature.
2020-07-20 14:29:06 +02:00
Oliver Smith c8d581e749
pmbootstrap install --no-local-pkgs: new option (MR 1951)
Don't install locally compiled packages and package signing keys. This
will be used for the official images generated with pmbootstrap.
2020-07-15 16:47:51 +03:00
Oliver Smith 05849a9f80
pmbootstrap install: make building pkgs optional (MR 1951)
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 "build_pkgs_on_install". 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-07-15 16:47:43 +03:00
Mark Hargreaves 0aed64d661
pmb/helpers/frontend.py: fix pmbootstrap kconfig check --file (MR 1961) 2020-07-15 16:30:57 +03:00
Oliver Smith f9c74277ca
cpu_emulation_required: not for armv7 -> armhf (MR 1952)
Make it possible to build armhf packages on armv7 devices, e.g. to help
with stuck build-edge-armhf packages that won't build with qemu.
2020-07-14 22:42:55 +02:00
Pellegrino Prevete 95762a229a
pmb/config/__init__.py: add CONFIG_USER_NS (for bubblewrap/flatpak) (MR 1943)
Also fix tests
2020-07-14 23:19:50 +03:00
Oliver Smith ae21bc8615
Prepare 1.21.0 release 2020-07-11 16:24:15 +02:00
Oliver Smith 9bbe78328f
setup.py: change devel status: alpha -> stable
pmbootstrap is fairly stable now, time to let setup.py and pypi.org
reflect it.
2020-07-11 16:19:52 +02:00
Oliver Smith 1d6c382cf7
install --ondev: pass cipher to ondev-prepare (MR 1958)
Let postmarketos-ondev honor the cryptsetup cipher from pmbootstrap.
2020-07-11 13:25:15 +02:00
Oliver Smith 3b02d35f1d
install --fde --android-recovery-zip: show warning (MR 1958)
This is likely to fail with the new default cryptsetup cipher of
aes-xts-plain64, as many downstream kernels used in recovery OS (like
TWRP) do not have CRYPTO_XTS set.
2020-07-11 13:25:09 +02:00
Oliver Smith 05c013536d
pmb.config.cipher: set default to aes-xts-plain64 (MR 1958)
Replace aes-cbc-plain64 with the stronger cipher aes-xts-plain64.
CONFIG_CRYPTO_XTS is necessary for this, so require it in
"pmbootstrap kconfig check".

Related: https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions#5-security-aspects
2020-07-11 13:24:21 +02:00
Oliver Smith ec71670f20
pmb.config.necessary_kconfig_options: sort keys (MR 1958)
Sort keys alphabetically.
2020-07-11 13:24:09 +02:00
Oliver Smith b366b5004f
CI: disable pmbootstrap-qemu-tests
The machine that was running them is currently broken.

Related: #1943
2020-07-11 00:08:57 +02:00
Mark Hargreaves 4312160c96
pmb/parse/bootimg.py: fix file names after mkbootimg-osm0sis update (MR 1959) 2020-07-10 22:53:00 +03:00
Oliver Smith 324ea788ba
install --ondev: don't ask for user password (MR 1954)
With postmarketos-ondev 0.2.0, the password is set in the on-device
installer.
2020-07-01 00:19:49 +02:00
Oliver Smith 90f57bbbcc
install --ondev: set username to "user" (MR 1953) 2020-06-30 21:50:49 +02:00
Oliver Smith ea60aaa08c
install --ondev: add ondev_min_version (MR 1953)
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-30 21:50:43 +02:00
Oliver Smith e089d05a55
install --ondev: ondev-prepare: fix log msg (MR 1953) 2020-06-30 21:50:39 +02:00
Oliver Smith 6fb194795a
install --ondev: ondev-prepare: pass pmb ver, ui (MR 1953)
Pass the pmbootstrap version and user interface, so it can be checked /
displayed in postmarketos-ondev.
2020-06-30 21:50:35 +02:00
Oliver Smith f9f5640d82
install --ondev: ondev-prepare: use env vars (MR 1953)
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-30 21:50:19 +02:00
Oliver Smith 8a02187a1a
pmb/aportgen/grub_efi.py: fix distfile collisions (MR 1950)
Same fix as MR 1947, but for grub_efi.py instead of musl.py. While at
it, order the imports alphabetically.
2020-06-24 21:08:44 +03:00
Oliver Smith 460d2c0eb4
pmb/aportgen/grub_efi.py: alpine mirrordir (MR 1950)
On branch stable, we would use Alpine's mirrordir "v3.11" for example.
2020-06-24 21:08:44 +03:00
Oliver Smith a74aafb978
pmb/aportgen/grub_efi.py: pass apkbuild-lint (MR 1950) 2020-06-24 21:08:44 +03:00
Oliver Smith 2bb96184d0
pmb/aportgen/grub_efi.py: use f-string in APKBUILD (MR 1950) 2020-06-24 21:08:44 +03:00
Oliver Smith b4a205d4db
pmb/aportgen/busybox_static.py: fix distfile collisions (MR 1949)
Same fix as MR 1947, but for busybox_static.py instead of musl.py. While
at it, order the imports alphabetically.
2020-06-24 20:40:45 +03:00
Oliver Smith 178931f992
pmb/aportgen/busybox_static.py: alpine mirrordir (MR 1949)
On branch stable, we would use Alpine's mirrordir "v3.11" for example.
2020-06-24 20:40:38 +03:00
Oliver Smith f9f9e19a4c
pmb/aportgen/busybox_static.py: pass lint (MR 1949) 2020-06-24 20:40:26 +03:00
Oliver Smith 9639da22c9
pmb/aportgen/busybox_static.py: use f-string (MR 1949) 2020-06-24 20:40:18 +03:00
Oliver Smith 143b35408e
aportgen get_upstream_aport: checkout branch (MR 1948)
Checkout the aports.git branch for the current channel (e.g.
3.12-stable), before trying to find the APKBUILD.

I had tried to auto-unshallow the git repository earlier, but then the
tags were missing. I decided that it's not worth to provide a migration
path: "pmbootstrap aportgen" is only used by few advanced users (to
maintain the pmaports repo).
2020-06-24 20:16:55 +03:00
Oliver Smith a86669d521
pmb.helpers.git.clone: remove shallow option
This made sense for Alpine's aports.git repository as we were only using
the master branch. But now that we are using more branches, we need the
entire git repository with all its branches cloned.
2020-06-24 19:29:21 +03:00
Oliver Smith bfbb095895
pmb/aportgen/musl.py: fix distfile collisions (MR 1947)
Add the Alpine mirrordir (e.g. "edge", "v3.12") to the distfile, so
musl-*.apk files of the same version and arch but from different
mirrordirs do not collide.

Let "abuild checksum" download these apks and generate the checksums,
instead of letting apk download them as side-effect of initializing
foreign arch chroots. The latter did not work anymore, because we would
copy the apk file with a glob that may matches the hash of either mirrordir.
Essentially:
    glob.glob(f"{args.work}/cache_apk_{arch}/{subpkgname}-{version}.*.apk")[0]

In the context of the on-device installer, I found that calculating this
hash is not trivial, so let's just avoid it here as well.

While at it, order the imports of musl.py alphabetically.
2020-06-24 04:41:54 +03:00
Oliver Smith 4f7a13084f
pmb/aportgen/musl.py: use channel alpine mirrordir (MR 1939)
On branch stable, we would use Alpine's mirrordir "v3.12" for example.
2020-06-21 12:07:29 +02:00
Oliver Smith ac90787e76
pmb/aportgen/musl.py: pass 'pmbootstrap lint' (MR 1939)
Remove quotes around pkgname and pkgver, indent with tabs and provide
a stub for arch_to_hostspec.
2020-06-21 12:07:09 +02:00
Oliver Smith 37ee340166
pmb/aportgen/musl.py: use f-string in APKBUILD (MR 1939) 2020-06-21 12:07:05 +02:00
Oliver Smith 357c1acc82
test/test_aportgen.py::test_aportgen: armhf->armv7 (MR 1942)
Alpine's armhf edge build bot is stuck, so musl-1.1.24-r9.*.apk is
missing and the test fails. armhf is on it's way out, so replace it with
armv7.
2020-06-21 11:50:57 +02:00
Oliver Smith ea710caafe
pmb/aportgen/binutils.py: pass apkbuild-lint (MR 1942) 2020-06-21 11:50:57 +02:00
Oliver Smith 654cc56062
pmb/aportgen/core.py: no quotes around some keys (MR 1942)
Don't print quotes for pkgname, pkgver, pkgrel. This is required to pass
apkbuild-lint.
2020-06-21 11:50:57 +02:00
Oliver Smith c0b80b26b5
pmb.aportgen.core.rewrite: no lines with empty val (MR 1942)
Avoid apkbuild-lint errors like:
	[AL5]:APKBUILD:15:variable set to empty string
2020-06-21 11:50:52 +02:00
Oliver Smith ddb5d9ae2c
pmbootstrap install --ondev: new option (MR 1946)
Add initial support for the on-device installer in pmbootstrap. Let
pmbootstrap create a regular split image, then prepare a new installer
rootfs and copy the previously generated rootfs image into the installer
rootfs. Put the installer rootfs into a new image, with reserved space.

There is more to do from here, such as disabling the generation of the
user account when using --ondev. But this requires support in
postmarketos-ondev first, so let's build that iteratively.

Related: https://wiki.postmarketos.org/wiki/On-device_installer
Related: https://gitlab.com/postmarketOS/postmarketos-ondev/-/issues
2020-06-19 09:36:51 +02:00
Oliver Smith 8fb69f9c46
install_system_image: add sdcard argument (MR 1946)
The on-device installer will run install_system_image once with
sdcard=None and the second time with sdcard=args.sdcard.
2020-06-19 09:36:51 +02:00
Oliver Smith 718839364b
install_system_image: add split argument (MR 1946) 2020-06-19 09:36:51 +02:00
Oliver Smith 539108bbc4
install_system_image: add step, steps parameters (MR 1946) 2020-06-19 09:36:51 +02:00
Oliver Smith a56e4eae5a
install_system_image: add root_label parameter (MR 1946)
Prepare for on-device installer, so it can use something other than
"pmOS_root" as label.
2020-06-19 09:36:51 +02:00
Oliver Smith 7fb41641ea
install_system_image: add suffix argument (MR 1946)
Allow files to be copied from a different suffix than rootfs_$DEVICE.
The on-device installer will use this.
2020-06-19 09:36:51 +02:00
Oliver Smith 17e7edb254
Cosmetics: install_system_image(): remove FDE msg (MR 1946)
Full disk encryption (--fde) has not been the default for a long time,
so no need to warn the user about it.
2020-06-19 09:36:51 +02:00
Oliver Smith cd58efdbd7
pmb.install._install.print_flash_info: cosmetics (MR 1946)
Fix a typo and wrap lines at 80 characters (especially one extra long
line). Use f-strings in lines that were modified (as we're doing it
nowadays).
2020-06-19 09:36:51 +02:00
Oliver Smith a3fd169c76
pmb.install._install.print_flash_info: new func (MR 1946)
Move code that prints flashing information from install_system_image()
to its own function. For the on-device installer, we'll need to call
install_system_image() twice, without printing the flashing information
each time. While at it, add "step" and "steps" parameters.
2020-06-19 09:36:51 +02:00
Oliver Smith a97ec615ad
pmbootstrap install: support size_reserve (MR 1946)
Create an empty partition between boot and root. This will be used by
the on-device installer, as explained in detail here:
https://wiki.postmarketos.org/wiki/On-device_installer
2020-06-19 09:36:50 +02:00
Oliver Smith 5fbc95c3c2
Cosmetic: pmb.install.partition: fix comment (MR 1946) 2020-06-19 09:36:50 +02:00
Oliver Smith 2fc0794e30
pmb/install: have size_boot, size_root in MiB (MR 1946)
Prepare for a future patch, that adds reserved space in MiB, by changing
size_boot and size_root from bytes to MB everywhere. This is what we need
most of the time and allows to drop some /1024**2 statements.
2020-06-19 09:36:50 +02:00
Oliver Smith 63fc2b621a
pmbootstrap chroot --install-blockdev: new option (MR 1946)
Create /dev/install inside the chroot from a block device, just like
done during the installation. This is useful for testing the Calamares
installer.
2020-06-19 09:36:50 +02:00
Oliver Smith 00691a56ee
blockdevice.create_and_mount_image: add split arg (MR 1946)
Add a "split" argument to the function, instead of using "args.split"
directly. "args.split" is only defined when calling "pmbootstrap install",
but the next patch will add a code path that calls the function from
"pmbootstrap chroot".
2020-06-19 09:36:50 +02:00
Bhushan Shah 79409053ad ci: install pip as well 2020-06-17 13:34:59 +05:30
Minecrell 3ebb994206
pmb.parse: Respect provider_priority if multiple providers exist (MR 1945)
Alpine APKBUILDs have the concept of "provider priorities" that affect
the choice of the provider to install when multiple packages provide
a virtual package.

One use case for this is to allow installation of different firmware
versions. bq-paella can run unsigned firmware, therefore you have the
choice between using the original firmware from the manufacturer, or
a slightly newer version from Qualcomm for the Dragonboard 410c.

We add provides="firmware-qcom-msm8916-wcnss" (the "virtual package")
to both firmware-qcom-db410c-wcnss and firmware-bq-picmt-wcnss.
At this point, attempting to install "firmware-qcom-msm8916-wcnss"
would still fail with apk. (Because it does not know which provider
to install.)

To pick a default we can set e.g. provider_priority=100 for
firmware-qcom-db410c-wcnss (the slightly newer version).
In that case, firmware-qcom-db410c-wcnss should be installed by default.

However, the user can choose to do "apk add firmware-bq-picmt-wcnss"
to override the default choice in case of problems. In that case,
the conflicting firmware-qcom-db410c-wcnss will be automatically removed.

At the moment, pmbootstrap does not respect the "provider_priority" at all.
In the above case, it would always install "firmware-bq-picmt-wcnss"
during "pmbootstrap install" since that has the shortest name.

Extend the pmbootstrap code to pick a provider with the highest priority
(if any of the providers has a priority set).
2020-06-16 01:31:28 +03:00
208 changed files with 9800 additions and 4203 deletions

9
.b4-config Normal file
View File

@ -0,0 +1,9 @@
# Allow this repository to be used with the 'b4' tool. See
# https://postmarketos.org/patch-review for details.
[b4]
midmask = https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%s
linkmask = https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%%3C%s%%3E
send-series-to = ~postmarketos/pmbootstrap-devel@lists.sr.ht
send-endpoint-web = NONE
backend = sourcehut

26
.build.yml Normal file
View File

@ -0,0 +1,26 @@
image: alpine/edge
packages:
- sudo
sources:
- https://git.sr.ht/~postmarketos/pmbootstrap
tasks:
- note: |
pmbootstrap/.ci/note.sh
- shellcheck: |
cd pmbootstrap
sudo .ci/shellcheck.sh
- ruff: |
cd pmbootstrap
sudo .ci/ruff.sh
- vermin: |
cd pmbootstrap
sudo .ci/vermin.sh
- codespell: |
cd pmbootstrap
sudo .ci/codespell.sh
- pytest: |
cd pmbootstrap
sudo .ci/pytest.sh
artifacts:
- ".local/var/pmbootstrap/log.txt"
- ".local/var/pmbootstrap/log_testsuite.txt"

20
.ci/codespell.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh -ex
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2023 Oliver Smith
# Description: find typos
# https://postmarketos.org/pmb-ci
if [ "$(id -u)" = 0 ]; then
set -x
apk -q add \
py3-codespell
exec su "${TESTUSER:-build}" -c "sh -e $0"
fi
set -x
# -L: words to ignore
codespell \
-L crate \
-L hda \
.

6
.ci/note.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh -e
printf "\n"
printf "PROTIP: use"
printf " \e[1;32mpmbootstrap ci\e[0m"
printf " to run these scripts locally.\n"

72
.ci/pytest.sh Executable file
View File

@ -0,0 +1,72 @@
#!/bin/sh -e
# Description: run pmbootstrap python testsuite
# Options: native slow
# https://postmarketos.org/pmb-ci
if [ "$(id -u)" = 0 ]; then
set -x
apk -q add \
git \
openssl \
py3-pytest \
py3-pytest-cov \
sudo
exec su "${TESTUSER:-build}" -c "sh -e $0"
fi
# Require pytest to be installed on the host system
if [ -z "$(command -v pytest)" ]; then
echo "ERROR: pytest command not found, make sure it is in your PATH."
exit 1
fi
# Use pytest-cov if it is installed to display code coverage
cov_arg=""
if python -c "import pytest_cov" >/dev/null 2>&1; then
cov_arg="--cov=pmb"
fi
echo "Initializing pmbootstrap..."
if ! yes '' | ./pmbootstrap.py \
--details-to-stdout \
init \
>/tmp/pmb_init 2>&1; then
cat /tmp/pmb_init
exit 1
fi
# Make sure that the work folder format is up to date, and that there are no
# mounts from aborted test cases (#1595)
./pmbootstrap.py work_migrate
./pmbootstrap.py -q shutdown
# Make sure we have a valid device (#1128)
device="$(./pmbootstrap.py config device)"
pmaports="$(./pmbootstrap.py config aports)"
deviceinfo="$(ls -1 "$pmaports"/device/*/device-"$device"/deviceinfo)"
if ! [ -e "$deviceinfo" ]; then
echo "ERROR: Could not find deviceinfo file for selected device:" \
"$device"
echo "Expected path: $deviceinfo"
echo "Maybe you have switched to a branch where your device does not"
echo "exist? Use 'pmbootstrap config device qemu-amd64' to switch to"
echo "a valid device."
exit 1
fi
# Make sure pmaports is clean, some of the tests will fail otherwise
if [ -n "$(git -C "$pmaports" status --porcelain)" ]; then
echo "ERROR: pmaports dir is not clean"
exit 1
fi
echo "Running pytest..."
echo "NOTE: use 'pmbootstrap log' to see the detailed log if running locally."
pytest \
--color=yes \
-vv \
-x \
$cov_arg \
test \
-m "not skip_ci" \
"$@"

19
.ci/ruff.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh -e
# Description: lint all python scripts
# https://postmarketos.org/pmb-ci
if [ "$(id -u)" = 0 ]; then
set -x
apk -q add ruff
exec su "${TESTUSER:-build}" -c "sh -e $0"
fi
set -x
# __init__.py with additional ignore:
# F401: imported, but not used
# shellcheck disable=SC2046
ruff --ignore "F401" $(find . -not -path '*/venv/*' -name '__init__.py')
# Check all other files
ruff --exclude=__init__.py .

15
.ci/shellcheck.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh -e
# Description: lint all shell scripts
# https://postmarketos.org/pmb-ci
if [ "$(id -u)" = 0 ]; then
set -x
apk -q add shellcheck
exec su "${TESTUSER:-build}" -c "sh -e $0"
fi
find . -name '*.sh' |
while read -r file; do
echo "shellcheck: $file"
shellcheck "$file"
done

25
.ci/vermin.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh -e
# Description: verify that we don't use too new python features
# https://postmarketos.org/pmb-ci
if [ "$(id -u)" = 0 ]; then
set -x
apk -q add vermin
exec su "${TESTUSER:-build}" -c "sh -e $0"
fi
# shellcheck disable=SC2046
vermin \
-t=3.7- \
--backport argparse \
--backport configparser \
--backport enum \
--backport typing \
--lint \
--no-parse-comments \
--eval-annotations \
$(find . -name '*.py' \
-a -not -path "./.venv/*" \
-a -not -path "./venv/*")
echo "vermin check passed"

View File

@ -1,107 +0,0 @@
---
# Author: Clayton Craft <clayton@craftyguy.net>
image: python:3.7-slim-stretch
cache:
paths:
- venv
before_script:
- ./.gitlab/setup-pmos-environment.sh
# venv created in CI_PROJECT_DIR for caching
- "[[ ! -d venv ]] && virtualenv venv -p $(which python3)"
- "source venv/bin/activate"
- "pip3 install pytest-cov python-coveralls pytest"
- "python3 --version"
- "su pmos -c 'git config --global user.email postmarketos-ci@localhost' || true"
- "su pmos -c 'git config --global user.name postmarketOS_CI' || true"
stages:
- checks
- tests
# defaults for "only"
# We need to run the CI jobs in a "merge request specific context", if CI is
# running in a merge request. Otherwise the environment variable that holds the
# merge request ID is not available. This means, we must set the "only"
# variable accordingly - and if we only do it for one job, all other jobs will
# not get executed. So have the defaults here, and use them in all jobs that
# should run on both the master branch, and in merge requests.
# https://docs.gitlab.com/ee/ci/merge_request_pipelines/index.html#excluding-certain-jobs
.only-default: &only-default
only:
- master
- merge_requests
- tags
static-code-analysis:
stage: checks
<<: *only-default
script:
# Note: This script uses CI_PROJECT_DIR
- su pmos -c "CI_PROJECT_DIR=$CI_PROJECT_DIR .gitlab/shared-runner_test-pmbootstrap.sh --static-code-analysis"
# MR settings
# (Checks for "Allow commits from members who can merge to the target branch")
mr-settings:
stage: checks
only:
- merge_requests
script:
- .gitlab/check_mr_settings.py
test-pmbootstrap:
stage: tests
<<: *only-default
script:
# Note: This script uses CI_PROJECT_DIR
- su pmos -c "CI_PROJECT_DIR=$CI_PROJECT_DIR .gitlab/shared-runner_test-pmbootstrap.sh --testcases-fast"
after_script:
# Move logs so it can be saved as artifacts
- "[[ -f /home/pmos/.local/var/pmbootstrap/log.txt ]] && mv /home/pmos/.local/var/pmbootstrap/log.txt $CI_PROJECT_DIR/log.txt"
- "[[ -f /home/pmos/.local/var/pmbootstrap/log_testsuite.txt ]] && mv /home/pmos/.local/var/pmbootstrap/log_testsuite.txt $CI_PROJECT_DIR/log_testsuite.txt"
- "[[ -f /home/pmos/.config/pmbootstrap.cfg ]] && cp /home/pmos/.config/pmbootstrap.cfg $CI_PROJECT_DIR/pmbootstrap.cfg"
- "sudo dmesg > $CI_PROJECT_DIR/dmesg.txt"
artifacts:
when: always
paths:
- "log.txt"
- "log_testsuite.txt"
- "dmesg.txt"
- "pmbootstrap.cfg"
expire_in: 1 week
pmbootstrap-qemu-tests:
stage: tests
<<: *only-default
only:
variables:
# This is configured in the gitlab project. Make sure there is a runner
# added to the project that is capable of running these tests before
# setting this variable in the project!
- $CI_RUN_QEMU
tags:
# This requires a specific runner, shared runners generally don't work.
- qemu
script:
# Init test (pipefail disabled so 'yes' doesn't fail test)
- "set +o pipefail; yes ''| ./pmbootstrap.py init; set -o pipefail"
# Build/install QEMU (so it doesn't timeout in the testcase)
- "./pmbootstrap.py chroot --add=qemu -- true"
# qemu running process tests (-x: stop after first failure)
- "python -m pytest -vv -x ./test/test_qemu_running_processes.py"
after_script:
# Move logs so it can be saved as artifacts
- "[[ -f ~/.local/var/pmbootstrap/log.txt ]] && mv ~/.local/var/pmbootstrap/log.txt $CI_PROJECT_DIR/log.txt"
- "[[ -f ~/.local/var/pmbootstrap/log_testsuite.txt ]] && mv ~/.local/var/pmbootstrap/log_testsuite.txt $CI_PROJECT_DIR/log_testsuite.txt"
- "[[ -f /home/pmos/.config/pmbootstrap.cfg ]] && cp /home/pmos/.config/pmbootstrap.cfg $CI_PROJECT_DIR/pmbootstrap.cfg"
- "sudo dmesg > $CI_PROJECT_DIR/dmesg.txt"
artifacts:
when: always
paths:
- "log.txt"
- "log_testsuite.txt"
- "dmesg.txt"
- "pmbootstrap.cfg"
expire_in: 1 week

View File

@ -1,156 +0,0 @@
#!/usr/bin/env python3
# Copyright 2020 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import argparse
import json
import os
import sys
import urllib.parse
import urllib.request
def check_environment_variables():
""" Make sure that all environment variables from GitLab CI are present,
and exit right here when a variable is missing. """
keys = ["CI_MERGE_REQUEST_IID",
"CI_MERGE_REQUEST_PROJECT_PATH",
"CI_MERGE_REQUEST_SOURCE_PROJECT_URL"]
for key in keys:
if key in os.environ:
continue
print("ERROR: missing environment variable: " + key)
print("Reference: https://docs.gitlab.com/ee/ci/variables/")
exit(1)
def get_url_api():
""" :returns: single merge request API URL, as documented here:
https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr """
project_path = os.environ["CI_MERGE_REQUEST_PROJECT_PATH"]
project_path = urllib.parse.quote_plus(project_path)
mr_id = os.environ["CI_MERGE_REQUEST_IID"]
url = "https://gitlab.com/api/v4/projects/{}/merge_requests/{}"
return url.format(project_path, mr_id)
def get_url_mr_edit():
""" :returns: the link where the user can edit their own MR """
url = "https://gitlab.com/{}/merge_requests/{}/edit"
return url.format(os.environ["CI_MERGE_REQUEST_PROJECT_PATH"],
os.environ["CI_MERGE_REQUEST_IID"])
def get_url_repo_settings():
""" :returns: link to the user's forked pmaports project's settings """
prefix = os.environ["CI_MERGE_REQUEST_SOURCE_PROJECT_URL"]
return prefix + "/settings/repository"
def get_mr_settings(path):
""" Get the merge request API data and parse it as JSON. Print the whole
thing on failure.
:param path: to a local file with the saved API data (will download a
fresh copy when set to None)
:returns: dict of settings data (see GitLab API reference) """
content = ""
if path:
# Read file
with open(path, encoding="utf-8") as handle:
content = handle.read()
else:
# Download from GitLab API
url = get_url_api()
print("Download " + url)
content = urllib.request.urlopen(url).read().decode("utf-8")
# Parse JSON
try:
return json.loads(content)
except:
print("ERROR: failed to decode JSON. Here's the whole content for"
" debugging:")
print("---")
print(content)
exit(1)
def settings_read(settings, key):
if key not in settings:
print("ERROR: missing '" + key + "' key in settings!")
print("Here are the whole settings for debugging:")
print("---")
print(settings)
exit(1)
return settings[key]
def check_allow_push(settings):
""" :returns: True when maintainers are allowed to push to the branch
(what we want!), False otherwise """
# Check if source branch is in same repository
source = settings_read(settings, "source_project_id")
target = settings_read(settings, "target_project_id")
if source == target:
return True
return settings_read(settings, "allow_maintainer_to_push")
def main():
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("--path", help="use a local file instead of querying"
" the GitLab API", default=None)
args = parser.parse_args()
# Check the merge request
check_environment_variables()
settings = get_mr_settings(args.path)
# Make sure that squashing is disabled
if settings_read(settings, "squash"):
print("*** MR settings check failed!")
print('ERROR: Please turn off the "Squash commits when merge request'
' is accepted." option in the merge request settings.')
return 1
if check_allow_push(settings):
print("*** MR settings check successful!")
else:
print("*** MR settings check failed!")
print()
print("We need to be able to push changes to your merge request.")
print("So we can rebase it on master right before merging, add the")
print("MR-ID to the commit messages, etc.")
print()
print("How to fix it:")
print("1) Open the 'edit' page of your merge request:")
print(" " + get_url_mr_edit())
print("2) Enable this option and save:")
print(" 'Allow commits from members who can merge to the target"
" branch'")
print("3) Run these tests again with an empty commit in your MR:")
print(" $ git commit --allow-empty -m 'run mr-settings test again'")
print()
print("If that setting is disabled, then you have created the MR from")
print("a protected branch. When you had forked the repository from")
print("postmarketOS, the protected branch settings were copied to")
print("your fork.")
print()
print("Resolve this with:")
print("1) Open your repository settings:")
print(" " + get_url_repo_settings())
print("2) Scroll down to 'Protected Branches' and expand it")
print("3) Click 'unprotect' next to the branch from your MR")
print("4) Follow steps 1-3 from the first list again, the option")
print(" should not be disabled anymore.")
print()
print("Thank you and sorry for the inconvenience.")
return 1
return 0
sys.exit(main())

View File

@ -1,22 +0,0 @@
# 'qemu' gitlab runner configuration file
# Author: Clayton Craft <clayton@craftyguy.net>
concurrent = 4
check_interval = 0
log_level = "debug"
[[runners]]
name = "corredor"
url = "https://gitlab.com/"
token = <REDACTED>
executor = "virtualbox"
builds_dir = "/home/pmos/builds"
[runners.ssh]
user = "pmos"
password = <REDACTED>
identity_file = "/home/pmos/.ssh/id_ecdsa"
[runners.virtualbox]
base_name = "pmbootstrap-vm"
base_snapshot = "ci-snapshot-python-3.6"
#disable_snapshots = false
disable_snapshots = true
[runners.cache]

View File

@ -1,23 +0,0 @@
#!/bin/bash
#
# This script is meant for the gitlab CI shared runners, not for
# any specific runners. Specific runners are expected to provide
# all of these configurations to save time, at least for now.
# Author: Clayton Craft <clayton@craftyguy.net>
# skip non-shared runner
[[ -d "/home/pmos" ]] && echo "pmos user already exists, assume running on pre-configured runner" && exit
# mount binfmt_misc
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
# install dependencies (procps: /bin/kill)
apt update
apt install -q -y git sudo procps
pip3 install virtualenv
# create pmos user
echo "Creating pmos user"
useradd pmos -m -s /bin/bash -b "/home"
chown -R pmos:pmos .
echo 'pmos ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

View File

@ -1,40 +0,0 @@
#!/bin/bash
#
# This script is meant to be executed by a non-root user, since pmbootstrap
# commands will fail otherwise. This is primarily used by the gitlab CI shared
# runners.
# This script also assumes, if run outside a gitlab CI runner, that cwd is
# the root of the pmbootstrap project. For gitlab CI runners, $CI_PROJECT_DIR
# is used.
# Author: Clayton Craft <clayton@craftyguy.net>
# Return failure on any failure of commands below
set -e
# Fail quickly if run as root, since other commands here will fail
[[ "$(id -u)" != "0" ]]
# These are specific to the gitlab CI
[[ $CI_PROJECT_DIR ]] && cd "$CI_PROJECT_DIR"
# shellcheck disable=SC1091
[[ -d venv ]] && source ./venv/bin/activate
# Init test (pipefail disabled so 'yes' doesn't fail test)
set +o pipefail
yes ''| ./pmbootstrap.py init
set -o pipefail
# this seems to be needed for some tests to pass
set +o pipefail
yes | ./pmbootstrap.py zap -m -p
set -o pipefail
case $1 in
--static-code-analysis )
./test/static_code_analysis.sh
;;
--testcases-fast )
# testcases_fast (qemu is omitted by not passing --all)
./test/testcases_fast.sh
;;
esac

127
README.md
View File

@ -1,23 +1,62 @@
# pmbootstrap
[**Introduction**](https://postmarketos.org/blog/2017/05/26/intro/) | [**Security Warning**](https://ollieparanoid.github.io/post/security-warning/) | [**Devices**](https://wiki.postmarketos.org/wiki/Devices)
Sophisticated chroot/build/flash tool to develop and install [postmarketOS](https://postmarketos.org).
Sophisticated chroot/build/flash tool to develop and install
[postmarketOS](https://postmarketos.org).
Package build scripts live in the [`pmaports`](https://gitlab.com/postmarketOS/pmaports) repository now.
## Development
pmbootstrap is being developed on SourceHut
([what](https://postmarketos.org/blog/2022/07/25/considering-sourcehut/)):
https://git.sr.ht/~postmarketos/pmbootstrap
Send patches via mail or web UI to
[pmbootstrap-devel](https://lists.sr.ht/~postmarketos/pmbootstrap-devel)
([subscribe](mailto:~postmarketos/pmbootstrap-devel+subscribe@lists.sr.ht)):
```
~postmarketos/pmbootstrap-devel@lists.sr.ht
```
You can set the default values for sending email in the git checkout
```
$ git config sendemail.to "~postmarketos/pmbootstrap-devel@lists.sr.ht"
$ git config format.subjectPrefix "PATCH pmbootstrap"
```
Run CI scripts locally with:
```
$ pmbootstrap ci
```
Run a single test file:
```
$ pytest -vv ./test/test_keys.py
```
## Issues
Issues are being tracked
[here](https://gitlab.com/postmarketOS/pmbootstrap/-/issues).
## Requirements
* 2 GB of RAM recommended for compiling
* Linux distribution on the host system (`x86`, `x86_64`, or `aarch64`)
* [Windows subsystem for Linux (WSL)](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux) does **not** work! Please use [VirtualBox](https://www.virtualbox.org/) instead.
* Kernels based on the grsec patchset [do **not** work](https://github.com/postmarketOS/pmbootstrap/issues/107) *(Alpine: use linux-vanilla instead of linux-hardened, Arch: linux-hardened [is not based on grsec](https://www.reddit.com/r/archlinux/comments/68b2jn/linuxhardened_in_community_repo_a_grsecurity/))*
* On Alpine Linux only: `apk add coreutils procps`
* Linux distribution on the host system (`x86`, `x86_64`, `aarch64` or `armv7`)
* [Windows subsystem for Linux (WSL)](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)
does **not** work! Please use [VirtualBox](https://www.virtualbox.org/) instead.
* [Linux kernel 3.17 or higher](https://postmarketos.org/oldkernel)
* Python 3.6+
* Python 3.7+
* OpenSSL
* git
* ps
* tar
## Usage Examples
Please refer to the [postmarketOS wiki](https://wiki.postmarketos.org) for in-depth coverage of topics such as [porting to a new device](https://wiki.postmarketos.org/wiki/Porting_to_a_new_device) or [installation](https://wiki.postmarketos.org/wiki/Installation_guide). The help output (`pmbootstrap -h`) has detailed usage instructions for every command. Read on for some generic examples of what can be done with `pmbootstrap`.
Please refer to the [postmarketOS wiki](https://wiki.postmarketos.org) for
in-depth coverage of topics such as
[porting to a new device](https://wiki.postmarketos.org/wiki/Porting_to_a_new_device)
or [installation](https://wiki.postmarketos.org/wiki/Installation_guide). The
help output (`pmbootstrap -h`) has detailed usage instructions for every
command. Read on for some generic examples of what can be done with
`pmbootstrap`.
### Installing pmbootstrap
<https://wiki.postmarketos.org/wiki/Installing_pmbootstrap>
@ -64,6 +103,27 @@ Generate a template for a new package:
$ pmbootstrap newapkbuild "https://gitlab.com/postmarketOS/osk-sdl/-/archive/0.52/osk-sdl-0.52.tar.bz2"
```
#### Default architecture
Packages will be compiled for the architecture of the device running
pmbootstrap by default. For example, if your `x86_64` PC runs pmbootstrap, it
would build a package for `x86_64` with this command:
```
$ pmbootstrap build hello-world
```
If you would rather build for the target device selected in `pmbootstrap init`
by default, then use the `build_default_device_arch` option:
```
$ pmbootstrap config build_default_device_arch True
```
If your target device is `pine64-pinephone` for example, pmbootstrap will now
build this package for `aarch64`:
```
$ pmbootstrap build hello-world
```
### Chroots
Enter the `armhf` building chroot:
```
@ -81,7 +141,9 @@ $ pmbootstrap zap
```
### Device Porting Assistance
Analyze Android [`boot.img`](https://wiki.postmarketos.org/wiki/Glossary#boot.img) files (also works with recovery OS images like TWRP):
Analyze Android
[`boot.img`](https://wiki.postmarketos.org/wiki/Glossary#boot.img) files (also
works with recovery OS images like TWRP):
```
$ pmbootstrap bootimg_analyze ~/Downloads/twrp-3.2.1-0-fp2.img
```
@ -145,12 +207,14 @@ List pmaports that don't have a binary package:
$ pmbootstrap repo_missing --arch=armhf --overview
```
Increase the `pkgrel` for each aport where the binary package has outdated dependencies (e.g. after soname bumps):
Increase the `pkgrel` for each aport where the binary package has outdated
dependencies (e.g. after soname bumps):
```
$ pmbootstrap pkgrel_bump --auto
```
Generate cross-compiler aports based on the latest version from Alpine's aports:
Generate cross-compiler aports based on the latest version from Alpine's
aports:
```
$ pmbootstrap aportgen binutils-armhf gcc-armhf
```
@ -171,6 +235,11 @@ Use `-v` on any action to get verbose logging:
$ pmbootstrap -v build hello-world
```
Parse a single deviceinfo and return it as JSON:
```
$ pmbootstrap deviceinfo_parse pine64-pinephone
```
Parse a single APKBUILD and return it as JSON:
```
$ pmbootstrap apkbuild_parse hello-world
@ -186,14 +255,32 @@ $ pmbootstrap apkindex_parse $WORK/cache_apk_x86_64/APKINDEX.8b865e19.tar.gz hel
$ pmbootstrap stats --arch=armhf
```
`distccd` log:
```
$ pmbootstrap log_distccd
```
### Use alternative sudo
## Development
### Testing
Install `pytest` (via your package manager or pip) and run it inside the pmbootstrap folder.
pmbootstrap supports `doas` and `sudo`.
If multiple sudo implementations are installed, pmbootstrap will use `doas`.
You can set the `PMB_SUDO` environmental variable to define the sudo
implementation you want to use.
### Select SSH keys to include and make authorized in new images
If the config file option `ssh_keys` is set to `True` (it defaults to `False`),
then all files matching the glob `~/.ssh/id_*.pub` will be placed in
`~/.ssh/authorized_keys` in the user's home directory in newly-built images.
Sometimes, for example if you have a large number of SSH keys, you may wish to
select a different set of public keys to include in an image. To do this, set
the `ssh_key_glob` configuration parameter in the pmbootstrap config file to a
string containing a glob that is to match the file or files you wish to
include.
For example, a `~/.config/pmbootstrap.cfg` may contain:
[pmbootstrap]
# ...
ssh_keys = True
ssh_key_glob = ~/.ssh/postmarketos-dev.pub
# ...
## License
[GPLv3](LICENSE)

View File

@ -14,6 +14,9 @@ check_kernel_folder() {
clean_kernel_src_dir() {
# Prevent Linux from appending Git version information to kernel version
# This will cause kernels to be packaged incorrectly.
touch .scmversion
if [ -f ".config" ] || [ -d "include/config" ]; then
echo "Source directory is not clean, running 'make mrproper'."
@ -44,16 +47,16 @@ export_pmbootstrap_dir() {
# Get pmbootstrap dir based on this script's location
# See also: <https://stackoverflow.com/a/29835459>
# shellcheck disable=SC2039
# shellcheck disable=SC3054
if [ -n "${BASH_SOURCE[0]}" ]; then
script_dir="$(dirname "${BASH_SOURCE[0]}")"
script_dir="$(dirname "$(realpath "$BASH_SOURCE")")"
else
script_dir="$(dirname "$1")"
fi
# Fail with debug information
# shellcheck disable=SC2155
export pmbootstrap_dir=$(realpath "$script_dir/..")
export pmbootstrap_dir="$(realpath "$script_dir/..")"
if ! [ -e "$pmbootstrap_dir/pmbootstrap.py" ]; then
echo "ERROR: Failed to get the script's location with your shell."
echo "Please adjust export_pmbootstrap_dir in envkernel.sh. Debug info:"
@ -68,7 +71,7 @@ set_alias_pmbootstrap() {
pmbootstrap="$pmbootstrap_dir"/pmbootstrap.py
# shellcheck disable=SC2139
alias pmbootstrap="\"$pmbootstrap\""
if [ -e ~/.config/pmbootstrap.cfg ]; then
if [ -e "${XDG_CONFIG_HOME:-$HOME/.config}"/pmbootstrap.cfg ]; then
"$pmbootstrap" work_migrate
else
echo "NOTE: First run of pmbootstrap, running 'pmbootstrap init'"
@ -80,7 +83,7 @@ set_alias_pmbootstrap() {
export_chroot_device_deviceinfo() {
chroot="$("$pmbootstrap" config work)/chroot_native"
device="$("$pmbootstrap" config device)"
deviceinfo="$(echo "$pmbootstrap_dir"/aports/device/*/device-"$device"/deviceinfo)"
deviceinfo="$(echo "$("$pmbootstrap" config aports)"/device/*/device-"$device"/deviceinfo)"
export chroot device deviceinfo
}
@ -114,10 +117,12 @@ initialize_chroot() {
host_arch="$(uname -m)"
need_cross_compiler=1
# Match arm* architectures
# shellcheck disable=SC2039
# shellcheck disable=SC3057
arch_substr="${host_arch:0:3}"
if [ "$arch" = "$host_arch" ] || \
{ [ "$arch_substr" = "arm" ] && [ "$arch_substr" = "$arch" ]; }; then
{ [ "$arch_substr" = "arm" ] && [ "$arch_substr" = "$arch" ]; } || \
{ [ "$arch" = "arm64" ] && [ "$host_arch" = "aarch64" ]; } || \
{ [ "$arch" = "x86" ] && [ "$host_arch" = "x86_64" ]; }; then
need_cross_compiler=0
fi
@ -153,6 +158,7 @@ initialize_chroot() {
elfutils-dev \
findutils \
flex \
g++ \
"$gcc_pkgname" \
gmp-dev \
linux-headers \
@ -163,7 +169,10 @@ initialize_chroot() {
musl-dev \
ncurses-dev \
perl \
py3-dt-schema \
sed \
yamllint \
yaml-dev \
xz || return 1
# Create /mnt/linux
@ -192,7 +201,7 @@ create_output_folder() {
set_alias_make() {
# Cross compiler prefix
# shellcheck disable=SC1090
# shellcheck disable=SC1091
prefix="$(CBUILD="$deviceinfo_arch" . "$chroot/usr/share/abuild/functions.sh";
arch_to_hostspec "$deviceinfo_arch")"
@ -210,9 +219,14 @@ set_alias_make() {
cross_compiler="/usr/bin/$prefix-"
fi
if [ "$arch" = "x86" ] && [ "$host_arch" = "x86_64" ]; then
cc=$hostcc
fi
# Build make command
cmd="echo '*** pmbootstrap envkernel.sh active for $PWD! ***';"
cmd="$cmd pmbootstrap -q chroot --user --"
cmd="$cmd CCACHE_DISABLE=1"
cmd="$cmd ARCH=$arch"
if [ "$need_cross_compiler" = 1 ]; then
cmd="$cmd CROSS_COMPILE=$cross_compiler"
@ -220,11 +234,6 @@ set_alias_make() {
cmd="$cmd make -C /mnt/linux O=/mnt/linux/.output"
cmd="$cmd CC=$cc HOSTCC=$hostcc"
# Avoid "+" suffix in kernel version if the working directory is dirty.
# (Otherwise we will generate a package that uses different paths...)
# Note: Set CONFIG_LOCALVERSION_AUTO=n in kernel config additionally
cmd="$cmd LOCALVERSION="
# shellcheck disable=SC2139
alias make="$cmd"
unset cmd
@ -239,7 +248,7 @@ set_alias_make() {
cmd="$cmd srcdir=/mnt/linux builddir=/mnt/linux/.output tmpdir=/tmp/envkernel"
cmd="$cmd ./\"\$_script\"\";"
cmd="$cmd else"
cmd="$cmd echo \"Error: \$_script not found.\";"
cmd="$cmd echo \"ERROR: \$_script not found.\";"
cmd="$cmd fi;"
cmd="$cmd };"
cmd="$cmd _run_script \"\$@\""
@ -259,7 +268,7 @@ set_alias_pmbroot_kernelroot() {
cross_compiler_version() {
if [ "$need_cross_compiler" = 1 ]; then
pmbootstrap chroot --user -- "${cross_compiler}gcc" --version \
"$pmbootstrap" chroot --user -- "${cross_compiler}gcc" --version \
2> /dev/null | grep "^.*gcc " | \
awk -F'[()]' '{ print $1 "("$2")" }'
else
@ -305,19 +314,17 @@ set_reactivate() {
}
check_and_deactivate() {
if [ "$POSTMARKETOS_ENVKERNEL_ENABLED" -eq 1 ]; then
# we already are runnning in envkernel
if [ "$POSTMARKETOS_ENVKERNEL_ENABLED" = 1 ]; then
# we already are running in envkernel
deactivate
fi
}
print_usage() {
# shellcheck disable=SC2039
# shellcheck disable=SC3054
if [ -n "${BASH_SOURCE[0]}" ]; then
echo "usage: source $(basename "${BASH_SOURCE[0]}")"
else
echo "usage: source $(basename "$1")"
echo "usage: source $(basename "$(realpath "$BASH_SOURCE")")"
fi
echo "optional arguments:"
echo " --fish Print fish alias syntax (internally used)"
@ -403,7 +410,7 @@ main() {
# Print fish alias syntax (when called from envkernel.fish)
fish_compat() {
[ "$1" = "--fish" ] || return
[ "$1" = "--fish" ] || return 0
for name in make kernelroot pmbootstrap pmbroot; do
echo "alias $(alias $name | sed 's/=/ /')"
done

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
# PYTHON_ARGCOMPLETE_OK
import sys
@ -14,6 +14,17 @@ from .helpers import logging as pmb_logging
from .helpers import mount
from .helpers import other
# pmbootstrap version
__version__ = "2.0.0"
# Python version check
version = sys.version_info
if version < (3, 7):
print("You need at least Python 3.7 to run pmbootstrap")
print("(You are running it with Python " + str(version.major) +
"." + str(version.minor) + ")")
sys.exit()
def main():
# Wrap everything to display nice error messages
@ -23,8 +34,11 @@ def main():
args = parse.arguments()
os.umask(0o22)
# Store script invocation command
os.environ["PMBOOTSTRAP_CMD"] = sys.argv[0]
# Sanity checks
other.check_grsec(args)
other.check_grsec()
if not args.as_root and os.geteuid() == 0:
raise RuntimeError("Do not run pmbootstrap as root!")
@ -54,7 +68,11 @@ def main():
if mount.ismount(args.work + "/chroot_native/dev"):
logging.info("NOTE: chroot is still active (use 'pmbootstrap"
" shutdown' as necessary)")
logging.info("Done")
logging.info("DONE!")
except KeyboardInterrupt:
print("\nCaught KeyboardInterrupt, exiting …")
sys.exit(130) # SIGINT(2) + 128
except Exception as e:
# Dump log to stdout when args (and therefore logging) init failed
@ -69,9 +87,16 @@ def main():
log_hint = "Run 'pmbootstrap log' for details."
if not args or not os.path.exists(args.log):
log_hint += (" Alternatively you can use '--details-to-stdout' to"
" get more output, e.g. 'pmbootstrap --details-to-stdout"
" init'.")
" get more output, e.g. 'pmbootstrap"
" --details-to-stdout init'.")
print()
print(log_hint)
print()
print("Before you report this error, ensure that pmbootstrap is "
"up to date.")
print("Find the latest version here:"
" https://git.sr.ht/~postmarketos/pmbootstrap/refs")
print(f"Your version: {__version__}")
return 1

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging
@ -37,14 +37,16 @@ def properties(pkgname):
def generate(args, pkgname):
if args.fork_alpine:
prefix, folder, options = (pkgname, "temp", {"confirm_overwrite": True})
prefix, folder, options = (pkgname, "temp",
{"confirm_overwrite": True})
else:
prefix, folder, options = properties(pkgname)
path_target = args.aports + "/" + folder + "/" + pkgname
# Confirm overwrite
if options["confirm_overwrite"] and os.path.exists(path_target):
logging.warning("WARNING: Target folder already exists: " + path_target)
logging.warning("WARNING: Target folder already exists: "
f"{path_target}")
if not pmb.helpers.cli.confirm(args, "Continue and overwrite?"):
raise RuntimeError("Aborted.")
@ -52,8 +54,10 @@ def generate(args, pkgname):
pmb.helpers.run.user(args, ["rm", "-r", args.work + "/aportgen"])
if args.fork_alpine:
upstream = pmb.aportgen.core.get_upstream_aport(args, pkgname)
pmb.helpers.run.user(args, ["cp", "-r", upstream, args.work + "/aportgen"])
pmb.aportgen.core.rewrite(args, pkgname, replace_simple={"# Contributor:*": None, "# Maintainer:*": None})
pmb.helpers.run.user(args, ["cp", "-r", upstream,
f"{args.work}/aportgen"])
pmb.aportgen.core.rewrite(args, pkgname, replace_simple={
"# Contributor:*": None, "# Maintainer:*": None})
else:
# Run pmb.aportgen.PREFIX.generate()
getattr(pmb.aportgen, prefix.replace("-", "_")).generate(args, pkgname)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.aportgen.core
import pmb.helpers.git
@ -11,50 +11,23 @@ def generate(args, pkgname):
upstream = pmb.aportgen.core.get_upstream_aport(args, "binutils")
pmb.helpers.run.user(args, ["cp", "-r", upstream, args.work + "/aportgen"])
# Architectures to build this package for
arches = list(pmb.config.build_device_architectures)
arches.remove(arch)
# Rewrite APKBUILD
fields = {
"arch": pmb.config.arch_native,
"makedepends_host": "zlib-dev jansson-dev zstd-dev",
"pkgdesc": f"Tools necessary to build programs for {arch} targets",
"pkgname": pkgname,
"pkgdesc": "Tools necessary to build programs for " + arch + " targets",
"arch": " ".join(arches),
"makedepends_build": "",
"makedepends_host": "",
"makedepends": "gettext libtool autoconf automake bison texinfo",
"subpackages": "",
}
replace_functions = {
"build": """
_target="$(arch_to_hostspec """ + arch + """)"
cd "$builddir"
"$builddir"/configure \\
--build="$CBUILD" \\
--target=$_target \\
--with-lib-path=/usr/lib \\
--prefix=/usr \\
--with-sysroot=/usr/$_target \\
--enable-ld=default \\
--enable-gold=yes \\
--enable-plugins \\
--enable-deterministic-archives \\
--disable-multilib \\
--disable-werror \\
--disable-nls
make
""",
"package": """
cd "$builddir"
make install DESTDIR="$pkgdir"
# remove man, info folders
rm -rf "$pkgdir"/usr/share
""",
"libs": None,
"gold": None,
replace_simple = {
"*--with-bugurl=*": "\t\t--with-bugurl=\"https://postmarketos.org/issues\" \\"
}
below_header = """
CTARGET_ARCH=""" + arch + """
CTARGET="$(arch_to_hostspec $CTARGET_ARCH)"
"""
pmb.aportgen.core.rewrite(args, pkgname, "main/binutils", fields,
"binutils", replace_functions, remove_indent=8)
"binutils", replace_simple=replace_simple,
below_header=below_header)

View File

@ -1,18 +1,15 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import os
import pmb.helpers.run
import pmb.aportgen.core
import pmb.parse.apkindex
import pmb.build
import pmb.chroot.apk
import pmb.chroot.apk_static
import pmb.helpers.run
import pmb.parse.apkindex
def generate(args, pkgname):
# Install busybox-static in chroot to get verified apks
arch = pkgname.split("-")[2]
pmb.chroot.apk.install(args, ["busybox-static"], "buildroot_" + arch)
# Parse version from APKINDEX
package_data = pmb.parse.apkindex.package(args, "busybox")
@ -20,63 +17,57 @@ def generate(args, pkgname):
pkgver = version.split("-r")[0]
pkgrel = version.split("-r")[1]
# Copy the apk file to the distfiles cache
pattern = (args.work + "/cache_apk_" + arch + "/busybox-static-" +
version + ".*.apk")
glob_result = glob.glob(pattern)
if not len(glob_result):
raise RuntimeError("Could not find aport " + pattern + "!"
" Update your aports_upstream git repo"
" to the latest version, delete your http cache"
" (pmbootstrap zap -hc) and try again.")
path = glob_result[0]
path_target = (args.work + "/cache_distfiles/busybox-static-" +
version + "-" + arch + ".apk")
if not os.path.exists(path_target):
pmb.helpers.run.root(args, ["cp", path, path_target])
# Hash the distfile
hashes = pmb.chroot.user(args, ["sha512sum",
"busybox-static-" + version + "-" + arch + ".apk"],
"buildroot_" + arch, "/var/cache/distfiles",
output_return=True)
# Prepare aportgen tempdir inside and outside of chroot
tempdir = "/tmp/aportgen"
pmb.chroot.root(args, ["rm", "-rf", tempdir])
pmb.helpers.run.user(args, ["mkdir", "-p", f"{args.work}/aportgen",
f"{args.work}/chroot_native/{tempdir}"])
# Write the APKBUILD
pmb.helpers.run.user(args, ["mkdir", "-p", args.work + "/aportgen"])
with open(args.work + "/aportgen/APKBUILD", "w", encoding="utf-8") as handle:
# Variables
handle.write("# Automatically generated aport, do not edit!\n"
"# Generator: pmbootstrap aportgen " + pkgname + "\n"
"\n"
"pkgname=" + pkgname + "\n"
"pkgver=" + pkgver + "\n"
"pkgrel=" + pkgrel + "\n"
"\n"
"_arch=\"" + arch + "\"\n"
"_mirror=\"" + args.mirror_alpine + "\"\n"
)
# Static part
static = """
channel_cfg = pmb.config.pmaports.read_config_channel(args)
mirrordir = channel_cfg["mirrordir_alpine"]
apkbuild_path = f"{args.work}/chroot_native/{tempdir}/APKBUILD"
apk_name = f"busybox-static-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk"
with open(apkbuild_path, "w", encoding="utf-8") as handle:
apkbuild = f"""\
# Automatically generated aport, do not edit!
# Generator: pmbootstrap aportgen {pkgname}
# Stub for apkbuild-lint
if [ -z "$(type -t arch_to_hostspec)" ]; then
arch_to_hostspec() {{ :; }}
fi
pkgname={pkgname}
pkgver={pkgver}
pkgrel={pkgrel}
_arch="{arch}"
_mirror="{pmb.config.aportgen_mirror_alpine}"
url="http://busybox.net"
license="GPL2"
arch="all"
arch="{pmb.config.arch_native}"
options="!check !strip"
pkgdesc="Statically linked Busybox for $_arch"
_target="$(arch_to_hostspec $_arch)"
source="
busybox-static-$pkgver-r$pkgrel-$_arch.apk::$_mirror/edge/main/$_arch/busybox-static-$pkgver-r$pkgrel.apk
busybox-static-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk::$_mirror/{mirrordir}/main/$_arch/busybox-static-$pkgver-r$pkgrel.apk
"
package() {
package() {{
mkdir -p "$pkgdir/usr/$_target"
cd "$pkgdir/usr/$_target"
tar -xf $srcdir/busybox-static-$pkgver-r$pkgrel-$_arch.apk
tar -xf $srcdir/{apk_name}
rm .PKGINFO .SIGN.*
}
}}
"""
for line in static.split("\n"):
handle.write(line[12:] + "\n")
for line in apkbuild.split("\n"):
handle.write(line[12:].replace(" " * 4, "\t") + "\n")
# Hashes
handle.write("sha512sums=\"" + hashes.rstrip() + "\"\n")
# Generate checksums
pmb.build.init_abuild_minimal(args)
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir])
pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir)
pmb.helpers.run.user(args, ["cp", apkbuild_path, f"{args.work}/aportgen"])

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import fnmatch
import logging
@ -54,19 +54,20 @@ def rewrite(args, pkgname, path_original="", fields={}, replace_pkgname=None,
lines (so they won't be bugged with issues regarding our generated aports),
and add reference to the original aport.
:param path_original: The original path of the automatically generated aport
:param fields: key-value pairs of fields, that shall be changed in the
:param path_original: The original path of the automatically generated
aport.
:param fields: key-value pairs of fields that shall be changed in the
APKBUILD. For example: {"pkgdesc": "my new package", "subpkgs": ""}
:param replace_pkgname: When set, $pkgname gets replaced with that string in
every line.
:param replace_pkgname: When set, $pkgname gets replaced with that string
in every line.
:param replace_functions: Function names and new bodies, for example:
{"build": "return 0"}
The body can also be None (deletes the function)
:param replace_simple: Lines, that fnmatch the pattern, get
:param replace_simple: Lines that fnmatch the pattern, get
replaced/deleted. Example: {"*test*": "# test", "*mv test.bin*": None}
:param below_header: String, that gets directly placed below the header.
:param remove_indent: Number of spaces to remove from function body provided
to replace_functions.
:param below_header: String that gets directly placed below the header.
:param remove_indent: Number of spaces to remove from function body
provided to replace_functions.
"""
# Header
@ -109,8 +110,8 @@ def rewrite(args, pkgname, path_original="", fields={}, replace_pkgname=None,
if line.startswith(func + "() {"):
skip_in_func = True
if body:
lines_new += format_function(func, body,
remove_indent=remove_indent)
lines_new += format_function(
func, body, remove_indent=remove_indent)
break
if skip_in_func:
continue
@ -118,7 +119,15 @@ def rewrite(args, pkgname, path_original="", fields={}, replace_pkgname=None,
# Replace fields
for key, value in fields.items():
if line.startswith(key + "="):
line = key + "=\"" + value + "\"\n"
if value:
if key in ["pkgname", "pkgver", "pkgrel"]:
# No quotes to avoid lint error
line = f"{key}={value}\n"
else:
line = f'{key}="{value}"\n'
else:
# Remove line without value to avoid lint error
line = ""
break
# Replace $pkgname
@ -143,11 +152,12 @@ def rewrite(args, pkgname, path_original="", fields={}, replace_pkgname=None,
handle.truncate()
def get_upstream_aport(args, pkgname):
def get_upstream_aport(args, pkgname, arch=None):
"""
Perform a git checkout of Alpine's aports and get the path to the aport.
:param pkgname: package name
:param arch: Alpine architecture (e.g. "armhf"), defaults to native arch
:returns: absolute path on disk where the Alpine aport is checked out
example: /opt/pmbootstrap_work/cache_git/aports/upstream/main/gcc
"""
@ -155,6 +165,19 @@ def get_upstream_aport(args, pkgname):
pmb.helpers.git.clone(args, "aports_upstream")
aports_upstream_path = args.work + "/cache_git/aports_upstream"
# Checkout branch
channel_cfg = pmb.config.pmaports.read_config_channel(args)
branch = channel_cfg["branch_aports"]
logging.info(f"Checkout aports.git branch: {branch}")
if pmb.helpers.run.user(args, ["git", "checkout", branch],
aports_upstream_path, check=False):
logging.info("NOTE: run 'pmbootstrap pull' and try again")
logging.info("NOTE: if it still fails, your aports.git was cloned with"
" an older version of pmbootstrap, as shallow clone."
" Unshallow it, or remove it and let pmbootstrap clone it"
f" again: {aports_upstream_path}")
raise RuntimeError("Branch checkout failed.")
# Search package
paths = glob.glob(aports_upstream_path + "/*/" + pkgname)
if len(paths) > 1:
@ -166,7 +189,7 @@ def get_upstream_aport(args, pkgname):
aport_path = paths[0]
# Parse APKBUILD
apkbuild = pmb.parse.apkbuild(args, aport_path + "/APKBUILD",
apkbuild = pmb.parse.apkbuild(f"{aport_path}/APKBUILD",
check_pkgname=False)
apkbuild_version = apkbuild["pkgver"] + "-r" + apkbuild["pkgrel"]
@ -174,7 +197,7 @@ def get_upstream_aport(args, pkgname):
split = aport_path.split("/")
repo = split[-2]
pkgname = split[-1]
index_path = pmb.helpers.repo.alpine_apkindex_path(args, repo)
index_path = pmb.helpers.repo.alpine_apkindex_path(args, repo, arch)
package = pmb.parse.apkindex.package(args, pkgname, indexes=[index_path])
# Compare version (return when equal)
@ -182,16 +205,18 @@ def get_upstream_aport(args, pkgname):
if compare == 0:
return aport_path
# Different version message
logging.error("ERROR: Package '" + pkgname + "' has a different version in"
# APKBUILD > binary: this is fine
if compare == 1:
logging.info(f"NOTE: {pkgname} {arch} binary package has a lower"
f" version {package['version']} than the APKBUILD"
f" {apkbuild_version}")
return aport_path
# APKBUILD < binary: aports.git is outdated
logging.error("ERROR: Package '" + pkgname + "' has a lower version in"
" local checkout of Alpine's aports (" + apkbuild_version +
") compared to Alpine's binary package (" +
package["version"] + ")!")
# APKBUILD < binary
if compare == -1:
raise RuntimeError("You can update your local checkout with: "
"'pmbootstrap pull'")
# APKBUILD > binary
raise RuntimeError("You can force an update of your binary package"
" APKINDEX files with: 'pmbootstrap update'")
raise RuntimeError("You can update your local checkout with: "
"'pmbootstrap pull'")

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
@ -9,26 +9,30 @@ import pmb.parse.apkindex
import pmb.parse.bootimg
def ask_for_architecture(args):
def ask_for_architecture():
architectures = pmb.config.build_device_architectures
# Don't show armhf, new ports shouldn't use this architecture
if "armhf" in architectures:
architectures.remove("armhf")
while True:
ret = pmb.helpers.cli.ask(args, "Device architecture", architectures,
architectures[0])
ret = pmb.helpers.cli.ask("Device architecture", architectures,
"aarch64", complete=architectures)
if ret in architectures:
return ret
logging.fatal("ERROR: Invalid architecture specified. If you want to"
" add a new architecture, edit build_device_architectures"
" in pmb/config/__init__.py.")
" add a new architecture, edit"
" build_device_architectures in"
" pmb/config/__init__.py.")
def ask_for_manufacturer(args):
def ask_for_manufacturer():
logging.info("Who produced the device (e.g. LG)?")
return pmb.helpers.cli.ask(args, "Manufacturer", None, None, False)
return pmb.helpers.cli.ask("Manufacturer", None, None, False)
def ask_for_name(args, manufacturer):
def ask_for_name(manufacturer):
logging.info("What is the official name (e.g. Google Nexus 5)?")
ret = pmb.helpers.cli.ask(args, "Name", None, None, False)
ret = pmb.helpers.cli.ask("Name", None, None, False)
# Always add the manufacturer
if not ret.startswith(manufacturer) and \
@ -37,44 +41,52 @@ def ask_for_name(args, manufacturer):
return ret
def ask_for_year(args):
def ask_for_year():
# Regex from https://stackoverflow.com/a/12240826
logging.info("In what year was the device released (e.g. 2012)?")
return pmb.helpers.cli.ask(args, "Year", None, None, False,
return pmb.helpers.cli.ask("Year", None, None, False,
validation_regex=r'^[1-9]\d{3,}$')
def ask_for_chassis(args):
def ask_for_chassis():
types = pmb.config.deviceinfo_chassis_types
logging.info("What type of device is it?")
logging.info("Valid types are: " + ", ".join(types))
return pmb.helpers.cli.ask(args, "Chassis", None, None, True,
validation_regex='|'.join(types), complete=types)
return pmb.helpers.cli.ask("Chassis", None, None, True,
validation_regex='|'.join(types),
complete=types)
def ask_for_keyboard(args):
return pmb.helpers.cli.confirm(args, "Does the device have a hardware keyboard?")
return pmb.helpers.cli.confirm(args, "Does the device have a hardware"
" keyboard?")
def ask_for_external_storage(args):
return pmb.helpers.cli.confirm(args, "Does the device have a sdcard or other"
" external storage medium?")
return pmb.helpers.cli.confirm(args, "Does the device have a sdcard or"
" other external storage medium?")
def ask_for_flash_method(args):
def ask_for_flash_method():
while True:
logging.info("Which flash method does the device support?")
method = pmb.helpers.cli.ask(args, "Flash method", pmb.config.flash_methods,
pmb.config.flash_methods[0])
method = pmb.helpers.cli.ask("Flash method",
pmb.config.flash_methods,
"none",
complete=pmb.config.flash_methods)
if method in pmb.config.flash_methods:
if method == "heimdall":
heimdall_types = ["isorec", "bootimg"]
while True:
logging.info("Does the device use the \"isolated recovery\" or boot.img?")
logging.info("<https://wiki.postmarketos.org/wiki/Deviceinfo_flash_methods#Isorec_or_bootimg.3F>")
heimdall_type = pmb.helpers.cli.ask(args, "Type", heimdall_types,
logging.info("Does the device use the \"isolated"
" recovery\" or boot.img?")
logging.info("<https://wiki.postmarketos.org/wiki"
"/Deviceinfo_flash_methods#Isorec_or_bootimg"
".3F>")
heimdall_type = pmb.helpers.cli.ask("Type",
heimdall_types,
heimdall_types[0])
if heimdall_type in heimdall_types:
method += "-" + heimdall_type
@ -88,13 +100,15 @@ def ask_for_flash_method(args):
def ask_for_bootimg(args):
logging.info("You can analyze a known working boot.img file to automatically fill"
" out the flasher information for your deviceinfo file. Either specify"
" the path to an image or press return to skip this step (you can do"
" it later with 'pmbootstrap bootimg_analyze').")
logging.info("You can analyze a known working boot.img file to"
" automatically fill out the flasher information for your"
" deviceinfo file. Either specify the path to an image or"
" press return to skip this step (you can do it later with"
" 'pmbootstrap bootimg_analyze').")
while True:
path = os.path.expanduser(pmb.helpers.cli.ask(args, "Path", None, "", False))
response = pmb.helpers.cli.ask("Path", None, "", False)
path = os.path.expanduser(response)
if not path:
return None
try:
@ -103,10 +117,11 @@ def ask_for_bootimg(args):
logging.fatal("ERROR: " + str(e) + ". Please try again.")
def generate_deviceinfo_fastboot_content(args, bootimg=None):
def generate_deviceinfo_fastboot_content(bootimg=None):
if bootimg is None:
bootimg = {"cmdline": "",
"qcdt": "false",
"mtk_mkimage": "false",
"dtb_second": "false",
"base": "",
"kernel_offset": "",
@ -114,28 +129,49 @@ def generate_deviceinfo_fastboot_content(args, bootimg=None):
"second_offset": "",
"tags_offset": "",
"pagesize": "2048"}
return f"""\
content = f"""\
deviceinfo_kernel_cmdline="{bootimg["cmdline"]}"
deviceinfo_generate_bootimg="true"
deviceinfo_bootimg_qcdt="{bootimg["qcdt"]}"
deviceinfo_bootimg_mtk_mkimage="{bootimg["mtk_mkimage"]}"
deviceinfo_bootimg_dtb_second="{bootimg["dtb_second"]}"
deviceinfo_flash_pagesize="{bootimg["pagesize"]}"
"""
if "header_version" in bootimg.keys():
content += f"""\
deviceinfo_header_version="{bootimg["header_version"]}"
"""
if bootimg["header_version"] == "2":
content += f"""\
deviceinfo_append_dtb="false"
deviceinfo_flash_offset_dtb="{bootimg["dtb_offset"]}"
"""
if "base" in bootimg.keys():
content += f"""\
deviceinfo_flash_offset_base="{bootimg["base"]}"
deviceinfo_flash_offset_kernel="{bootimg["kernel_offset"]}"
deviceinfo_flash_offset_ramdisk="{bootimg["ramdisk_offset"]}"
deviceinfo_flash_offset_second="{bootimg["second_offset"]}"
deviceinfo_flash_offset_tags="{bootimg["tags_offset"]}"
deviceinfo_flash_pagesize="{bootimg["pagesize"]}"
"""
return content
def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
chassis, has_keyboard, has_external_storage,
flash_method, bootimg=None):
codename = "-".join(pkgname.split("-")[1:])
external_storage = "true" if has_external_storage else "false"
# Note: New variables must be added to pmb/config/__init__.py as well
content = f"""\
# Reference: <https://postmarketos.org/deviceinfo>
# Please use double quotes only. You can source this file in shell scripts.
# Please use double quotes only. You can source this file in shell
# scripts.
deviceinfo_format_version="0"
deviceinfo_name="{name}"
@ -143,13 +179,12 @@ def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
deviceinfo_codename="{codename}"
deviceinfo_year="{year}"
deviceinfo_dtb=""
deviceinfo_modules_initfs=""
deviceinfo_arch="{arch}"
# Device related
deviceinfo_chassis="{chassis}"
deviceinfo_keyboard="{"true" if has_keyboard else "false"}"
deviceinfo_external_storage="{"true" if has_external_storage else "false"}"
deviceinfo_external_storage="{external_storage}"
deviceinfo_screen_width="800"
deviceinfo_screen_height="600"
@ -159,13 +194,13 @@ def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
content_heimdall_bootimg = """\
deviceinfo_flash_heimdall_partition_kernel=""
deviceinfo_flash_heimdall_partition_system=""
deviceinfo_flash_heimdall_partition_rootfs=""
"""
content_heimdall_isorec = """\
deviceinfo_flash_heimdall_partition_kernel=""
deviceinfo_flash_heimdall_partition_initfs=""
deviceinfo_flash_heimdall_partition_system=""
deviceinfo_flash_heimdall_partition_rootfs=""
"""
content_0xffff = """\
@ -177,9 +212,9 @@ def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
"""
if flash_method == "fastboot":
content += generate_deviceinfo_fastboot_content(args, bootimg)
content += generate_deviceinfo_fastboot_content(bootimg)
elif flash_method == "heimdall-bootimg":
content += generate_deviceinfo_fastboot_content(args, bootimg)
content += generate_deviceinfo_fastboot_content(bootimg)
content += content_heimdall_bootimg
elif flash_method == "heimdall-isorec":
content += content_heimdall_isorec
@ -190,21 +225,42 @@ def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
# Write to file
pmb.helpers.run.user(args, ["mkdir", "-p", args.work + "/aportgen"])
with open(args.work + "/aportgen/deviceinfo", "w", encoding="utf-8") as handle:
path = args.work + "/aportgen/deviceinfo"
with open(path, "w", encoding="utf-8") as handle:
for line in content.rstrip().split("\n"):
handle.write(line.lstrip() + "\n")
def generate_modules_initfs(args):
content = """\
# Remove this comment after reading, or the file if unnecessary (CHANGEME!)
# This file can contain a list of modules to be included in the initramfs,
# so that they are available in early boot stages. It should have one
# module name per line. If there are multiple kernel variants with different
# requirements for modules into the initramfs, one modules-initfs.$variant
# file should be created for each of them.
"""
# Write to file
pmb.helpers.run.user(args, ["mkdir", "-p", args.work + "/aportgen"])
path = args.work + "/aportgen/modules-initfs"
with open(path, "w", encoding="utf-8") as handle:
for line in content.rstrip().split("\n"):
handle.write(line.lstrip() + "\n")
def generate_apkbuild(args, pkgname, name, arch, flash_method):
# Dependencies
depends = "postmarketos-base linux-" + "-".join(pkgname.split("-")[1:])
depends = ["postmarketos-base",
"linux-" + "-".join(pkgname.split("-")[1:])]
if flash_method in ["fastboot", "heimdall-bootimg"]:
depends += " mkbootimg"
depends.append("mkbootimg")
if flash_method == "0xffff":
depends += " uboot-tools"
depends += " mesa-dri-gallium"
depends.append("uboot-tools")
# Whole APKBUILD
depends.sort()
depends = ("\n" + " " * 12).join(depends)
content = f"""\
# Reference: <https://postmarketos.org/devicepkg>
pkgname={pkgname}
@ -215,9 +271,14 @@ def generate_apkbuild(args, pkgname, name, arch, flash_method):
license="MIT"
arch="{arch}"
options="!check !archcheck"
depends="{depends}"
depends="
{depends}
"
makedepends="devicepkg-dev"
source="deviceinfo"
source="
deviceinfo
modules-initfs
"
build() {{
devicepkg_build $startdir $pkgname
@ -232,20 +293,21 @@ def generate_apkbuild(args, pkgname, name, arch, flash_method):
# Write the file
pmb.helpers.run.user(args, ["mkdir", "-p", args.work + "/aportgen"])
with open(args.work + "/aportgen/APKBUILD", "w", encoding="utf-8") as handle:
path = args.work + "/aportgen/APKBUILD"
with open(path, "w", encoding="utf-8") as handle:
for line in content.rstrip().split("\n"):
handle.write(line[8:].replace(" " * 4, "\t") + "\n")
def generate(args, pkgname):
arch = ask_for_architecture(args)
manufacturer = ask_for_manufacturer(args)
name = ask_for_name(args, manufacturer)
year = ask_for_year(args)
chassis = ask_for_chassis(args)
arch = ask_for_architecture()
manufacturer = ask_for_manufacturer()
name = ask_for_name(manufacturer)
year = ask_for_year()
chassis = ask_for_chassis()
has_keyboard = ask_for_keyboard(args)
has_external_storage = ask_for_external_storage(args)
flash_method = ask_for_flash_method(args)
flash_method = ask_for_flash_method()
bootimg = None
if flash_method in ["fastboot", "heimdall-bootimg"]:
bootimg = ask_for_bootimg(args)
@ -253,4 +315,5 @@ def generate(args, pkgname):
generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
chassis, has_keyboard, has_external_storage,
flash_method, bootimg)
generate_modules_initfs(args)
generate_apkbuild(args, pkgname, name, arch, flash_method)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.aportgen.core
import pmb.helpers.git
@ -10,33 +10,35 @@ def generate(args, pkgname):
prefix = pkgname.split("-")[0]
arch = pkgname.split("-")[1]
if prefix == "gcc":
upstream = pmb.aportgen.core.get_upstream_aport(args, "gcc")
upstream = pmb.aportgen.core.get_upstream_aport(args, "gcc", arch)
based_on = "main/gcc (from Alpine)"
elif prefix == "gcc4":
upstream = args.aports + "/main/gcc4"
upstream = f"{args.aports}/main/gcc4"
based_on = "main/gcc4 (from postmarketOS)"
elif prefix == "gcc6":
upstream = args.aports + "/main/gcc6"
upstream = f"{args.aports}/main/gcc6"
based_on = "main/gcc6 (from postmarketOS)"
else:
raise ValueError("Invalid prefix '" + prefix + "', expected gcc, gcc4 or"
raise ValueError(f"Invalid prefix '{prefix}', expected gcc, gcc4 or"
" gcc6.")
pmb.helpers.run.user(args, ["cp", "-r", upstream, args.work + "/aportgen"])
pmb.helpers.run.user(args, ["cp", "-r", upstream, f"{args.work}/aportgen"])
# Rewrite APKBUILD (only building for x86_64 covers most use cases and
# Rewrite APKBUILD (only building for native covers most use cases and
# saves a lot of build time, can be changed on demand)
fields = {
"pkgname": pkgname,
"pkgdesc": "Stage2 cross-compiler for " + arch,
"arch": "x86_64",
"depends": "isl binutils-" + arch + " mpc1",
"makedepends_build": "gcc g++ paxmark bison flex texinfo gawk zip gmp-dev mpfr-dev mpc1-dev zlib-dev",
"makedepends_host": "linux-headers gmp-dev mpfr-dev mpc1-dev isl-dev zlib-dev musl-dev-" + arch + " binutils-" + arch,
"subpackages": "g++-" + arch + ":gpp" if prefix == "gcc" else "",
"pkgdesc": f"Stage2 cross-compiler for {arch}",
"arch": pmb.config.arch_native,
"depends": f"binutils-{arch} mpc1",
"makedepends_build": "gcc g++ bison flex texinfo gawk zip"
" gmp-dev mpfr-dev mpc1-dev zlib-dev",
"makedepends_host": "linux-headers gmp-dev mpfr-dev mpc1-dev isl-dev"
f" zlib-dev musl-dev-{arch} binutils-{arch}",
"subpackages": "",
# gcc6: options is already there, so we need to replace it and not only
# set it below the header like done below.
"options": "!strip !tracedeps",
"options": "!strip",
"LIBGOMP": "false",
"LIBGCC": "false",
@ -44,6 +46,11 @@ def generate(args, pkgname):
"LIBITM": "false",
}
# Latest gcc only, not gcc4 and gcc6
if prefix == "gcc":
fields["subpackages"] = f"g++-{arch}:gpp" \
f" libstdc++-dev-{arch}:libcxx_dev"
below_header = "CTARGET_ARCH=" + arch + """
CTARGET="$(arch_to_hostspec ${CTARGET_ARCH})"
LANG_D=false
@ -52,7 +59,7 @@ def generate(args, pkgname):
LANG_GO=false
LANG_FORTRAN=false
LANG_ADA=false
options="!strip !tracedeps"
options="!strip"
# abuild doesn't try to tries to install "build-base-$CTARGET_ARCH"
# when this variable matches "no*"
@ -76,6 +83,9 @@ def generate(args, pkgname):
# use CBUILDROOT as sysroot. In the original APKBUILD this is a local
# variable, but we make it a global one.
'*_cross_configure=*': None,
# Do not build foreign arch libgcc, we use the one from Alpine (#2168)
'_libgcc=true*': '_libgcc=false',
}
pmb.aportgen.core.rewrite(args, pkgname, based_on, fields,

View File

@ -1,12 +1,11 @@
# Copyright 2020 Nick Reitemeyer
# Copyright 2023 Nick Reitemeyer, Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import os
import pmb.helpers.run
import pmb.aportgen.core
import pmb.parse.apkindex
import pmb.build
import pmb.chroot.apk
import pmb.chroot.apk_static
import pmb.helpers.run
import pmb.parse.apkindex
def generate(args, pkgname):
@ -18,54 +17,47 @@ def generate(args, pkgname):
pkgver = version.split("-r")[0]
pkgrel = version.split("-r")[1]
pmb.chroot.apk.install(args, ["grub-efi"], "buildroot_x86")
pattern = (args.work + "/cache_apk_" + arch + "/grub-efi-" +
version + ".*.apk")
glob_result = glob.glob(pattern)
if not len(glob_result):
raise RuntimeError("Could not find aport " + pattern + "!"
" Update your aports_upstream git repo"
" to the latest version, delete your http cache"
" (pmbootstrap zap -hc) and try again.")
path = glob_result[0]
path_target = (args.work + "/cache_distfiles/grub-efi-" +
version + "-" + arch + ".apk")
if not os.path.exists(path_target):
pmb.helpers.run.root(args, ["cp", path, path_target])
# Prepare aportgen tempdir inside and outside of chroot
tempdir = "/tmp/aportgen"
pmb.chroot.root(args, ["rm", "-rf", tempdir])
pmb.helpers.run.user(args, ["mkdir", "-p", f"{args.work}/aportgen",
f"{args.work}/chroot_native/{tempdir}"])
# Hash the distfile
hashes = pmb.chroot.user(args, ["sha512sum",
"grub-efi-" + version + "-" + arch + ".apk"],
"buildroot_" + arch, "/var/cache/distfiles",
output_return=True)
# Write the APKBUILD
channel_cfg = pmb.config.pmaports.read_config_channel(args)
mirrordir = channel_cfg["mirrordir_alpine"]
apkbuild_path = f"{args.work}/chroot_native/{tempdir}/APKBUILD"
apk_name = f'"$srcdir/grub-efi-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk"'
with open(apkbuild_path, "w", encoding="utf-8") as handle:
apkbuild = f"""\
# Automatically generated aport, do not edit!
# Generator: pmbootstrap aportgen {pkgname}
pkgname={pkgname}
pkgver={pkgver}
pkgrel={pkgrel}
_arch="{arch}"
_mirror="{pmb.config.aportgen_mirror_alpine}"
pmb.helpers.run.user(args, ["mkdir", "-p", args.work + "/aportgen"])
with open(args.work + "/aportgen/APKBUILD", "w", encoding="utf-8") as handle:
handle.write("# Automatically generated aport, do not edit!\n"
"# Generator: pmbootstrap aportgen " + pkgname + "\n"
"\n"
"pkgname=" + pkgname + "\n"
"pkgver=" + pkgver + "\n"
"pkgrel=" + pkgrel + "\n"
"\n"
"_arch=\"" + arch + "\"\n"
"_mirror=\"" + args.mirror_alpine + "\"\n"
)
static = """
pkgdesc="GRUB $_arch EFI files for every architecture"
url="https://www.gnu.org/software/grub/"
license="GPL-3.0-or-later"
arch="all"
source="grub-efi-$pkgver-r$pkgrel-$_arch.apk::$_mirror/edge/main/$_arch/grub-efi-$pkgver-r$pkgrel.apk"
arch="{pmb.config.arch_native}"
source="grub-efi-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk::$_mirror/{mirrordir}/main/$_arch/grub-efi-$pkgver-r$pkgrel.apk"
package() {
package() {{
mkdir -p "$pkgdir"
cd "$pkgdir"
tar -xf "$srcdir/grub-efi-$pkgver-r$pkgrel-$_arch.apk"
tar -xf {apk_name}
rm .PKGINFO .SIGN.*
}
}}
"""
for line in static.split("\n"):
handle.write(line[12:] + "\n")
for line in apkbuild.split("\n"):
handle.write(line[12:].replace(" " * 4, "\t") + "\n")
handle.write("sha512sums=\"" + hashes.rstrip() + "\"\n")
# Generate checksums
pmb.build.init_abuild_minimal(args)
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir])
pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir)
pmb.helpers.run.user(args, ["cp", apkbuild_path, f"{args.work}/aportgen"])

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.helpers.run
import pmb.aportgen.core
@ -10,19 +10,54 @@ def generate_apkbuild(args, pkgname, deviceinfo, patches):
device = "-".join(pkgname.split("-")[1:])
carch = pmb.parse.arch.alpine_to_kernel(deviceinfo["arch"])
makedepends = "bash bc bison devicepkg-dev flex openssl-dev perl"
makedepends = ["bash", "bc", "bison", "devicepkg-dev", "findutils", "flex",
"openssl-dev", "perl"]
build = """
unset LDFLAGS
make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \\
KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS\""""
package = """
downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir\""""
downstreamkernel_package "$builddir" "$pkgdir" "$_carch\" \\
"$_flavor" "$_outdir\""""
if deviceinfo.get("header_version") == "2":
package += """
make dtbs_install O="$_outdir" ARCH="$_carch" \\
INSTALL_DTBS_PATH="$pkgdir\"/boot/dtbs"""
if deviceinfo["bootimg_qcdt"] == "true":
makedepends += " dtbtool"
package += """\n
# Master DTB (deviceinfo_bootimg_qcdt)
dtbTool -p scripts/dtc/ -o "$_outdir/arch/$_carch/boot"/dt.img "$_outdir/arch/$_carch/boot/"
install -Dm644 "$_outdir/arch/$_carch/boot"/dt.img "$pkgdir"/boot/dt.img"""
build += """\n
# Master DTB (deviceinfo_bootimg_qcdt)"""
vendors = ["spreadtrum", "exynos", "other"]
soc_vendor = pmb.helpers.cli.ask("SoC vendor", vendors,
vendors[-1], complete=vendors)
if soc_vendor == "spreadtrum":
makedepends.append("dtbtool-sprd")
build += """
dtbTool-sprd -p "$_outdir/scripts/dtc/" \\
-o "$_outdir/arch/$_carch/boot"/dt.img \\
"$_outdir/arch/$_carch/boot/dts/\""""
elif soc_vendor == "exynos":
codename = "-".join(pkgname.split("-")[2:])
makedepends.append("dtbtool-exynos")
build += """
dtbTool-exynos -o "$_outdir/arch/$_carch/boot"/dt.img \\
$(find "$_outdir/arch/$_carch/boot/dts/\""""
build += f" -name *{codename}*.dtb)"
else:
makedepends.append("dtbtool")
build += """
dtbTool -o "$_outdir/arch/$_carch/boot"/dt.img \\
"$_outdir/arch/$_carch/boot/\""""
package += """
install -Dm644 "$_outdir/arch/$_carch/boot"/dt.img \\
"$pkgdir"/boot/dt.img"""
makedepends.sort()
makedepends = ("\n" + " " * 12).join(makedepends)
patches = ("\n" + " " * 12).join(patches)
content = f"""\
# Reference: <https://postmarketos.org/vendorkernel>
@ -38,7 +73,9 @@ def generate_apkbuild(args, pkgname, deviceinfo, patches):
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="{makedepends}"
makedepends="
{makedepends}
"
# Source
_repository="(CHANGEME!)"
@ -57,10 +94,7 @@ def generate_apkbuild(args, pkgname, deviceinfo, patches):
. downstreamkernel_prepare
}}
build() {{
unset LDFLAGS
make O="$_outdir" ARCH="$_carch" CC="${{CC:-gcc}}" \\
KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
build() {{{build}
}}
package() {{{package}
@ -70,9 +104,9 @@ def generate_apkbuild(args, pkgname, deviceinfo, patches):
"""
# Write the file
with open(args.work + "/aportgen/APKBUILD", "w", encoding="utf-8") as handle:
with open(f"{args.work}/aportgen/APKBUILD", "w", encoding="utf-8") as hndl:
for line in content.rstrip().split("\n"):
handle.write(line[8:].replace(" " * 4, "\t") + "\n")
hndl.write(line[8:].replace(" " * 4, "\t") + "\n")
def generate(args, pkgname):
@ -84,6 +118,7 @@ def generate(args, pkgname):
patches = [
"gcc7-give-up-on-ilog2-const-optimizations.patch",
"gcc8-fix-put-user.patch",
"gcc10-extern_YYLOC_global_declaration.patch",
"kernel-use-the-gnu89-standard-explicitly.patch",
]
for patch in patches:

View File

@ -1,18 +1,15 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import os
import pmb.helpers.run
import pmb.aportgen.core
import pmb.parse.apkindex
import pmb.build
import pmb.chroot.apk
import pmb.chroot.apk_static
import pmb.helpers.run
import pmb.parse.apkindex
def generate(args, pkgname):
# Install musl in chroot to get verified apks
arch = pkgname.split("-")[1]
pmb.chroot.apk.install(args, ["musl-dev"], "buildroot_" + arch)
# Parse musl version from APKINDEX
package_data = pmb.parse.apkindex.package(args, "musl")
@ -20,50 +17,37 @@ def generate(args, pkgname):
pkgver = version.split("-r")[0]
pkgrel = version.split("-r")[1]
# Architectures to build this package for
arches = list(pmb.config.build_device_architectures)
arches.remove(arch)
# Copy the apk files to the distfiles cache
for subpkgname in ["musl", "musl-dev"]:
pattern = (args.work + "/cache_apk_" + arch + "/" + subpkgname +
"-" + version + ".*.apk")
glob_result = glob.glob(pattern)
if not len(glob_result):
raise RuntimeError("Could not find aport " + pattern + "!"
" Update your aports_upstream git repo"
" to the latest version, delete your http cache"
" (pmbootstrap zap -hc) and try again.")
path = glob_result[0]
path_target = (args.work + "/cache_distfiles/" + subpkgname + "-" +
version + "-" + arch + ".apk")
if not os.path.exists(path_target):
pmb.helpers.run.root(args, ["cp", path, path_target])
# Hash the distfiles
hashes = pmb.chroot.user(args, ["sha512sum",
"musl-" + version + "-" + arch + ".apk",
"musl-dev-" + version + "-" + arch + ".apk"], "buildroot_" + arch,
"/var/cache/distfiles", output_return=True)
# Prepare aportgen tempdir inside and outside of chroot
tempdir = "/tmp/aportgen"
pmb.chroot.root(args, ["rm", "-rf", tempdir])
pmb.helpers.run.user(args, ["mkdir", "-p", f"{args.work}/aportgen",
f"{args.work}/chroot_native/{tempdir}"])
# Write the APKBUILD
pmb.helpers.run.user(args, ["mkdir", "-p", args.work + "/aportgen"])
with open(args.work + "/aportgen/APKBUILD", "w", encoding="utf-8") as handle:
# Variables
handle.write("# Automatically generated aport, do not edit!\n"
"# Generator: pmbootstrap aportgen " + pkgname + "\n"
"\n"
"pkgname=\"" + pkgname + "\"\n"
"pkgver=\"" + pkgver + "\"\n"
"pkgrel=" + pkgrel + "\n"
"arch=\"" + " ".join(arches) + "\"\n"
"subpackages=\"musl-dev-" + arch + ":package_dev\"\n"
"\n"
"_arch=\"" + arch + "\"\n"
"_mirror=\"" + args.mirror_alpine + "\"\n"
)
# Static part
static = """
channel_cfg = pmb.config.pmaports.read_config_channel(args)
mirrordir = channel_cfg["mirrordir_alpine"]
apkbuild_path = f"{args.work}/chroot_native/{tempdir}/APKBUILD"
apk_name = f"$srcdir/musl-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk"
apk_dev_name = f"$srcdir/musl-dev-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk"
with open(apkbuild_path, "w", encoding="utf-8") as handle:
apkbuild = f"""\
# Automatically generated aport, do not edit!
# Generator: pmbootstrap aportgen {pkgname}
# Stub for apkbuild-lint
if [ -z "$(type -t arch_to_hostspec)" ]; then
arch_to_hostspec() {{ :; }}
fi
pkgname={pkgname}
pkgver={pkgver}
pkgrel={pkgrel}
arch="{pmb.config.arch_native}"
subpackages="musl-dev-{arch}:package_dev"
_arch="{arch}"
_mirror="{pmb.config.aportgen_mirror_alpine}"
url="https://musl-libc.org"
license="MIT"
options="!check !strip"
@ -72,28 +56,29 @@ def generate(args, pkgname):
_target="$(arch_to_hostspec $_arch)"
source="
musl-$pkgver-r$pkgrel-$_arch.apk::$_mirror/edge/main/$_arch/musl-$pkgver-r$pkgrel.apk
musl-dev-$pkgver-r$pkgrel-$_arch.apk::$_mirror/edge/main/$_arch/musl-dev-$pkgver-r$pkgrel.apk
musl-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk::$_mirror/{mirrordir}/main/$_arch/musl-$pkgver-r$pkgrel.apk
musl-dev-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk::$_mirror/{mirrordir}/main/$_arch/musl-dev-$pkgver-r$pkgrel.apk
"
package() {
package() {{
mkdir -p "$pkgdir/usr/$_target"
cd "$pkgdir/usr/$_target"
# Use 'busybox tar' to avoid 'tar: Child returned status 141'
# on some machines (builds.sr.ht, gitlab-ci). See pmaports#26.
busybox tar -xf $srcdir/musl-$pkgver-r$pkgrel-$_arch.apk
busybox tar -xf {apk_name}
rm .PKGINFO .SIGN.*
}
package_dev() {
}}
package_dev() {{
mkdir -p "$subpkgdir/usr/$_target"
cd "$subpkgdir/usr/$_target"
# Use 'busybox tar' to avoid 'tar: Child returned status 141'
# on some machines (builds.sr.ht, gitlab-ci). See pmaports#26.
busybox tar -xf $srcdir/musl-dev-$pkgver-r$pkgrel-$_arch.apk
busybox tar -xf {apk_dev_name}
rm .PKGINFO .SIGN.*
# symlink everything from /usr/$_target/usr/* to /usr/$_target/*
# so the cross-compiler gcc does not fail to build.
# symlink everything from /usr/$_target/usr/*
# to /usr/$_target/* so the cross-compiler gcc does not fail
# to build.
for _dir in include lib; do
mkdir -p "$subpkgdir/usr/$_target/$_dir"
cd "$subpkgdir/usr/$_target/usr/$_dir"
@ -102,10 +87,13 @@ def generate(args, pkgname):
ln -s /usr/$_target/usr/$_dir/$i $i
done
done
}
}}
"""
for line in static.split("\n"):
handle.write(line[12:] + "\n")
for line in apkbuild.split("\n"):
handle.write(line[12:].replace(" " * 4, "\t") + "\n")
# Hashes
handle.write("sha512sums=\"" + hashes.rstrip() + "\"\n")
# Generate checksums
pmb.build.init_abuild_minimal(args)
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir])
pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir)
pmb.helpers.run.user(args, ["cp", apkbuild_path, f"{args.work}/aportgen"])

View File

@ -1,9 +1,9 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb.build.init import init
from pmb.build.init import init, init_abuild_minimal, init_compiler
from pmb.build.envkernel import package_kernel
from pmb.build.menuconfig import menuconfig
from pmb.build.kconfig import menuconfig
from pmb.build.newapkbuild import newapkbuild
from pmb.build.other import copy_to_buildpath, is_necessary, \
index_repo
from pmb.build._package import package
from pmb.build._package import mount_pmaports, package

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import datetime
import logging
@ -8,27 +8,26 @@ import pmb.build
import pmb.build.autodetect
import pmb.chroot
import pmb.chroot.apk
import pmb.chroot.distccd
import pmb.helpers.pmaports
import pmb.helpers.repo
import pmb.parse
import pmb.parse.arch
def skip_already_built(args, pkgname, arch):
def skip_already_built(pkgname, arch):
"""
Check if the package was already built in this session, and add it
to the cache in case it was not built yet.
:returns: True when it can be skipped or False
"""
if arch not in args.cache["built"]:
args.cache["built"][arch] = []
if pkgname in args.cache["built"][arch]:
if arch not in pmb.helpers.other.cache["built"]:
pmb.helpers.other.cache["built"][arch] = []
if pkgname in pmb.helpers.other.cache["built"][arch]:
logging.verbose(pkgname + ": already checked this session,"
" no need to build it or its dependencies")
return True
args.cache["built"][arch].append(pkgname)
pmb.helpers.other.cache["built"][arch].append(pkgname)
return False
@ -104,7 +103,8 @@ def get_depends(args, apkbuild):
ret = sorted(set(ret))
# Don't recurse forever when a package depends on itself (#948)
for pkgname in [apkbuild["pkgname"]] + list(apkbuild["subpackages"].keys()):
for pkgname in ([apkbuild["pkgname"]] +
list(apkbuild["subpackages"].keys())):
if pkgname in ret:
logging.verbose(apkbuild["pkgname"] + ": ignoring dependency on"
" itself: " + pkgname)
@ -129,6 +129,9 @@ def build_depends(args, apkbuild, arch, strict):
if "no_depends" in args and args.no_depends:
pmb.helpers.repo.update(args, arch)
for depend in depends:
# Ignore conflicting dependencies
if depend.startswith("!"):
continue
# Check if binary package is missing
if not pmb.parse.apkindex.package(args, depend, arch, False):
raise RuntimeError("Missing binary package for dependency '" +
@ -137,7 +140,8 @@ def build_depends(args, apkbuild, arch, strict):
" it was started with --no-depends.")
# Check if binary package is outdated
apkbuild_dep = get_apkbuild(args, depend, arch)
if apkbuild_dep and pmb.build.is_necessary(args, arch, apkbuild_dep):
if apkbuild_dep and \
pmb.build.is_necessary(args, arch, apkbuild_dep):
raise RuntimeError(f"Binary package for dependency '{depend}'"
f" of '{pkgname}' is outdated, but"
f" pmbootstrap won't build any depends"
@ -145,6 +149,8 @@ def build_depends(args, apkbuild, arch, strict):
else:
# Build the dependencies
for depend in depends:
if depend.startswith("!"):
continue
if package(args, depend, arch, strict=strict):
depends_built += [depend]
logging.verbose(pkgname + ": build dependencies: done, built: " +
@ -169,11 +175,8 @@ def is_necessary_warn_depends(args, apkbuild, arch, force, depends_built):
ret = True
if not ret and len(depends_built):
# Warn of potentially outdated package
logging.warning("WARNING: " + pkgname + " depends on rebuilt" +
" package(s) " + ",".join(depends_built) + " (use" +
" 'pmbootstrap build " + pkgname + " --force' if" +
" necessary!)")
logging.verbose(f"{pkgname}: depends on rebuilt package(s): "
f" {', '.join(depends_built)}")
logging.verbose(pkgname + ": build necessary: " + str(ret))
return ret
@ -186,7 +189,7 @@ def init_buildenv(args, apkbuild, arch, strict=False, force=False, cross=None,
just initialized the build environment for nothing) and then setup the
whole build environment (abuild, gcc, dependencies, cross-compiler).
:param cross: None, "native", "distcc", or "crossdirect"
:param cross: None, "native", or "crossdirect"
:param skip_init_buildenv: can be set to False to avoid initializing the
build environment. Use this when building
something during initialization of the build
@ -197,7 +200,7 @@ def init_buildenv(args, apkbuild, arch, strict=False, force=False, cross=None,
depends_arch = arch
if cross == "native":
depends_arch = args.arch_native
depends_arch = pmb.config.arch_native
# Build dependencies
depends, built = build_depends(args, apkbuild, depends_arch, strict)
@ -210,7 +213,10 @@ def init_buildenv(args, apkbuild, arch, strict=False, force=False, cross=None,
if not skip_init_buildenv:
pmb.build.init(args, suffix)
pmb.build.other.configure_abuild(args, suffix)
pmb.build.other.configure_ccache(args, suffix)
if args.ccache:
pmb.build.other.configure_ccache(args, suffix)
if "rust" in depends or "cargo" in depends:
pmb.chroot.apk.install(args, ["sccache"], suffix)
if not strict and "pmb:strict" not in apkbuild["options"] and len(depends):
pmb.chroot.apk.install(args, depends, suffix)
if src:
@ -218,41 +224,13 @@ def init_buildenv(args, apkbuild, arch, strict=False, force=False, cross=None,
# Cross-compiler init
if cross:
cross_pkgs = ["ccache-cross-symlinks"]
if "gcc4" in depends:
cross_pkgs += ["gcc4-" + arch]
elif "gcc6" in depends:
cross_pkgs += ["gcc6-" + arch]
else:
cross_pkgs += ["gcc-" + arch, "g++-" + arch]
if "clang" in depends or "clang-dev" in depends:
cross_pkgs += ["clang"]
if cross == "crossdirect":
cross_pkgs += ["crossdirect"]
if "rust" in depends or "cargo" in depends:
cross_pkgs += ["rust"]
pmb.chroot.apk.install(args, cross_pkgs)
if cross == "distcc":
pmb.chroot.distccd.start(args, arch)
pmb.build.init_compiler(args, depends, cross, arch)
if cross == "crossdirect":
pmb.chroot.mount_native_into_foreign(args, suffix)
return True
def get_gcc_version(args, arch):
"""
Get the GCC version for a specific arch from parsing the right APKINDEX.
We feed this to ccache, so it knows the right GCC version, when
cross-compiling in a foreign arch chroot with distcc. See the "using
ccache with other compiler wrappers" section of their man page:
<https://linux.die.net/man/1/ccache>
:returns: a string like "6.4.0-r5"
"""
return pmb.parse.apkindex.package(args, "gcc-" + arch,
args.arch_native)["version"]
def get_pkgver(original_pkgver, original_source=False, now=None):
"""
Get the original pkgver when using the original source. Otherwise, get the
@ -285,7 +263,7 @@ def override_source(args, apkbuild, pkgver, src, suffix="native"):
return
# Mount source in chroot
mount_path = "/mnt/pmbootstrap-source-override/"
mount_path = "/mnt/pmbootstrap/source-override/"
mount_path_outside = args.work + "/chroot_" + suffix + mount_path
pmb.helpers.mount.bind(args, src, mount_path_outside, umount=True)
@ -344,6 +322,16 @@ def override_source(args, apkbuild, pkgver, src, suffix="native"):
pmb.chroot.user(args, ["mv", append_path + "_", apkbuild_path], suffix)
def mount_pmaports(args, destination, suffix="native"):
"""
Mount pmaports.git in chroot.
:param destination: mount point inside the chroot
"""
outside_destination = args.work + "/chroot_" + suffix + destination
pmb.helpers.mount.bind(args, args.aports, outside_destination, umount=True)
def link_to_git_dir(args, suffix):
"""
Make /home/pmos/build/.git point to the .git dir from pmaports.git, with a
@ -364,13 +352,12 @@ def link_to_git_dir(args, suffix):
# initialization of the chroot, because the pmaports dir may not exist yet
# at that point. Use umount=True, so we don't have an old path mounted
# (some tests change the pmaports dir).
inside_destination = "/mnt/pmaports"
outside_destination = args.work + "/chroot_" + suffix + inside_destination
pmb.helpers.mount.bind(args, args.aports, outside_destination, umount=True)
destination = "/mnt/pmaports"
mount_pmaports(args, destination, suffix)
# Create .git symlink
pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/build"], suffix)
pmb.chroot.user(args, ["ln", "-sf", inside_destination + "/.git",
pmb.chroot.user(args, ["ln", "-sf", destination + "/.git",
"/home/pmos/build/.git"], suffix)
@ -381,7 +368,7 @@ def run_abuild(args, apkbuild, arch, strict=False, force=False, cross=None,
depending on the cross-compiler method and target architecture), copy
the aport to the chroot and execute abuild.
:param cross: None, "native", "distcc", or "crossdirect"
:param cross: None, "native", or "crossdirect"
:param src: override source used to build the package with a local folder
:returns: (output, cmd, env), output is the destination apk path relative
to the package folder ("x86_64/hello-1-r2.apk"). cmd and env are
@ -410,24 +397,28 @@ def run_abuild(args, apkbuild, arch, strict=False, force=False, cross=None,
hostspec = pmb.parse.arch.alpine_to_hostspec(arch)
env["CROSS_COMPILE"] = hostspec + "-"
env["CC"] = hostspec + "-gcc"
if cross == "distcc":
env["CCACHE_PREFIX"] = "distcc"
env["CCACHE_PATH"] = "/usr/lib/arch-bin-masquerade/" + arch + ":/usr/bin"
env["CCACHE_COMPILERCHECK"] = "string:" + get_gcc_version(args, arch)
env["DISTCC_HOSTS"] = "@127.0.0.1:/home/pmos/.distcc-sshd/distccd"
env["DISTCC_SSH"] = ("ssh -o StrictHostKeyChecking=no -p" +
args.port_distccd)
env["DISTCC_BACKOFF_PERIOD"] = "0"
if not args.distcc_fallback:
env["DISTCC_FALLBACK"] = "0"
if args.verbose:
env["DISTCC_VERBOSE"] = "1"
if cross == "crossdirect":
env["PATH"] = ":".join(["/native/usr/lib/crossdirect/" + arch,
pmb.config.chroot_path])
if not args.ccache:
env["CCACHE_DISABLE"] = "1"
# Use sccache without crossdirect (crossdirect uses it via rustc.sh)
if args.ccache and cross != "crossdirect":
env["RUSTC_WRAPPER"] = "/usr/bin/sccache"
# Cache binary objects from go in this path (like ccache)
env["GOCACHE"] = "/home/pmos/.cache/go-build"
# Cache go modules (git repositories). Usually these should be bundled and
# it should not be required to download them at build time, in that case
# the APKBUILD sets the GOPATH (and therefore indirectly GOMODCACHE). But
# e.g. when using --src they are not bundled, in that case it makes sense
# to point GOMODCACHE at pmbootstrap's work dir so the modules are only
# downloaded once.
if args.go_mod_cache:
env["GOMODCACHE"] = "/home/pmos/go/pkg/mod"
# Build the abuild command
cmd = ["abuild", "-D", "postmarketOS"]
if strict or "pmb:strict" in apkbuild["options"]:
@ -461,14 +452,17 @@ def finish(args, apkbuild, arch, output, strict=False, suffix="native"):
# Clear APKINDEX cache (we only parse APKINDEX files once per session and
# cache the result for faster dependency resolving, but after we built a
# package we need to parse it again)
pmb.parse.apkindex.clear_cache(args, f"{args.work}/packages/{channel}"
f"/{arch}/APKINDEX.tar.gz")
pmb.parse.apkindex.clear_cache(f"{args.work}/packages/{channel}"
f"/{arch}/APKINDEX.tar.gz")
# Uninstall build dependencies (strict mode)
if strict or "pmb:strict" in apkbuild["options"]:
logging.info("(" + suffix + ") uninstall build dependencies")
pmb.chroot.user(args, ["abuild", "undeps"], suffix, "/home/pmos/build",
env={"SUDO_APK": "abuild-apk --no-progress"})
# If the build depends contain postmarketos-keys or postmarketos-base,
# abuild will have removed the postmarketOS repository key (pma#1230)
pmb.chroot.init_keys(args)
def package(args, pkgname, arch=None, force=False, strict=False,
@ -476,9 +470,14 @@ def package(args, pkgname, arch=None, force=False, strict=False,
"""
Build a package and its dependencies with Alpine Linux' abuild.
If this function is called multiple times on the same pkgname but first
with force=False and then force=True the force argument will be ignored due
to the package cache.
See the skip_already_built() call below.
:param pkgname: package name to be built, as specified in the APKBUILD
:param arch: architecture we're building for (default: native)
:param force: even build, if not necessary
:param force: always build, even if not necessary
:param strict: avoid building with irrelevant dependencies installed by
letting abuild install and uninstall all dependencies.
:param skip_init_buildenv: can be set to False to avoid initializing the
@ -490,8 +489,8 @@ def package(args, pkgname, arch=None, force=False, strict=False,
output path relative to the packages folder ("armhf/ab-1-r2.apk")
"""
# Once per session is enough
arch = arch or args.arch_native
if skip_already_built(args, pkgname, arch):
arch = arch or pmb.config.arch_native
if skip_already_built(pkgname, arch):
return
# Only build when APKBUILD exists
@ -502,7 +501,7 @@ def package(args, pkgname, arch=None, force=False, strict=False,
# Detect the build environment (skip unnecessary builds)
if not check_build_for_arch(args, pkgname, arch):
return
suffix = pmb.build.autodetect.suffix(args, apkbuild, arch)
suffix = pmb.build.autodetect.suffix(apkbuild, arch)
cross = pmb.build.autodetect.crosscompile(args, apkbuild, arch, suffix)
if not init_buildenv(args, apkbuild, arch, strict, force, cross, suffix,
skip_init_buildenv, src):

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
@ -40,7 +40,7 @@ def arch(args, pkgname):
:returns: arch string like "x86_64" or "armhf". Preferred order, depending
on what is supported by the APKBUILD:
* native arch
* device arch
* device arch (this will be preferred instead if build_default_device_arch is true)
* first arch in the APKBUILD
"""
aport = pmb.helpers.pmaports.find(args, pkgname)
@ -48,20 +48,30 @@ def arch(args, pkgname):
if ret:
return ret
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
apkbuild = pmb.parse.apkbuild(f"{aport}/APKBUILD")
arches = apkbuild["arch"]
if "noarch" in arches or "all" in arches or args.arch_native in arches:
return args.arch_native
arch_device = args.deviceinfo["arch"]
if arch_device in arches:
return arch_device
if args.build_default_device_arch:
preferred_arch = args.deviceinfo["arch"]
preferred_arch_2nd = pmb.config.arch_native
else:
preferred_arch = pmb.config.arch_native
preferred_arch_2nd = args.deviceinfo["arch"]
return apkbuild["arch"][0]
if "noarch" in arches or "all" in arches or preferred_arch in arches:
return preferred_arch
if preferred_arch_2nd in arches:
return preferred_arch_2nd
try:
return apkbuild["arch"][0]
except IndexError:
return None
def suffix(args, apkbuild, arch):
if arch == args.arch_native:
def suffix(apkbuild, arch):
if arch == pmb.config.arch_native:
return "native"
if "pmb:cross-native" in apkbuild["options"]:
@ -72,14 +82,14 @@ def suffix(args, apkbuild, arch):
def crosscompile(args, apkbuild, arch, suffix):
"""
:returns: None, "native", "crossdirect" or "distcc"
:returns: None, "native", "crossdirect"
"""
if not args.cross:
return None
if not pmb.parse.arch.cpu_emulation_required(args, arch):
if not pmb.parse.arch.cpu_emulation_required(arch):
return None
if suffix == "native":
return "native"
if args.no_crossdirect or "!pmb:crossdirect" in apkbuild["options"]:
return "distcc"
if "!pmb:crossdirect" in apkbuild["options"]:
return None
return "crossdirect"

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
@ -10,7 +10,7 @@ import pmb.helpers.pmaports
def update(args, pkgname):
""" Fetch all sources and update the checksums in the APKBUILD. """
pmb.build.init(args)
pmb.build.init_abuild_minimal(args)
pmb.build.copy_to_buildpath(args, pkgname)
logging.info("(native) generate checksums for " + pkgname)
pmb.chroot.user(args, ["abuild", "checksum"],
@ -24,7 +24,7 @@ def update(args, pkgname):
def verify(args, pkgname):
""" Fetch all sources and verify their checksums. """
pmb.build.init(args)
pmb.build.init_abuild_minimal(args)
pmb.build.copy_to_buildpath(args, pkgname)
logging.info("(native) verify checksums for " + pkgname)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Robert Yang
# Copyright 2023 Robert Yang
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
@ -12,14 +12,14 @@ import pmb.helpers.pmaports
import pmb.parse
def match_kbuild_out(args, word):
def match_kbuild_out(word):
"""
Look for paths in the following formats:
"<prefix>/<kbuild_out>/arch/<arch>/boot"
"<prefix>/<kbuild_out>/include/config/kernel.release"
:param word: space separated string cut out from a line from an APKBUILD
function body, that might be the kbuild output path
function body that might be the kbuild output path
:returns: kernel build output directory.
empty string when a separate build output directory isn't used.
None, when no output directory is found.
@ -47,7 +47,7 @@ def match_kbuild_out(args, word):
return "" if out_dir is None else out_dir.strip("/")
def find_kbuild_output_dir(args, function_body):
def find_kbuild_output_dir(function_body):
"""
Guess what the kernel build output directory is. Parses each line of the
function word by word, looking for paths which contain the kbuild output
@ -61,7 +61,7 @@ def find_kbuild_output_dir(args, function_body):
guesses = []
for line in function_body:
for item in line.split():
kbuild_out = match_kbuild_out(args, item)
kbuild_out = match_kbuild_out(item)
if kbuild_out is not None:
guesses.append(kbuild_out)
break
@ -86,7 +86,7 @@ def modify_apkbuild(args, pkgname, aport):
Modify kernel APKBUILD to package build output from envkernel.sh
"""
apkbuild_path = aport + "/APKBUILD"
apkbuild = pmb.parse.apkbuild(args, apkbuild_path)
apkbuild = pmb.parse.apkbuild(apkbuild_path)
if os.path.exists(args.work + "/aportgen"):
pmb.helpers.run.user(args, ["rm", "-r", args.work + "/aportgen"])
@ -104,6 +104,23 @@ def modify_apkbuild(args, pkgname, aport):
pmb.aportgen.core.rewrite(args, pkgname, apkbuild_path, fields=fields)
def host_build_bindmount(args, chroot, flag_file, mount=False):
"""
Check if the bind mount already exists and unmount it.
Then bindmount the current directory into the chroot as
/mnt/linux so it can be used by the envkernel abuild wrapper
"""
flag_path = f"{chroot}/{flag_file}"
if os.path.exists(flag_path):
logging.info("Cleaning up kernel sources bind-mount")
pmb.helpers.run.root(args, ["umount", chroot + "/mnt/linux"], check=False)
pmb.helpers.run.root(args, ["rm", flag_path])
if mount:
pmb.helpers.mount.bind(args, ".", f"{chroot}/mnt/linux")
pmb.helpers.run.root(args, ["touch", flag_path])
def run_abuild(args, pkgname, arch, apkbuild_path, kbuild_out):
"""
Prepare build environment and run abuild.
@ -117,10 +134,30 @@ def run_abuild(args, pkgname, arch, apkbuild_path, kbuild_out):
build_path = "/home/pmos/build"
kbuild_out_source = "/mnt/linux/.output"
# If the kernel was cross-compiled on the host rather than with the envkernel
# helper, we can still use the envkernel logic to package the artifacts for
# development, making it easy to quickly sideload a new kernel or pmbootstrap
# to create a boot image
# This handles bind mounting the current directory (assumed to be kernel sources)
# into the chroot so we can run abuild against it for the currently selected
# devices kernel package.
flag_file = "envkernel-bind-mounted"
host_build = False
if not pmb.helpers.mount.ismount(chroot + "/mnt/linux"):
logging.info("envkernel.sh hasn't run, assuming the kernel was cross compiled"
"on host and using current dir as source")
host_build = True
host_build_bindmount(args, chroot, flag_file, mount=host_build)
if not os.path.exists(chroot + kbuild_out_source):
raise RuntimeError("No '.output' dir found in your kernel source dir."
"Compile the " + args.device + " kernel with "
"envkernel.sh first, then try again.")
raise RuntimeError("No '.output' dir found in your kernel source dir. "
"Compile the " + args.device + " kernel first and "
"then try again. See https://postmarketos.org/envkernel"
"for details. If building on your host and only using "
"--envkernel for packaging, make sure you have O=.output "
"as an argument to make.")
# Create working directory for abuild
pmb.build.copy_to_buildpath(args, pkgname)
@ -142,11 +179,14 @@ def run_abuild(args, pkgname, arch, apkbuild_path, kbuild_out):
# Create the apk package
env = {"CARCH": arch,
"CHOST": arch,
"CBUILD": args.arch_native,
"CBUILD": pmb.config.arch_native,
"SUDO_APK": "abuild-apk --no-progress"}
cmd = ["abuild", "rootpkg"]
pmb.chroot.user(args, cmd, working_dir=build_path, env=env)
# Clean up bindmount if needed
host_build_bindmount(args, chroot, flag_file)
# Clean up symlinks
if build_output != "":
if os.path.islink(chroot + "/mnt/linux/" + build_output) and \
@ -166,19 +206,25 @@ def package_kernel(args):
"argument.")
aport = pmb.helpers.pmaports.find(args, pkgname)
function_body = pmb.parse.function_body(aport + "/APKBUILD", "package")
kbuild_out = find_kbuild_output_dir(args, function_body)
modify_apkbuild(args, pkgname, aport)
apkbuild_path = args.work + "/aportgen/APKBUILD"
arch = args.deviceinfo["arch"]
apkbuild = pmb.parse.apkbuild(args, apkbuild_path, check_pkgname=False)
suffix = pmb.build.autodetect.suffix(args, apkbuild, arch)
apkbuild = pmb.parse.apkbuild(apkbuild_path, check_pkgname=False)
if apkbuild["_outdir"]:
kbuild_out = apkbuild["_outdir"]
else:
function_body = pmb.parse.function_body(aport + "/APKBUILD", "package")
kbuild_out = find_kbuild_output_dir(function_body)
suffix = pmb.build.autodetect.suffix(apkbuild, arch)
# Install package dependencies
depends, _ = pmb.build._package.build_depends(args, apkbuild, args.arch_native, strict=False)
depends, _ = pmb.build._package.build_depends(
args, apkbuild, pmb.config.arch_native, strict=False)
pmb.build.init(args, suffix)
if pmb.parse.arch.cpu_emulation_required(arch):
depends.append("binutils-" + arch)
pmb.chroot.apk.install(args, depends, suffix)
output = (arch + "/" + apkbuild["pkgname"] + "-" + apkbuild["pkgver"] +

View File

@ -1,8 +1,9 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging
import glob
import logging
import os
import pathlib
import pmb.build
import pmb.config
@ -11,15 +12,14 @@ import pmb.chroot.apk
import pmb.helpers.run
def init(args, suffix="native"):
# Check if already initialized
marker = "/var/local/pmbootstrap_chroot_build_init_done"
if os.path.exists(args.work + "/chroot_" + suffix + marker):
def init_abuild_minimal(args, suffix="native"):
""" Initialize a minimal chroot with abuild where one can do
'abuild checksum'. """
marker = f"{args.work}/chroot_{suffix}/tmp/pmb_chroot_abuild_init_done"
if os.path.exists(marker):
return
# Initialize chroot, install packages
pmb.chroot.apk.install(args, pmb.config.build_packages, suffix,
build=False)
pmb.chroot.apk.install(args, ["abuild"], suffix, build=False)
# Fix permissions
pmb.chroot.root(args, ["chown", "root:abuild",
@ -27,26 +27,45 @@ def init(args, suffix="native"):
pmb.chroot.root(args, ["chmod", "g+w",
"/var/cache/distfiles"], suffix)
# Add user to group abuild
pmb.chroot.root(args, ["adduser", "pmos", "abuild"], suffix)
pathlib.Path(marker).touch()
def init(args, suffix="native"):
""" Initialize a chroot for building packages with abuild. """
marker = f"{args.work}/chroot_{suffix}/tmp/pmb_chroot_build_init_done"
if os.path.exists(marker):
return
init_abuild_minimal(args, suffix)
# Initialize chroot, install packages
pmb.chroot.apk.install(args, pmb.config.build_packages, suffix,
build=False)
# Generate package signing keys
chroot = args.work + "/chroot_" + suffix
if not os.path.exists(args.work + "/config_abuild/abuild.conf"):
logging.info("(" + suffix + ") generate abuild keys")
pmb.chroot.user(args, ["abuild-keygen", "-n", "-q", "-a"],
suffix)
suffix, env={"PACKAGER": "pmos <pmos@local>"})
# Copy package signing key to /etc/apk/keys
for key in glob.glob(chroot +
"/mnt/pmbootstrap-abuild-config/*.pub"):
"/mnt/pmbootstrap/abuild-config/*.pub"):
key = key[len(chroot):]
pmb.chroot.root(args, ["cp", key, "/etc/apk/keys/"], suffix)
# Add gzip wrapper, that converts '-9' to '-1'
# Add gzip wrapper that converts '-9' to '-1'
if not os.path.exists(chroot + "/usr/local/bin/gzip"):
with open(chroot + "/tmp/gzip_wrapper.sh", "w") as handle:
content = """
#!/bin/sh
# Simple wrapper, that converts -9 flag for gzip to -1 for speed
# improvement with abuild. FIXME: upstream to abuild with a flag!
# Simple wrapper that converts -9 flag for gzip to -1 for
# speed improvement with abuild. FIXME: upstream to abuild
# with a flag!
args=""
for arg in "$@"; do
[ "$arg" == "-9" ] && arg="-1"
@ -58,13 +77,10 @@ def init(args, suffix="native"):
for i in range(len(lines)):
lines[i] = lines[i][16:]
handle.write("\n".join(lines))
pmb.chroot.root(args, ["cp", "/tmp/gzip_wrapper.sh", "/usr/local/bin/gzip"],
suffix)
pmb.chroot.root(args, ["cp", "/tmp/gzip_wrapper.sh",
"/usr/local/bin/gzip"], suffix)
pmb.chroot.root(args, ["chmod", "+x", "/usr/local/bin/gzip"], suffix)
# Add user to group abuild
pmb.chroot.root(args, ["adduser", "pmos", "abuild"], suffix)
# abuild.conf: Don't clean the build folder after building, so we can
# inspect it afterwards for debugging
pmb.chroot.root(args, ["sed", "-i", "-e", "s/^CLEANUP=.*/CLEANUP=''/",
@ -76,5 +92,27 @@ def init(args, suffix="native"):
"s/^ERROR_CLEANUP=.*/ERROR_CLEANUP=''/",
"/etc/abuild.conf"], suffix)
# Mark the chroot as initialized
pmb.chroot.root(args, ["touch", marker], suffix)
pathlib.Path(marker).touch()
def init_compiler(args, depends, cross, arch):
cross_pkgs = ["ccache-cross-symlinks"]
if "gcc4" in depends:
cross_pkgs += ["gcc4-" + arch]
elif "gcc6" in depends:
cross_pkgs += ["gcc6-" + arch]
else:
cross_pkgs += ["gcc-" + arch, "g++-" + arch]
if "clang" in depends or "clang-dev" in depends:
cross_pkgs += ["clang"]
if cross == "crossdirect":
cross_pkgs += ["crossdirect"]
if "rust" in depends or "cargo" in depends:
if args.ccache:
cross_pkgs += ["sccache"]
# crossdirect for rust installs all build dependencies in the
# native chroot too, as some of them can be required for building
# native macros / build scripts
cross_pkgs += depends
pmb.chroot.apk.install(args, cross_pkgs)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging
@ -14,10 +14,10 @@ import pmb.helpers.run
import pmb.parse
def get_arch(args, apkbuild):
def get_arch(apkbuild):
"""
Get the architecture, that the user wants to run menuconfig on, depending on
the APKBUILD and on the --arch parameter.
Take the architecture from the APKBUILD or complain if it's ambiguous. This
function only gets called if --arch is not set.
:param apkbuild: looks like: {"pkgname": "linux-...",
"arch": ["x86_64", "armhf", "aarch64"]}
@ -25,19 +25,18 @@ def get_arch(args, apkbuild):
"""
pkgname = apkbuild["pkgname"]
# Multiple architectures (requires --arch)
if len(apkbuild["arch"]) > 1:
if args.arch is None:
raise RuntimeError("Package '" + pkgname + "' supports multiple"
" architectures, please use '--arch' to specify"
" the desired architecture.")
return args.arch
# Disabled package (arch="")
if not apkbuild["arch"]:
raise RuntimeError(f"'{pkgname}' is disabled (arch=\"\"). Please use"
" '--arch' to specify the desired architecture.")
# Single architecture (--arch must be unset or match)
if args.arch is None or args.arch == apkbuild["arch"][0]:
return apkbuild["arch"][0]
raise RuntimeError("Package '" + pkgname + "' only supports the '" +
apkbuild["arch"][0] + "' architecture.")
# Multiple architectures
if len(apkbuild["arch"]) > 1:
raise RuntimeError(f"'{pkgname}' supports multiple architectures"
f" ({', '.join(apkbuild['arch'])}). Please use"
" '--arch' to specify the desired architecture.")
return apkbuild["arch"][0]
def get_outputdir(args, pkgname, apkbuild):
@ -79,43 +78,7 @@ def get_outputdir(args, pkgname, apkbuild):
" template with: pmbootstrap aportgen " + pkgname)
def menuconfig(args, pkgname):
# Pkgname: allow omitting "linux-" prefix
if pkgname.startswith("linux-"):
pkgname_ = pkgname.split("linux-")[1]
logging.info("PROTIP: You can simply do 'pmbootstrap kconfig edit " +
pkgname_ + "'")
else:
pkgname = "linux-" + pkgname
# Read apkbuild
aport = pmb.helpers.pmaports.find(args, pkgname)
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
arch = get_arch(args, apkbuild)
kopt = "menuconfig"
# Set up build tools and makedepends
pmb.build.init(args)
depends = apkbuild["makedepends"]
kopt = "menuconfig"
copy_xauth = False
if args.xconfig:
depends += ["qt-dev", "font-noto"]
kopt = "xconfig"
copy_xauth = True
elif args.gconfig:
depends += ["gtk+2.0-dev", "glib-dev", "libglade-dev", "font-noto"]
kopt = "gconfig"
copy_xauth = True
else:
depends += ["ncurses-dev"]
pmb.chroot.apk.install(args, depends)
# Copy host's .xauthority into native
if copy_xauth:
pmb.chroot.other.copy_xauthority(args)
# Patch and extract sources
def extract_and_patch_sources(args, pkgname, arch):
pmb.build.copy_to_buildpath(args, pkgname)
logging.info("(native) extract kernel source")
pmb.chroot.user(args, ["abuild", "unpack"], "native", "/home/pmos/build")
@ -124,14 +87,66 @@ def menuconfig(args, pkgname):
"/home/pmos/build", output="interactive",
env={"CARCH": arch})
def menuconfig(args, pkgname, use_oldconfig):
# Pkgname: allow omitting "linux-" prefix
if not pkgname.startswith("linux-"):
pkgname = "linux-" + pkgname
# Read apkbuild
aport = pmb.helpers.pmaports.find(args, pkgname)
apkbuild = pmb.parse.apkbuild(f"{aport}/APKBUILD")
arch = args.arch or get_arch(apkbuild)
suffix = pmb.build.autodetect.suffix(apkbuild, arch)
cross = pmb.build.autodetect.crosscompile(args, apkbuild, arch, suffix)
hostspec = pmb.parse.arch.alpine_to_hostspec(arch)
# Set up build tools and makedepends
pmb.build.init(args, suffix)
if cross:
pmb.build.init_compiler(args, [], cross, arch)
depends = apkbuild["makedepends"]
copy_xauth = False
if use_oldconfig:
kopt = "oldconfig"
else:
kopt = "menuconfig"
if args.xconfig:
depends += ["qt5-qtbase-dev", "font-noto"]
kopt = "xconfig"
copy_xauth = True
elif args.nconfig:
kopt = "nconfig"
depends += ["ncurses-dev"]
else:
depends += ["ncurses-dev"]
pmb.chroot.apk.install(args, depends)
# Copy host's .xauthority into native
if copy_xauth:
pmb.chroot.other.copy_xauthority(args)
extract_and_patch_sources(args, pkgname, arch)
# Check for background color variable
color = os.environ.get("MENUCONFIG_COLOR")
# Run make menuconfig
outputdir = get_outputdir(args, pkgname, apkbuild)
logging.info("(native) make " + kopt)
env = {"ARCH": pmb.parse.arch.alpine_to_kernel(arch),
"DISPLAY": os.environ.get("DISPLAY"),
"XAUTHORITY": "/home/pmos/.Xauthority"}
if cross:
env["CROSS_COMPILE"] = f"{hostspec}-"
env["CC"] = f"{hostspec}-gcc"
if color:
env["MENUCONFIG_COLOR"] = color
pmb.chroot.user(args, ["make", kopt], "native",
outputdir, output="tui",
env={"ARCH": pmb.parse.arch.alpine_to_kernel(arch),
"DISPLAY": os.environ.get("DISPLAY"),
"XAUTHORITY": "/home/pmos/.Xauthority"})
outputdir, output="tui", env=env)
# Find the updated config
source = args.work + "/chroot_native" + outputdir + "/.config"
@ -146,5 +161,4 @@ def menuconfig(args, pkgname):
pmb.build.checksum.update(args, pkgname)
# Check config
pmb.parse.kconfig.check(args, apkbuild["_flavor"], force_anbox_check=False,
details=True)
pmb.parse.kconfig.check(args, apkbuild["_flavor"], details=True)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import os
@ -25,7 +25,7 @@ def newapkbuild(args, folder, args_passed, force=False):
# Paths for copying
source_apkbuild = glob_result[0]
pkgname = pmb.parse.apkbuild(args, source_apkbuild, False)["pkgname"]
pkgname = pmb.parse.apkbuild(source_apkbuild, False)["pkgname"]
target = args.aports + "/" + folder + "/" + pkgname
# Move /home/pmos/build/$pkgname/* to /home/pmos/build/*

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import logging
@ -28,7 +28,16 @@ def copy_to_buildpath(args, package, suffix="native"):
pmb.chroot.root(args, ["rm", "-rf", "/home/pmos/build"], suffix)
# Copy aport contents with resolved symlinks
pmb.helpers.run.root(args, ["cp", "-rL", aport + "/", build])
pmb.helpers.run.root(args, ["mkdir", "-p", build])
for entry in os.listdir(aport):
# Don't copy those dirs, as those have probably been generated by running `abuild`
# on the host system directly and not cleaning up after itself.
# Those dirs might contain broken symlinks and cp fails resolving them.
if entry in ["src", "pkg"]:
logging.warn(f"WARNING: Not copying {entry}, looks like a leftover from abuild")
continue
pmb.helpers.run.root(args, ["cp", "-rL", f"{aport}/{entry}", f"{build}/{entry}"])
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos",
"/home/pmos/build"], suffix)
@ -75,8 +84,8 @@ def is_necessary(args, arch, apkbuild, indexes=None):
# b) Aports folder has a newer version
if version_new != version_old:
logging.debug(msg + "Binary package out of date (binary: " + version_old +
", aport: " + version_new + ")")
logging.debug(f"{msg}Binary package out of date (binary: "
f"{version_old}, aport: {version_new})")
return True
# Aports and binary repo have the same version.
@ -117,7 +126,7 @@ def index_repo(args, arch=None):
pmb.chroot.user(args, command, working_dir=path_repo_chroot)
else:
logging.debug("NOTE: Can't build index for: " + path)
pmb.parse.apkindex.clear_cache(args, path + "/APKINDEX.tar.gz")
pmb.parse.apkindex.clear_cache(f"{path}/APKINDEX.tar.gz")
def configure_abuild(args, suffix, verify=False):
@ -134,14 +143,16 @@ def configure_abuild(args, suffix, verify=False):
continue
if line != (prefix + args.jobs + "\n"):
if verify:
raise RuntimeError("Failed to configure abuild: " + path +
"\nTry to delete the file (or zap the chroot).")
raise RuntimeError(f"Failed to configure abuild: {path}"
"\nTry to delete the file"
"(or zap the chroot).")
pmb.chroot.root(args, ["sed", "-i", "-e",
"s/^" + prefix + ".*/" + prefix + args.jobs + "/",
"/etc/abuild.conf"], suffix)
f"s/^{prefix}.*/{prefix}{args.jobs}/",
"/etc/abuild.conf"],
suffix)
configure_abuild(args, suffix, True)
return
raise RuntimeError("Could not find " + prefix + " line in " + path)
pmb.chroot.root(args, ["sed", "-i", f"$ a\\{prefix}{args.jobs}", "/etc/abuild.conf"], suffix)
def configure_ccache(args, suffix="native", verify=False):

View File

@ -1,7 +1,7 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb.chroot.init import init
from pmb.chroot.mount import mount, mount_native_into_foreign
from pmb.chroot.init import init, init_keys
from pmb.chroot.mount import mount, mount_native_into_foreign, remove_mnt_pmbootstrap
from pmb.chroot.root import root
from pmb.chroot.user import user
from pmb.chroot.user import exists as user_exists

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging
@ -6,6 +6,7 @@ import shlex
import pmb.chroot
import pmb.config
import pmb.helpers.apk
import pmb.helpers.pmaports
import pmb.parse.apkindex
import pmb.parse.arch
@ -24,11 +25,11 @@ def update_repository_list(args, suffix="native", check=False):
True.
"""
# Skip if we already did this
if suffix in args.cache["apk_repository_list_updated"]:
if suffix in pmb.helpers.other.cache["apk_repository_list_updated"]:
return
# Read old entries or create folder structure
path = args.work + "/chroot_" + suffix + "/etc/apk/repositories"
path = f"{args.work}/chroot_{suffix}/etc/apk/repositories"
lines_old = []
if os.path.exists(path):
# Read all old lines
@ -42,20 +43,20 @@ def update_repository_list(args, suffix="native", check=False):
# Up to date: Save cache, return
lines_new = pmb.helpers.repo.urls(args)
if lines_old == lines_new:
args.cache["apk_repository_list_updated"].append(suffix)
pmb.helpers.other.cache["apk_repository_list_updated"].append(suffix)
return
# Check phase: raise error when still outdated
if check:
raise RuntimeError("Failed to update: " + path)
raise RuntimeError(f"Failed to update: {path}")
# Update the file
logging.debug("(" + suffix + ") update /etc/apk/repositories")
logging.debug(f"({suffix}) update /etc/apk/repositories")
if os.path.exists(path):
pmb.helpers.run.root(args, ["rm", path])
for line in lines_new:
pmb.helpers.run.root(args, ["sh", "-c", "echo " +
shlex.quote(line) + " >> " + path])
pmb.helpers.run.root(args, ["sh", "-c", "echo "
f"{shlex.quote(line)} >> {path}"])
update_repository_list(args, suffix, True)
@ -66,177 +67,180 @@ def check_min_version(args, suffix="native"):
"""
# Skip if we already did this
if suffix in args.cache["apk_min_version_checked"]:
if suffix in pmb.helpers.other.cache["apk_min_version_checked"]:
return
# Skip if apk is not installed yet
if not os.path.exists(args.work + "/chroot_" + suffix + "/sbin/apk"):
logging.debug("NOTE: Skipped apk version check for chroot '" + suffix +
"', because it is not installed yet!")
if not os.path.exists(f"{args.work}/chroot_{suffix}/sbin/apk"):
logging.debug(f"NOTE: Skipped apk version check for chroot '{suffix}'"
", because it is not installed yet!")
return
# Compare
version_installed = installed(args, suffix)["apk-tools"]["version"]
version_min = pmb.config.apk_tools_static_min_version
if pmb.parse.version.compare(version_installed, version_min) == -1:
raise RuntimeError("You have an outdated version of the 'apk' package"
" manager installed (your version: " + version_installed +
", expected at least: " + version_min + "). Delete"
" your http cache and zap all chroots, then try again:"
" 'pmbootstrap zap -hc'")
pmb.helpers.apk.check_outdated(
args, version_installed,
"Delete your http cache and zap all chroots, then try again:"
" 'pmbootstrap zap -hc'")
# Mark this suffix as checked
args.cache["apk_min_version_checked"].append(suffix)
pmb.helpers.other.cache["apk_min_version_checked"].append(suffix)
def install_is_necessary(args, build, arch, package, packages_installed):
def install_build(args, package, arch):
"""
This function optionally builds an out of date package, and checks if the
version installed inside a chroot is up to date.
:param build: Set to true to build the package, if the binary packages are
out of date, and it is in the aports folder.
:param packages_installed: Return value from installed().
:returns: True if the package needs to be installed/updated, False otherwise.
Build an outdated package unless pmbootstrap was invoked with
"pmbootstrap install" and the option to build packages during pmb install
is disabled.
:param package: name of the package to build
:param arch: architecture of the package to build
"""
# Build package
if build:
pmb.build.package(args, package, arch)
# User may have disabled building packages during "pmbootstrap install"
if args.action == "install" and not args.build_pkgs_on_install:
if not pmb.parse.apkindex.package(args, package, arch, False):
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'.")
# Use the existing binary package
return
# No further checks when not installed
if package not in packages_installed:
return True
# Make sure, that we really have a binary package
data_repo = pmb.parse.apkindex.package(args, package, arch, False)
if not data_repo:
logging.warning("WARNING: Internal error in pmbootstrap," +
" package '" + package + "' for " + arch +
" has not been built yet, but it should have"
" been. Rebuilding it with force. Please "
" report this, if there is no ticket about this"
" yet!")
pmb.build.package(args, package, arch, True)
return install_is_necessary(args, build, arch, package,
packages_installed)
# Compare the installed version vs. the version in the repos
data_installed = packages_installed[package]
compare = pmb.parse.version.compare(data_installed["version"],
data_repo["version"])
# a) Installed newer (should not happen normally)
if compare == 1:
logging.info("WARNING: " + arch + " package '" + package +
"' installed version " + data_installed["version"] +
" is newer, than the version in the repositories: " +
data_repo["version"] +
" See also: <https://postmarketos.org/warning-repo>")
return False
# b) Repo newer
elif compare == -1:
return True
# c) Same version, look at last modified
elif compare == 0:
time_installed = float(data_installed["timestamp"])
time_repo = float(data_repo["timestamp"])
return time_repo > time_installed
# Build the package if it's in pmaports and there is no binary package
# with the same pkgver and pkgrel. This check is done in
# pmb.build.is_necessary, which gets called in pmb.build.package.
return pmb.build.package(args, package, arch)
def replace_aports_packages_with_path(args, packages, suffix, arch):
def packages_split_to_add_del(packages):
"""
apk will only re-install packages with the same pkgname, pkgver and pkgrel,
when you give it the absolute path to the package. This function replaces
all packages, that were built locally, with the absolute path to the package.
Sort packages into "to_add" and "to_del" lists depending on their pkgname
starting with an exclamation mark.
:param packages: list of pkgnames
:returns: (to_add, to_del) - tuple of lists of pkgnames, e.g.
(["hello-world", ...], ["some-conflict-pkg", ...])
"""
ret = []
to_add = []
to_del = []
for package in packages:
aport = pmb.helpers.pmaports.find(args, package, False)
if aport:
data_repo = pmb.parse.apkindex.package(args, package, arch, False)
if not data_repo:
raise RuntimeError(package + ": could not find binary"
" package, although it should exist for"
" sure at this point in the code."
" Probably an APKBUILD subpackage parsing"
" bug. Related: https://gitlab.com/"
"postmarketOS/build.postmarketos.org/"
"issues/61")
apk_path = ("/mnt/pmbootstrap-packages/" + arch + "/" +
package + "-" + data_repo["version"] + ".apk")
if os.path.exists(args.work + "/chroot_" + suffix + apk_path):
package = apk_path
ret.append(package)
if package.startswith("!"):
to_del.append(package.lstrip("!"))
else:
to_add.append(package)
return (to_add, to_del)
def packages_get_locally_built_apks(args, packages, arch):
"""
Iterate over packages and if existing, get paths to locally built packages.
This is used to force apk to upgrade packages to newer local versions, even
if the pkgver and pkgrel did not change.
:param packages: list of pkgnames
:param arch: architecture that the locally built packages should have
:returns: list of apk file paths that are valid inside the chroots, e.g.
["/mnt/pmbootstrap/packages/x86_64/hello-world-1-r6.apk", ...]
"""
channel = pmb.config.pmaports.read_config(args)["channel"]
ret = []
for package in packages:
data_repo = pmb.parse.apkindex.package(args, package, arch, False)
if not data_repo:
continue
apk_file = f"{package}-{data_repo['version']}.apk"
if not os.path.exists(f"{args.work}/packages/{channel}/{arch}/{apk_file}"):
continue
ret.append(f"/mnt/pmbootstrap/packages/{arch}/{apk_file}")
return ret
def install_run_apk(args, to_add, to_add_local, to_del, suffix):
"""
Run apk to add packages, and ensure only the desired packages get
explicitly marked as installed.
:param to_add: list of pkgnames to install, without their dependencies
:param to_add_local: return of packages_get_locally_built_apks()
:param to_del: list of pkgnames to be deleted, this should be set to
conflicting dependencies in any of the packages to be
installed or their dependencies (e.g. ["osk-sdl"])
:param suffix: the chroot suffix, e.g. "native" or "rootfs_qemu-amd64"
"""
# Sanitize packages: don't allow '--allow-untrusted' and other options
# to be passed to apk!
for package in to_add + to_add_local + to_del:
if package.startswith("-"):
raise ValueError(f"Invalid package name: {package}")
commands = [["add"] + to_add]
# Use a virtual package to mark only the explicitly requested packages as
# explicitly installed, not the ones in to_add_local
if to_add_local:
commands += [["add", "-u", "--virtual", ".pmbootstrap"] + to_add_local,
["del", ".pmbootstrap"]]
if to_del:
commands += [["del"] + to_del]
for (i, command) in enumerate(commands):
if args.offline:
command = ["--no-network"] + command
if i == 0:
pmb.helpers.apk.apk_with_progress(args, ["apk"] + command,
chroot=True, suffix=suffix)
else:
# Virtual package related commands don't actually install or remove
# packages, but only mark the right ones as explicitly installed.
# They finish up almost instantly, so don't display a progress bar.
pmb.chroot.root(args, ["apk", "--no-progress"] + command,
suffix=suffix)
def install(args, packages, suffix="native", build=True):
"""
Install packages from pmbootstrap's local package index or the pmOS/Alpine
binary package mirrors. Iterate over all dependencies recursively, and
build missing packages as necessary.
:param packages: list of pkgnames to be installed
:param suffix: the chroot suffix, e.g. "native" or "rootfs_qemu-amd64"
:param build: automatically build the package, when it does not exist yet
or needs to be updated, and it is inside the pm-aports
folder. Checking this is expensive - if you know, that all
packages are provides by upstream repos, set this to False!
or needs to be updated, and it is inside pmaports. For the
special case that all packages are expected to be in Alpine's
repositories, set this to False for performance optimization.
"""
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
if not packages:
logging.verbose("pmb.chroot.apk.install called with empty packages list,"
" ignoring")
return
# Initialize chroot
check_min_version(args, suffix)
pmb.chroot.init(args, suffix)
# Add depends to packages
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
packages_with_depends = pmb.parse.depends.recurse(args, packages, suffix)
to_add, to_del = packages_split_to_add_del(packages_with_depends)
# Filter outdated packages (build them if required)
packages_installed = installed(args, suffix)
packages_todo = []
for package in packages_with_depends:
if install_is_necessary(
args, build, arch, package, packages_installed):
packages_todo.append(package)
if not len(packages_todo):
return
if build:
for package in to_add:
install_build(args, package, arch)
# Sanitize packages: don't allow '--allow-untrusted' and other options
# to be passed to apk!
for package in packages_todo:
if package.startswith("-"):
raise ValueError("Invalid package name: " + package)
to_add_local = packages_get_locally_built_apks(args, to_add, arch)
to_add_no_deps, _ = packages_split_to_add_del(packages)
# Readable install message without dependencies
message = "(" + suffix + ") install"
for pkgname in packages:
if pkgname not in packages_installed:
message += " " + pkgname
logging.info(message)
# Local packages: Using the path instead of pkgname makes apk update
# packages of the same version if the build date is different
packages_todo = replace_aports_packages_with_path(args, packages_todo,
suffix, arch)
# Use a virtual package to mark only the explicitly requested packages as
# explicitly installed, not their dependencies or specific paths (#1212)
commands = [["add"] + packages]
if packages != packages_todo:
commands = [["add", "-u", "--virtual", ".pmbootstrap"] + packages_todo,
["add"] + packages,
["del", ".pmbootstrap"]]
for command in commands:
if args.offline:
command = ["--no-network"] + command
pmb.chroot.root(args, ["apk", "--no-progress"] + command, suffix=suffix, disable_timeout=True)
def upgrade(args, suffix="native"):
"""
Upgrade all packages installed in a chroot
"""
# Update APKINDEX files
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
pmb.helpers.repo.update(args, arch)
# Rebuild and upgrade out-of-date packages
packages = list(installed(args, suffix).keys())
install(args, packages, suffix)
logging.info(f"({suffix}) install {' '.join(to_add_no_deps)}")
install_run_apk(args, to_add_no_deps, to_add_local, to_del, suffix)
def installed(args, suffix="native"):
@ -254,5 +258,5 @@ def installed(args, suffix="native"):
}, ...
}
"""
path = args.work + "/chroot_" + suffix + "/lib/apk/db/installed"
return pmb.parse.apkindex.parse(args, path, False)
path = f"{args.work}/chroot_{suffix}/lib/apk/db/installed"
return pmb.parse.apkindex.parse(path, False)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging
@ -7,6 +7,7 @@ import tarfile
import tempfile
import stat
import pmb.helpers.apk
import pmb.helpers.run
import pmb.config
import pmb.config.load
@ -17,7 +18,7 @@ import pmb.parse.version
def read_signature_info(tar):
"""
Find various information about the signature, that was used to sign
Find various information about the signature that was used to sign
/sbin/apk.static inside the archive (not to be confused with the normal apk
archive signature!)
@ -31,19 +32,19 @@ def read_signature_info(tar):
sigfilename = filename
break
if not sigfilename:
raise RuntimeError("Could not find signature filename in apk." +
" This means, that your apk file is damaged. Delete it" +
" and try again. If the problem persists, fill out a bug" +
" report.")
raise RuntimeError("Could not find signature filename in apk."
" This means that your apk file is damaged."
" Delete it and try again."
" If the problem persists, fill out a bug report.")
sigkey = sigfilename[len(prefix):]
logging.debug("sigfilename: " + sigfilename)
logging.debug("sigkey: " + sigkey)
logging.debug(f"sigfilename: {sigfilename}")
logging.debug(f"sigkey: {sigkey}")
# Get path to keyfile on disk
sigkey_path = pmb.config.apk_keys_path + "/" + sigkey
sigkey_path = f"{pmb.config.apk_keys_path}/{sigkey}"
if "/" in sigkey or not os.path.exists(sigkey_path):
logging.debug("sigkey_path: " + sigkey_path)
raise RuntimeError("Invalid signature key: " + sigkey)
logging.debug(f"sigkey_path: {sigkey_path}")
raise RuntimeError(f"Invalid signature key: {sigkey}")
return (sigfilename, sigkey_path)
@ -70,7 +71,7 @@ def extract_temp(tar, sigfilename):
ret[ftype]["temp_path"] = path
shutil.copyfileobj(tar.extractfile(member), handle)
logging.debug("extracted: " + path)
logging.debug(f"extracted: {path}")
handle.close()
return ret
@ -82,7 +83,7 @@ def verify_signature(args, files, sigkey_path):
:param files: return value from extract_temp()
:raises RuntimeError: when verification failed and removes temp files
"""
logging.debug("Verify apk.static signature with " + sigkey_path)
logging.debug(f"Verify apk.static signature with {sigkey_path}")
try:
pmb.helpers.run.user(args, ["openssl", "dgst", "-sha1", "-verify",
sigkey_path, "-signature", files[
@ -113,22 +114,24 @@ def extract(args, version, apk_path):
os.unlink(files["sig"]["temp_path"])
temp_path = files["apk"]["temp_path"]
# Verify the version, that the extracted binary reports
logging.debug("Verify the version reported by the apk.static binary" +
" (must match the package version " + version + ")")
# Verify the version that the extracted binary reports
logging.debug("Verify the version reported by the apk.static binary"
f" (must match the package version {version})")
os.chmod(temp_path, os.stat(temp_path).st_mode | stat.S_IEXEC)
version_bin = pmb.helpers.run.user(args, [temp_path, "--version"],
output_return=True)
version_bin = version_bin.split(" ")[1].split(",")[0]
if not version.startswith(version_bin + "-r"):
if not version.startswith(f"{version_bin}-r"):
os.unlink(temp_path)
raise RuntimeError("Downloaded apk-tools-static-" + version + ".apk,"
" but the apk binary inside that package reports to be"
" version: " + version_bin + "! Looks like a downgrade attack"
" from a malicious server! Switch the server (-m) and try again.")
raise RuntimeError(f"Downloaded apk-tools-static-{version}.apk,"
" but the apk binary inside that package reports"
f" to be version: {version_bin}!"
" Looks like a downgrade attack"
" from a malicious server! Switch the server (-m)"
" and try again.")
# Move it to the right path
target_path = args.work + "/apk.static"
target_path = f"{args.work}/apk.static"
shutil.move(temp_path, target_path)
@ -136,8 +139,10 @@ def download(args, file):
"""
Download a single file from an Alpine mirror.
"""
base_url = args.mirror_alpine + "edge/main/" + args.arch_native
return pmb.helpers.http.download(args, base_url + "/" + file, file)
channel_cfg = pmb.config.pmaports.read_config_channel(args)
mirrordir = channel_cfg["mirrordir_alpine"]
base_url = f"{args.mirror_alpine}{mirrordir}/main/{pmb.config.arch_native}"
return pmb.helpers.http.download(args, f"{base_url}/{file}", file)
def init(args):
@ -150,16 +155,12 @@ def init(args):
indexes=[apkindex])
version = index_data["version"]
# Extract and verify the apk-tools-static version
version_min = pmb.config.apk_tools_static_min_version
apk_name = "apk-tools-static-" + version + ".apk"
if pmb.parse.version.compare(version, version_min) == -1:
raise RuntimeError("Your APKINDEX has an outdated version of"
" apk-tools-static (your version: " + version +
", expected at least:" + version_min + "). Please" +
" run 'pmbootstrap update'.")
# Verify the apk-tools-static version
pmb.helpers.apk.check_outdated(
args, version, "Run 'pmbootstrap update', then try again.")
# Download, extract, verify apk-tools-static
apk_name = f"apk-tools-static-{version}.apk"
apk_static = download(args, apk_name)
extract(args, version, apk_static)
@ -167,4 +168,5 @@ def init(args):
def run(args, parameters):
if args.offline:
parameters = ["--no-network"] + parameters
pmb.helpers.run.root(args, [args.work + "/apk.static"] + parameters)
pmb.helpers.apk.apk_with_progress(
args, [f"{args.work}/apk.static"] + parameters, chroot=False)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging
@ -18,11 +18,22 @@ def register(args, arch):
Get arch, magic, mask.
"""
arch_qemu = pmb.parse.arch.alpine_to_qemu(arch)
# always make sure the qemu-<arch> binary is installed, since registering
# may happen outside of this method (e.g. by OS)
if f"qemu-{arch_qemu}" not in pmb.chroot.apk.installed(args):
pmb.chroot.apk.install(args, ["qemu-" + arch_qemu])
if is_registered(arch_qemu):
return
pmb.helpers.other.check_binfmt_misc(args)
pmb.chroot.apk.install(args, ["qemu-" + arch_qemu])
info = pmb.parse.binfmt_info(args, arch_qemu)
# Don't continue if the actions from check_binfmt_misc caused the OS to
# automatically register the target arch
if is_registered(arch_qemu):
return
info = pmb.parse.binfmt_info(arch_qemu)
# Build registration string
# https://en.wikipedia.org/wiki/Binfmt_misc

View File

@ -1,250 +0,0 @@
# Copyright 2020 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import errno
import json
import logging
import os
import pmb.chroot
import pmb.config
import pmb.chroot.apk
""" Packages for foreign architectures (e.g. armhf) get built in chroots
running with QEMU. While this works, it is painfully slow. So we speed it
up by using distcc to let cross compilers running in the native chroots do
the heavy lifting.
This file sets up an SSH server in the native chroot, which will then be
used by the foreign arch chroot to communicate with the distcc daemon. We
make sure that only the foreign arch chroot can connect to the sshd by only
listening on localhost, as well as generating dedicated ssh keys.
Using the SSH server instead of running distccd directly is a security
measure. Distccd does not authenticate its clients and would therefore
allow any process of the host system (not related to pmbootstrap) to
execute compilers in the native chroot. By modifying the compiler's options
or sending malicious data to the compiler, it is likely that the process
can gain remote code execution [1]. That way, a compromised, but sandboxed
process could gain privilege escalation.
[1]: <https://github.com/distcc/distcc/issues/155#issuecomment-374014645>
"""
def init_server(args):
"""
Install dependencies and generate keys for the server.
"""
# Install dependencies
pmb.chroot.apk.install(args, ["arch-bin-masquerade", "distcc",
"openssh-server"])
# Config folder (nothing to do if existing)
dir = "/home/pmos/.distcc-sshd"
dir_outside = args.work + "/chroot_native" + dir
if os.path.exists(dir_outside):
return
# Generate keys
logging.info("(native) generate distcc-sshd server keys")
pmb.chroot.user(args, ["mkdir", "-p", dir + "/etc/ssh"])
pmb.chroot.user(args, ["ssh-keygen", "-A", "-f", dir])
def init_client(args, suffix):
"""
Install dependencies and generate keys for the client.
"""
# Install dependencies
pmb.chroot.apk.install(args, ["arch-bin-masquerade", "distcc",
"openssh-client"], suffix)
# Public key path (nothing to do if existing)
pub = "/home/pmos/id_ed25519.pub"
pub_outside = args.work + "/chroot_" + suffix + pub
if os.path.exists(pub_outside):
return
# Generate keys
logging.info("(" + suffix + ") generate distcc-sshd client keys")
pmb.chroot.user(args, ["ssh-keygen", "-t", "ed25519", "-N", "",
"-f", "/home/pmos/.ssh/id_ed25519"], suffix)
pmb.chroot.user(args, ["cp", "/home/pmos/.ssh/id_ed25519.pub", pub],
suffix)
def configure_authorized_keys(args, suffix):
"""
Exclusively allow one foreign arch chroot to access the sshd.
"""
auth = "/home/pmos/.distcc-sshd/authorized_keys"
auth_outside = args.work + "/chroot_native/" + auth
pub = "/home/pmos/id_ed25519.pub"
pub_outside = args.work + "/chroot_" + suffix + pub
pmb.helpers.run.root(args, ["cp", pub_outside, auth_outside])
def configure_cmdlist(args, arch):
"""
Create a whitelist of all the cross compiler wrappers.
Distcc 3.3 and above requires such a whitelist, or else it will only run
with the --make-me-a-botnet parameter (even in ssh mode).
"""
dir = "/home/pmos/.distcc-sshd"
with open(args.work + "/chroot_native/tmp/cmdlist", "w") as handle:
for cmd in ["c++", "cc", "cpp", "g++", "gcc"]:
cmd_full = "/usr/lib/arch-bin-masquerade/" + arch + "/" + cmd
handle.write(cmd_full + "\n")
pmb.chroot.root(args, ["mv", "/tmp/cmdlist", dir + "/cmdlist"])
pmb.chroot.user(args, ["cat", dir + "/cmdlist"])
def configure_distccd_wrapper(args):
"""
Wrap distccd in a shell script, so we can pass the compiler whitelist and
set the verbose flag (when pmbootstrap is running with --verbose).
"""
dir = "/home/pmos/.distcc-sshd"
with open(args.work + "/chroot_native/tmp/wrapper", "w") as handle:
handle.write("#!/bin/sh\n"
"export DISTCC_CMDLIST='" + dir + "/cmdlist'\n"
"distccd --log-file /home/pmos/distccd.log --nice 19")
if args.verbose:
handle.write(" --verbose")
handle.write(" \"$@\"\n")
pmb.chroot.root(args, ["mv", "/tmp/wrapper", dir + "/distccd"])
pmb.chroot.user(args, ["cat", dir + "/distccd"])
pmb.chroot.root(args, ["chmod", "+x", dir + "/distccd"])
def configure_sshd(args):
"""
Configure the SSH daemon in the native chroot.
"""
dir = "/home/pmos/.distcc-sshd"
config = """AllowAgentForwarding no
AllowTcpForwarding no
AuthorizedKeysFile /home/pmos/.distcc-sshd/authorized_keys
HostKey /home/pmos/.distcc-sshd/etc/ssh/ssh_host_ed25519_key
ListenAddress 127.0.0.1
PasswordAuthentication no
PidFile /home/pmos/.distcc-sshd/sshd.pid
Port """ + args.port_distccd + """
X11Forwarding no"""
with open(args.work + "/chroot_native/tmp/cfg", "w") as handle:
for line in config.split("\n"):
handle.write(line.lstrip() + "\n")
pmb.chroot.root(args, ["mv", "/tmp/cfg", dir + "/sshd_config"])
pmb.chroot.user(args, ["cat", dir + "/sshd_config"])
def get_running_pid(args):
"""
:returns: the running distcc-sshd's pid as integer or None
"""
# PID file must exist
pidfile = "/home/pmos/.distcc-sshd/sshd.pid"
pidfile_outside = args.work + "/chroot_native" + pidfile
if not os.path.exists(pidfile_outside):
return None
# Verify, if it still exists by sending a kill signal
with open(pidfile_outside, "r") as handle:
pid = int(handle.read()[:-1])
try:
os.kill(pid, 0)
except OSError as err:
if err.errno == errno.ESRCH: # no such process
pmb.helpers.run.root(args, ["rm", pidfile_outside])
return None
return pid
def get_running_parameters(args):
"""
Get the parameters of the currently running distcc-sshd instance.
:returns: a dictionary in the form of
{"arch": "armhf", "port": 1234, "verbose": False}
If the information can not be read, "arch" is set to "unknown"
"""
# Return defaults
path = args.work + "/chroot_native/tmp/distcc_sshd_parameters"
if not os.path.exists(path):
return {"arch": "unknown", "port": 0, "verbose": False}
# Parse the file as JSON
with open(path, "r") as handle:
return json.loads(handle.read())
def set_running_parameters(args, arch):
"""
Set the parameters of the currently running distcc-sshd instance.
"""
parameters = {"arch": arch,
"port": args.port_distccd,
"verbose": args.verbose}
path = args.work + "/chroot_native/tmp/distcc_sshd_parameters"
with open(path, "w") as handle:
json.dump(parameters, handle)
def is_running_with_same_parameters(args, arch):
"""
Check whether we can use the already running distcc-sshd instance with our
current set of parameters. In case we can use it directly, we save some
time, otherwise we need to stop it, configure it again, and start it once
more.
"""
if not get_running_pid(args):
return False
parameters = get_running_parameters(args)
return (parameters["arch"] == arch and
parameters["port"] == args.port_distccd and
parameters["verbose"] == args.verbose)
def stop(args):
"""
Kill the sshd process (by using its pid).
"""
pid = get_running_pid(args)
if not pid:
return
parameters = get_running_parameters(args)
logging.info("(native) stop distcc-sshd (" + parameters["arch"] + ")")
pmb.chroot.user(args, ["kill", str(pid)])
def start(args, arch):
"""
Set up a new distcc-sshd instance or use an already running one.
"""
if is_running_with_same_parameters(args, arch):
return
stop(args)
# Initialize server and client
suffix = "buildroot_" + arch
init_server(args)
init_client(args, suffix)
logging.info("(native) start distcc-sshd (" + arch + ") on 127.0.0.1:" +
args.port_distccd)
# Configure server parameters (arch, port, verbose)
configure_authorized_keys(args, suffix)
configure_distccd_wrapper(args)
configure_cmdlist(args, arch)
configure_sshd(args)
# Run
dir = "/home/pmos/.distcc-sshd"
pmb.chroot.user(args, ["/usr/sbin/sshd", "-f", dir + "/sshd_config",
"-E", dir + "/log.txt"])
set_running_parameters(args, arch)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
@ -22,7 +22,7 @@ def copy_resolv_conf(args, suffix="native"):
If the file doesn't exist, create an empty file with 'touch'.
"""
host = "/etc/resolv.conf"
chroot = args.work + "/chroot_" + suffix + host
chroot = f"{args.work}/chroot_{suffix}{host}"
if os.path.exists(host):
if not os.path.exists(chroot) or not filecmp.cmp(host, chroot):
pmb.helpers.run.root(args, ["cp", host, chroot])
@ -30,29 +30,59 @@ def copy_resolv_conf(args, suffix="native"):
pmb.helpers.run.root(args, ["touch", chroot])
def mark_in_chroot(args, suffix="native"):
"""
Touch a flag so we can know when we're running in chroot (and
don't accidentally flash partitions on our host). This marker
gets removed in pmb.chroot.shutdown (pmbootstrap shutdown).
"""
in_chroot_file = f"{args.work}/chroot_{suffix}/in-pmbootstrap"
if not os.path.exists(in_chroot_file):
pmb.helpers.run.root(args, ["touch", in_chroot_file])
def setup_qemu_emulation(args, suffix):
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
if not pmb.parse.arch.cpu_emulation_required(args, arch):
if not pmb.parse.arch.cpu_emulation_required(arch):
return
chroot = args.work + "/chroot_" + suffix
chroot = f"{args.work}/chroot_{suffix}"
arch_qemu = pmb.parse.arch.alpine_to_qemu(arch)
# mount --bind the qemu-user binary
pmb.chroot.binfmt.register(args, arch)
pmb.helpers.mount.bind_file(args, args.work + "/chroot_native/usr/bin/qemu-" + arch_qemu,
chroot + "/usr/bin/qemu-" + arch_qemu + "-static",
pmb.helpers.mount.bind_file(args, f"{args.work}/chroot_native"
f"/usr/bin/qemu-{arch_qemu}",
f"{chroot}/usr/bin/qemu-{arch_qemu}-static",
create_folders=True)
def init_keys(args):
"""
All Alpine and postmarketOS repository keys are shipped with pmbootstrap.
Copy them into $WORK/config_apk_keys, which gets mounted inside the various
chroots as /etc/apk/keys.
This is done before installing any package, so apk can verify APKINDEX
files of binary repositories even though alpine-keys/postmarketos-keys are
not installed yet.
"""
for key in glob.glob(f"{pmb.config.apk_keys_path}/*.pub"):
target = f"{args.work}/config_apk_keys/{os.path.basename(key)}"
if not os.path.exists(target):
# Copy as root, so the resulting files in chroots are owned by root
pmb.helpers.run.root(args, ["cp", key, target])
def init(args, suffix="native"):
# When already initialized: just prepare the chroot
chroot = args.work + "/chroot_" + suffix
chroot = f"{args.work}/chroot_{suffix}"
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
pmb.chroot.mount(args, suffix)
setup_qemu_emulation(args, suffix)
if os.path.islink(chroot + "/bin/sh"):
mark_in_chroot(args, suffix)
if os.path.islink(f"{chroot}/bin/sh"):
pmb.config.workdir.chroot_check_channel(args, suffix)
copy_resolv_conf(args, suffix)
pmb.chroot.apk.update_repository_list(args, suffix)
@ -61,17 +91,15 @@ def init(args, suffix="native"):
# Require apk-tools-static
pmb.chroot.apk_static.init(args)
logging.info("(" + suffix + ") install alpine-base")
logging.info(f"({suffix}) install alpine-base")
# Initialize cache
apk_cache = args.work + "/cache_apk_" + arch
pmb.helpers.run.root(args, ["ln", "-s", "-f", "/var/cache/apk", chroot +
"/etc/apk/cache"])
apk_cache = f"{args.work}/cache_apk_{arch}"
pmb.helpers.run.root(args, ["ln", "-s", "-f", "/var/cache/apk",
f"{chroot}/etc/apk/cache"])
# Initialize /etc/apk/keys/, resolv.conf, repositories
for key in glob.glob(pmb.config.apk_keys_path + "/*.pub"):
pmb.helpers.run.root(args, ["cp", key, args.work +
"/config_apk_keys/"])
init_keys(args)
copy_resolv_conf(args, suffix)
pmb.chroot.apk.update_repository_list(args, suffix)
@ -79,22 +107,23 @@ def init(args, suffix="native"):
# Install alpine-base
pmb.helpers.repo.update(args, arch)
pmb.chroot.apk_static.run(args, ["--no-progress", "--root", chroot,
"--cache-dir", apk_cache, "--initdb", "--arch", arch,
pmb.chroot.apk_static.run(args, ["--root", chroot,
"--cache-dir", apk_cache,
"--initdb", "--arch", arch,
"add", "alpine-base"])
# Building chroots: create "pmos" user, add symlinks to /home/pmos
if not suffix.startswith("rootfs_"):
pmb.chroot.root(args, ["adduser", "-D", "pmos", "-u",
pmb.config.chroot_uid_user], suffix, auto_init=False)
pmb.config.chroot_uid_user],
suffix, auto_init=False)
# Create the links (with subfolders if necessary)
for target, link_name in pmb.config.chroot_home_symlinks.items():
link_dir = os.path.dirname(link_name)
if not os.path.exists(chroot + link_dir):
if not os.path.exists(f"{chroot}{link_dir}"):
pmb.chroot.user(args, ["mkdir", "-p", link_dir], suffix)
if not os.path.exists(chroot + target):
if not os.path.exists(f"{chroot}{target}"):
pmb.chroot.root(args, ["mkdir", "-p", target], suffix)
pmb.chroot.user(args, ["ln", "-s", target, link_name], suffix)
pmb.chroot.root(args, ["chown", "pmos:pmos", target],
suffix)
pmb.chroot.root(args, ["chown", "pmos:pmos", target], suffix)

View File

@ -1,10 +1,11 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging
import pmb.chroot.initfs_hooks
import pmb.chroot.other
import pmb.chroot.apk
import pmb.config.pmaports
import pmb.helpers.cli
@ -12,15 +13,20 @@ def build(args, flavor, suffix):
# Update mkinitfs and hooks
pmb.chroot.apk.install(args, ["postmarketos-mkinitfs"], suffix)
pmb.chroot.initfs_hooks.update(args, suffix)
pmaports_cfg = pmb.config.pmaports.read_config(args)
# Call mkinitfs
logging.info("(" + suffix + ") mkinitfs " + flavor)
release_file = (args.work + "/chroot_" + suffix + "/usr/share/kernel/" +
flavor + "/kernel.release")
with open(release_file, "r") as handle:
release = handle.read().rstrip()
pmb.chroot.root(args, ["mkinitfs", "-o", "/boot/initramfs-" + flavor, release],
suffix)
logging.info(f"({suffix}) mkinitfs {flavor}")
if pmaports_cfg.get("supported_mkinitfs_without_flavors", False):
pmb.chroot.root(args, ["mkinitfs"], suffix)
else:
release_file = (f"{args.work}/chroot_{suffix}/usr/share/kernel/"
f"{flavor}/kernel.release")
with open(release_file, "r") as handle:
release = handle.read().rstrip()
pmb.chroot.root(args, ["mkinitfs", "-o",
f"/boot/initramfs-{flavor}", release],
suffix)
def extract(args, flavor, suffix, extra=False):
@ -30,30 +36,38 @@ def extract(args, flavor, suffix, extra=False):
"""
# Extraction folder
inside = "/tmp/initfs-extracted"
pmaports_cfg = pmb.config.pmaports.read_config(args)
if pmaports_cfg.get("supported_mkinitfs_without_flavors", False):
initfs_file = "/boot/initramfs"
else:
initfs_file = f"/boot/initramfs-${flavor}"
if extra:
inside = "/tmp/initfs-extra-extracted"
flavor += "-extra"
outside = args.work + "/chroot_" + suffix + inside
initfs_file += "-extra"
outside = f"{args.work}/chroot_{suffix}{inside}"
if os.path.exists(outside):
if not pmb.helpers.cli.confirm(args, "Extraction folder " + outside +
" already exists. Do you want to overwrite it?"):
if not pmb.helpers.cli.confirm(args, f"Extraction folder {outside}"
" already exists."
" Do you want to overwrite it?"):
raise RuntimeError("Aborted!")
pmb.chroot.root(args, ["rm", "-r", inside], suffix)
# Extraction script (because passing a file to stdin is not allowed
# in pmbootstrap's chroot/shell functions for security reasons)
with open(args.work + "/chroot_" + suffix + "/tmp/_extract.sh", "w") as handle:
with open(f"{args.work}/chroot_{suffix}/tmp/_extract.sh", "w") as handle:
handle.write(
"#!/bin/sh\n"
"cd " + inside + " && cpio -i < _initfs\n")
f"cd {inside} && cpio -i < _initfs\n")
# Extract
commands = [["mkdir", "-p", inside],
["cp", "/boot/initramfs-" + flavor, inside + "/_initfs.gz"],
["gzip", "-d", inside + "/_initfs.gz"],
["cp", initfs_file, f"{inside}/_initfs.gz"],
["gzip", "-d", f"{inside}/_initfs.gz"],
["cat", "/tmp/_extract.sh"], # for the log
["sh", "/tmp/_extract.sh"],
["rm", "/tmp/_extract.sh", inside + "/_initfs"]
["rm", "/tmp/_extract.sh", f"{inside}/_initfs"]
]
for command in commands:
pmb.chroot.root(args, command, suffix)
@ -73,11 +87,8 @@ def ls(args, flavor, suffix, extra=False):
def frontend(args):
# Find the appropriate kernel flavor
suffix = "rootfs_" + args.device
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix)
flavor = flavors[0]
if hasattr(args, "flavor") and args.flavor:
flavor = args.flavor
suffix = f"rootfs_{args.device}"
flavor = pmb.chroot.other.kernel_flavor_installed(args, suffix)
# Handle initfs actions
action = args.action_initfs
@ -85,9 +96,9 @@ def frontend(args):
build(args, flavor, suffix)
elif action == "extract":
dir = extract(args, flavor, suffix)
logging.info("Successfully extracted initramfs to: " + dir)
logging.info(f"Successfully extracted initramfs to: {dir}")
dir_extra = extract(args, flavor, suffix, True)
logging.info("Successfully extracted initramfs-extra to: " + dir_extra)
logging.info(f"Successfully extracted initramfs-extra to: {dir_extra}")
elif action == "ls":
logging.info("*** initramfs ***")
ls(args, flavor, suffix)
@ -103,10 +114,9 @@ def frontend(args):
elif action == "hook_del":
pmb.chroot.initfs_hooks.delete(args, args.hook, suffix)
# Rebuild the initfs for all kernels after adding/removing a hook
for flavor in flavors:
build(args, flavor, suffix)
# Rebuild the initfs after adding/removing a hook
build(args, flavor, suffix)
if action in ["ls", "extract"]:
link = "https://wiki.postmarketos.org/wiki/Initramfs_development"
logging.info("See also: <" + link + ">")
logging.info(f"See also: <{link}>")

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import glob
@ -23,7 +23,7 @@ def list_chroot(args, suffix, remove_prefix=True):
def list_aports(args):
ret = []
prefix = pmb.config.initfs_hook_prefix
for path in glob.glob(args.aports + "/*/" + prefix + "*"):
for path in glob.glob(f"{args.aports}/*/{prefix}*"):
ret.append(os.path.basename(path)[len(prefix):])
return ret
@ -33,31 +33,28 @@ def ls(args, suffix):
hooks_aports = list_aports(args)
for hook in hooks_aports:
line = "* " + hook
if hook in hooks_chroot:
line += " (installed)"
else:
line += " (not installed)"
line = f"* {hook} ({'' if hook in hooks_chroot else 'not '}installed)"
logging.info(line)
def add(args, hook, suffix):
if hook not in list_aports(args):
raise RuntimeError("Invalid hook name! Run 'pmbootstrap initfs hook_ls'"
raise RuntimeError("Invalid hook name!"
" Run 'pmbootstrap initfs hook_ls'"
" to get a list of all hooks.")
prefix = pmb.config.initfs_hook_prefix
pmb.chroot.apk.install(args, [prefix + hook], suffix)
pmb.chroot.apk.install(args, [f"{prefix}{hook}"], suffix)
def delete(args, hook, suffix):
if hook not in list_chroot(args, suffix):
raise RuntimeError("There is no such hook installed!")
prefix = pmb.config.initfs_hook_prefix
pmb.chroot.root(args, ["apk", "del", prefix + hook], suffix)
pmb.chroot.root(args, ["apk", "del", f"{prefix}{hook}"], suffix)
def update(args, suffix):
"""
Rebuild and update all hooks, that are out of date
Rebuild and update all hooks that are out of date
"""
pmb.chroot.apk.install(args, list_chroot(args, suffix, False), suffix)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import logging
@ -72,6 +72,9 @@ def mount_dev_tmpfs(args, suffix="native"):
"tmpfs", dev + "/shm"])
create_device_nodes(args, suffix)
# Setup /dev/fd as a symlink
pmb.helpers.run.root(args, ["ln", "-sf", "/proc/self/fd", f"{dev}/"])
def mount(args, suffix="native"):
# Mount tmpfs as the chroot's /dev
@ -103,3 +106,18 @@ def mount_native_into_foreign(args, suffix):
if not os.path.lexists(musl_link):
pmb.helpers.run.root(args, ["ln", "-s", "/native/lib/" + musl,
musl_link])
def remove_mnt_pmbootstrap(args, suffix):
""" Safely remove /mnt/pmbootstrap directories from the chroot, without
running rm -r as root and potentially removing data inside the
mountpoint in case it was still mounted (bug in pmbootstrap, or user
ran pmbootstrap 2x in parallel). This is similar to running 'rm -r -d',
but we don't assume that the host's rm has the -d flag (busybox does
not). """
mnt_dir = f"{args.work}/chroot_{suffix}/mnt/pmbootstrap"
if not os.path.exists(mnt_dir):
return
for path in glob.glob(f"{mnt_dir}/*") + [mnt_dir]:
pmb.helpers.run.root(args, ["rmdir", path])

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import glob
@ -7,38 +7,33 @@ import pmb.chroot.apk
import pmb.install
def kernel_flavors_installed(args, suffix, autoinstall=True):
def kernel_flavor_installed(args, suffix, autoinstall=True):
"""
Get all installed kernel flavors and make sure that there's at least one
Get installed kernel flavor. Optionally install the device's kernel
beforehand.
:param suffix: the chroot suffix, e.g. "native" or "rootfs_qemu-amd64"
:param autoinstall: make sure that at least one kernel flavor is installed
:returns: list of installed kernel flavors, e.g. ["postmarketos-mainline"]
:param autoinstall: install the device's kernel if it is not installed
:returns: * string with the installed kernel flavor,
e.g. ["postmarketos-qcom-sdm845"]
* None if no kernel is installed
"""
# Automatically install the selected kernel
if autoinstall:
packages = (["device-" + args.device] +
packages = ([f"device-{args.device}"] +
pmb.install.get_kernel_package(args, args.device))
pmb.chroot.apk.install(args, packages, suffix)
# Find all kernels in /boot
prefix = "vmlinuz-"
prefix_len = len(prefix)
pattern = args.work + "/chroot_" + suffix + "/boot/" + prefix + "*"
ret = []
for file in glob.glob(pattern):
flavor = os.path.basename(file)[prefix_len:]
if flavor[-4:] == "-dtb":
flavor = flavor[:-4]
ret.append(flavor)
pattern = f"{args.work}/chroot_{suffix}/usr/share/kernel/*"
glob_result = glob.glob(pattern)
# Return without duplicates
return list(set(ret))
# There should be only one directory here
return os.path.basename(glob_result[0]) if glob_result else None
def tempfolder(args, path, suffix="native"):
"""
Create a temporary folder inside the chroot, that belongs to "user".
Create a temporary folder inside the chroot that belongs to "user".
The folder gets deleted, if it already exists.
:param path: of the temporary folder inside the chroot

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import shutil
@ -18,14 +18,16 @@ def executables_absolute_path():
for binary in ["sh", "chroot"]:
path = shutil.which(binary, path=pmb.config.chroot_host_path)
if not path:
raise RuntimeError("Could not find the '" + binary +
"' executable. Make sure, that it is in" " your current user's PATH.")
raise RuntimeError(f"Could not find the '{binary}'"
" executable. Make sure that it is in"
" your current user's PATH.")
ret[binary] = path
return ret
def root(args, cmd, suffix="native", working_dir="/", output="log",
output_return=False, check=None, env={}, auto_init=True, disable_timeout=False):
output_return=False, check=None, env={}, auto_init=True,
disable_timeout=False):
"""
Run a command inside a chroot as root.
@ -37,25 +39,27 @@ def root(args, cmd, suffix="native", working_dir="/", output="log",
arguments and the return value.
"""
# Initialize chroot
chroot = args.work + "/chroot_" + suffix
if not auto_init and not os.path.islink(chroot + "/bin/sh"):
raise RuntimeError("Chroot does not exist: " + chroot)
chroot = f"{args.work}/chroot_{suffix}"
if not auto_init and not os.path.islink(f"{chroot}/bin/sh"):
raise RuntimeError(f"Chroot does not exist: {chroot}")
if auto_init:
pmb.chroot.init(args, suffix)
# Readable log message (without all the escaping)
msg = "(" + suffix + ") % "
msg = f"({suffix}) % "
for key, value in env.items():
msg += key + "=" + value + " "
msg += f"{key}={value} "
if working_dir != "/":
msg += "cd " + working_dir + "; "
msg += f"cd {working_dir}; "
msg += " ".join(cmd)
# Merge env with defaults into env_all
env_all = {"CHARSET": "UTF-8",
"HISTFILE": "~/.ash_history",
"HOME": "/root",
"LANG": "UTF-8",
"PATH": pmb.config.chroot_path,
"PYTHONUNBUFFERED": "1",
"SHELL": "/bin/ash",
"TERM": "xterm"}
for key, value in env.items():
@ -67,9 +71,11 @@ def root(args, cmd, suffix="native", working_dir="/", output="log",
# cmd_sudo: ["sudo", "env", "-i", "sh", "-c", "PATH=... /sbin/chroot ..."]
executables = executables_absolute_path()
cmd_chroot = [executables["chroot"], chroot, "/bin/sh", "-c",
pmb.helpers.run.flat_cmd(cmd, working_dir)]
cmd_sudo = ["sudo", "env", "-i", executables["sh"], "-c",
pmb.helpers.run.flat_cmd(cmd_chroot, env=env_all)]
kill_as_root = output in ["log", "stdout"]
pmb.helpers.run_core.flat_cmd(cmd, working_dir)]
cmd_sudo = pmb.config.sudo([
"env", "-i", executables["sh"], "-c",
pmb.helpers.run_core.flat_cmd(cmd_chroot, env=env_all)]
)
return pmb.helpers.run_core.core(args, msg, cmd_sudo, None, output,
output_return, check, kill_as_root, disable_timeout)
output_return, check, True,
disable_timeout)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import glob
@ -7,7 +7,6 @@ import socket
from contextlib import closing
import pmb.chroot
import pmb.chroot.distccd
import pmb.helpers.mount
import pmb.install.losetup
import pmb.parse.arch
@ -23,6 +22,17 @@ def kill_adb(args):
pmb.chroot.root(args, ["adb", "-P", str(port), "kill-server"])
def kill_sccache(args):
"""
Kill sccache daemon if it's running. Unlike ccache it automatically spawns
a daemon when you call it and exits after some time of inactivity.
"""
port = 4226
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
if sock.connect_ex(("127.0.0.1", port)) == 0:
pmb.chroot.root(args, ["sccache", "--stop-server"])
def shutdown_cryptsetup_device(args, name):
"""
:param name: cryptsetup device name, usually "pm_crypt" in pmbootstrap
@ -49,10 +59,9 @@ def shutdown_cryptsetup_device(args, name):
def shutdown(args, only_install_related=False):
pmb.chroot.distccd.stop(args)
# Stop adb server
# Stop daemons
kill_adb(args)
kill_sccache(args)
# Umount installation-related paths (order is important!)
pmb.helpers.mount.umount_all(args, args.work +
@ -67,10 +76,19 @@ def shutdown(args, only_install_related=False):
path = path_outside[len(chroot):]
pmb.install.losetup.umount(args, path, auto_init=False)
# Umount device rootfs chroot
chroot_rootfs = args.work + "/chroot_rootfs_" + args.device
if os.path.exists(chroot_rootfs):
pmb.helpers.mount.umount_all(args, chroot_rootfs)
# Umount device rootfs and installer chroots
for prefix in ["rootfs", "installer"]:
path = f"{args.work}/chroot_{prefix}_{args.device}"
if os.path.exists(path):
pmb.helpers.mount.umount_all(args, path)
# Remove "in-pmbootstrap" marker from all chroots. This marker indicates
# that pmbootstrap has set up all mount points etc. to run programs inside
# the chroots, but we want it gone afterwards (e.g. when the chroot
# contents get copied to a rootfs / installer image, or if creating an
# android recovery zip from its contents).
for marker in glob.glob(f"{args.work}/chroot_*/in-pmbootstrap"):
pmb.helpers.run.root(args, ["rm", marker])
if not only_install_related:
# Umount all folders inside args.work
@ -81,6 +99,6 @@ def shutdown(args, only_install_related=False):
# Clean up the rest
for arch in pmb.config.build_device_architectures:
if pmb.parse.arch.cpu_emulation_required(args, arch):
if pmb.parse.arch.cpu_emulation_required(arch):
pmb.chroot.binfmt.unregister(args, arch)
logging.debug("Shutdown complete")

View File

@ -1,7 +1,8 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.chroot.root
import pmb.helpers.run
import pmb.helpers.run_core
def user(args, cmd, suffix="native", working_dir="/", output="log",
@ -21,7 +22,7 @@ def user(args, cmd, suffix="native", working_dir="/", output="log",
if "HOME" not in env:
env["HOME"] = "/home/pmos"
flat_cmd = pmb.helpers.run.flat_cmd(cmd, env=env)
flat_cmd = pmb.helpers.run_core.flat_cmd(cmd, env=env)
cmd = ["busybox", "su", "pmos", "-c", flat_cmd]
return pmb.chroot.root(args, cmd, suffix, working_dir, output,
output_return, check, {}, auto_init)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import logging
@ -15,20 +15,21 @@ import pmb.parse.apkindex
def zap(args, confirm=True, dry=False, pkgs_local=False, http=False,
pkgs_local_mismatch=False, pkgs_online_mismatch=False, distfiles=False,
rust=False):
rust=False, netboot=False):
"""
Shutdown everything inside the chroots (e.g. distccd, adb), umount
Shutdown everything inside the chroots (e.g. adb), umount
everything and then safely remove folders from the work-directory.
:param dry: Only show what would be deleted, do not delete for real
:param pkgs_local: Remove *all* self-compiled packages (!)
:param http: Clear the http cache (used e.g. for the initial apk download)
:param pkgs_local_mismatch: Remove the packages, that have a different version
compared to what is in the aports folder.
:param pkgs_online_mismatch: Clean out outdated binary packages downloaded from
mirrors (e.g. from Alpine)
:param pkgs_local_mismatch: Remove the packages that have
a different version compared to what is in the aports folder.
:param pkgs_online_mismatch: Clean out outdated binary packages
downloaded from mirrors (e.g. from Alpine)
:param distfiles: Clear the downloaded files cache
:param rust: Remove rust related caches
:param netboot: Remove images for netboot
NOTE: This function gets called in pmb/config/init.py, with only args.work
and args.device set!
@ -39,7 +40,8 @@ def zap(args, confirm=True, dry=False, pkgs_local=False, http=False,
logging.debug("Calculate work folder size")
size_old = pmb.helpers.other.folder_size(args, args.work)
# Delete packages with a different version compared to aports, then re-index
# Delete packages with a different version compared to aports,
# then re-index
if pkgs_local_mismatch:
zap_pkgs_local_mismatch(args, confirm, dry)
@ -53,6 +55,7 @@ def zap(args, confirm=True, dry=False, pkgs_local=False, http=False,
patterns = [
"chroot_native",
"chroot_buildroot_*",
"chroot_installer_*",
"chroot_rootfs_*",
]
if pkgs_local:
@ -63,14 +66,17 @@ def zap(args, confirm=True, dry=False, pkgs_local=False, http=False,
patterns += ["cache_distfiles"]
if rust:
patterns += ["cache_rust"]
if netboot:
patterns += ["images_netboot"]
# Delete everything matching the patterns
for pattern in patterns:
pattern = os.path.realpath(args.work + "/" + pattern)
pattern = os.path.realpath(f"{args.work}/{pattern}")
matches = glob.glob(pattern)
for match in matches:
if not confirm or pmb.helpers.cli.confirm(args, "Remove " + match + "?"):
logging.info("% rm -rf " + match)
if (not confirm or
pmb.helpers.cli.confirm(args, f"Remove {match}?")):
logging.info(f"% rm -rf {match}")
if not dry:
pmb.helpers.run.root(args, ["rm", "-rf", match])
@ -78,15 +84,15 @@ def zap(args, confirm=True, dry=False, pkgs_local=False, http=False,
pmb.config.workdir.clean(args)
# Chroots were zapped, so no repo lists exist anymore
args.cache["apk_repository_list_updated"].clear()
pmb.helpers.other.cache["apk_repository_list_updated"].clear()
# Print amount of cleaned up space
if dry:
logging.info("Dry run: nothing has been deleted")
else:
size_new = pmb.helpers.other.folder_size(args, args.work)
mb = (size_old - size_new) / 1024 / 1024
logging.info("Cleared up ~" + str(math.ceil(mb)) + " MB of space")
mb = (size_old - size_new) / 1024
logging.info(f"Cleared up ~{math.ceil(mb)} MB of space")
def zap_pkgs_local_mismatch(args, confirm=True, dry=False):
@ -103,7 +109,7 @@ def zap_pkgs_local_mismatch(args, confirm=True, dry=False):
pattern = f"{args.work}/packages/{channel}/*/APKINDEX.tar.gz"
for apkindex_path in glob.glob(pattern):
# Delete packages without same version in aports
blocks = pmb.parse.apkindex.parse_blocks(args, apkindex_path)
blocks = pmb.parse.apkindex.parse_blocks(apkindex_path)
for block in blocks:
pkgname = block["pkgname"]
origin = block["origin"]
@ -111,29 +117,29 @@ def zap_pkgs_local_mismatch(args, confirm=True, dry=False):
arch = block["arch"]
# Apk path
apk_path_short = arch + "/" + pkgname + "-" + version + ".apk"
apk_path_short = f"{arch}/{pkgname}-{version}.apk"
apk_path = f"{args.work}/packages/{channel}/{apk_path_short}"
if not os.path.exists(apk_path):
logging.info("WARNING: Package mentioned in index not"
" found: " + apk_path_short)
f" found: {apk_path_short}")
continue
# Aport path
aport_path = pmb.helpers.pmaports.find(args, origin, False)
if not aport_path:
logging.info("% rm " + apk_path_short + " (" + origin +
" aport not found)")
logging.info(f"% rm {apk_path_short}"
f" ({origin} aport not found)")
if not dry:
pmb.helpers.run.root(args, ["rm", apk_path])
reindex = True
continue
# Clear out any binary apks that do not match what is in aports
apkbuild = pmb.parse.apkbuild(args, aport_path + "/APKBUILD")
version_aport = apkbuild["pkgver"] + "-r" + apkbuild["pkgrel"]
apkbuild = pmb.parse.apkbuild(f"{aport_path}/APKBUILD")
version_aport = f"{apkbuild['pkgver']}-r{apkbuild['pkgrel']}"
if version != version_aport:
logging.info("% rm " + apk_path_short + " (" + origin +
" aport: " + version_aport + ")")
logging.info(f"% rm {apk_path_short}"
f" ({origin} aport: {version_aport})")
if not dry:
pmb.helpers.run.root(args, ["rm", apk_path])
reindex = True
@ -144,18 +150,22 @@ def zap_pkgs_local_mismatch(args, confirm=True, dry=False):
def zap_pkgs_online_mismatch(args, confirm=True, dry=False):
# Check whether we need to do anything
paths = glob.glob(args.work + "/cache_apk_*")
paths = glob.glob(f"{args.work}/cache_apk_*")
if not len(paths):
return
if confirm and not pmb.helpers.cli.confirm(args, "Remove outdated binary packages?"):
if (confirm and not pmb.helpers.cli.confirm(args,
"Remove outdated"
" binary packages?")):
return
# Iterate over existing apk caches
for path in paths:
arch = os.path.basename(path).split("_", 2)[2]
suffix = "native" if arch == args.arch_native else "buildroot_" + arch
suffix = f"buildroot_{arch}"
if arch == pmb.config.arch_native:
suffix = "native"
# Clean the cache with apk
logging.info("(" + suffix + ") apk -v cache clean")
logging.info(f"({suffix}) apk -v cache clean")
if not dry:
pmb.chroot.root(args, ["apk", "-v", "cache", "clean"], suffix)

169
pmb/ci/__init__.py Normal file
View File

@ -0,0 +1,169 @@
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import collections
import glob
import logging
import os
import shlex
import pmb.chroot
import pmb.helpers.cli
def get_ci_scripts(topdir):
""" Find 'pmbootstrap ci'-compatible scripts inside a git repository, and
parse their metadata (description, options). The reference is at:
https://postmarketos.org/pmb-ci
:param topdir: top directory of the git repository, get it with:
pmb.helpers.git.get_topdir()
:returns: a dict of CI scripts found in the git repository, e.g.
{"ruff": {"description": "lint all python scripts",
"options": []},
...} """
ret = {}
for script in glob.glob(f"{topdir}/.ci/*.sh"):
is_pmb_ci_script = False
description = ""
options = []
with open(script) as handle:
for line in handle:
if line.startswith("# https://postmarketos.org/pmb-ci"):
is_pmb_ci_script = True
elif line.startswith("# Description: "):
description = line.split(": ", 1)[1].rstrip()
elif line.startswith("# Options: "):
options = line.split(": ", 1)[1].rstrip().split(" ")
elif not line.startswith("#"):
# Stop parsing after the block of comments on top
break
if not is_pmb_ci_script:
continue
if not description:
logging.error(f"ERROR: {script}: missing '# Description: …' line")
exit(1)
for option in options:
if option not in pmb.config.ci_valid_options:
raise RuntimeError(f"{script}: unsupported option '{option}'."
" Typo in script or pmbootstrap too old?")
short_name = os.path.basename(script).split(".", -1)[0]
ret[short_name] = {"description": description,
"options": options}
return ret
def sort_scripts_by_speed(scripts):
""" Order the scripts, so fast scripts run before slow scripts. Whether a
script is fast or not is determined by the '# Options: slow' comment in
the file.
:param scripts: return of get_ci_scripts()
:returns: same format as get_ci_scripts(), but as ordered dict with
fast scripts before slow scripts """
ret = collections.OrderedDict()
# Fast scripts first
for script_name, script in scripts.items():
if "slow" in script["options"]:
continue
ret[script_name] = script
# Then slow scripts
for script_name, script in scripts.items():
if "slow" not in script["options"]:
continue
ret[script_name] = script
return ret
def ask_which_scripts_to_run(scripts_available):
""" Display an interactive prompt about which of the scripts the user
wishes to run, or all of them.
:param scripts_available: same format as get_ci_scripts()
:returns: either full scripts_available (all selected), or a subset """
count = len(scripts_available.items())
choices = ["all"]
logging.info(f"Available CI scripts ({count}):")
for script_name, script in scripts_available.items():
extra = ""
if "slow" in script["options"]:
extra += " (slow)"
logging.info(f"* {script_name}: {script['description']}{extra}")
choices += [script_name]
selection = pmb.helpers.cli.ask("Which script?", None, "all",
complete=choices)
if selection == "all":
return scripts_available
ret = {}
ret[selection] = scripts_available[selection]
return ret
def copy_git_repo_to_chroot(args, topdir):
""" Create a tarball of the git repo (including unstaged changes and new
files) and extract it in chroot_native.
:param topdir: top directory of the git repository, get it with:
pmb.helpers.git.get_topdir() """
pmb.chroot.init(args)
tarball_path = f"{args.work}/chroot_native/tmp/git.tar.gz"
files = pmb.helpers.git.get_files(args, topdir)
with open(f"{tarball_path}.files", "w") as handle:
for file in files:
handle.write(file)
handle.write("\n")
pmb.helpers.run.user(args, ["tar", "-cf", tarball_path, "-T",
f"{tarball_path}.files"], topdir)
ci_dir = "/home/pmos/ci"
pmb.chroot.user(args, ["rm", "-rf", ci_dir])
pmb.chroot.user(args, ["mkdir", ci_dir])
pmb.chroot.user(args, ["tar", "-xf", "/tmp/git.tar.gz"],
working_dir=ci_dir)
def run_scripts(args, topdir, scripts):
""" Run one of the given scripts after another, either natively or in a
chroot. Display a progress message and stop on error (without printing
a python stack trace).
:param topdir: top directory of the git repository, get it with:
pmb.helpers.git.get_topdir()
:param scripts: return of get_ci_scripts() """
steps = len(scripts)
step = 0
repo_copied = False
for script_name, script in scripts.items():
step += 1
where = "pmbootstrap chroot"
if "native" in script["options"]:
where = "native"
script_path = f".ci/{script_name}.sh"
logging.info(f"*** ({step}/{steps}) RUNNING CI SCRIPT: {script_path}"
f" [{where}] ***")
if "native" in script["options"]:
rc = pmb.helpers.run.user(args, [script_path], topdir,
output="tui")
continue
else:
# Run inside pmbootstrap chroot
if not repo_copied:
copy_git_repo_to_chroot(args, topdir)
repo_copied = True
env = {"TESTUSER": "pmos"}
rc = pmb.chroot.root(args, [script_path], check=False, env=env,
working_dir="/home/pmos/ci",
output="tui")
if rc:
logging.error(f"ERROR: CI script failed: {script_name}")
exit(1)

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import glob
import json
import os
import shutil
@ -10,8 +11,11 @@ import pmb.config
import pmb.config.pmaports
import pmb.helpers.cli
import pmb.helpers.devices
import pmb.helpers.git
import pmb.helpers.http
import pmb.helpers.logging
import pmb.helpers.other
import pmb.helpers.pmaports
import pmb.helpers.run
import pmb.helpers.ui
import pmb.chroot.zap
@ -26,8 +30,25 @@ def require_programs():
missing.append(program)
if missing:
raise RuntimeError("Can't find all programs required to run"
" pmbootstrap. Please install first: " +
", ".join(missing))
" pmbootstrap. Please install first:"
f" {', '.join(missing)}")
def ask_for_username(args):
"""
Ask for a reasonable username for the non-root user.
:returns: the username
"""
while True:
ret = pmb.helpers.cli.ask("Username", None, args.user, False,
"[a-z_][a-z0-9_-]*")
if ret == "root":
logging.fatal("ERROR: don't put \"root\" here. This is about"
" creating an additional non-root user. Don't worry,"
" the root user will also be created ;)")
continue
return ret
def ask_for_work_path(args):
@ -45,13 +66,13 @@ def ask_for_work_path(args):
while True:
try:
work = os.path.expanduser(pmb.helpers.cli.ask(
args, "Work path", None, args.work, False))
"Work path", None, args.work, False))
work = os.path.realpath(work)
exists = os.path.exists(work)
# Work must not be inside the pmbootstrap path
if (work == pmb.config.pmb_src or
work.startswith(pmb.config.pmb_src + "/")):
work.startswith(f"{pmb.config.pmb_src}/")):
logging.fatal("ERROR: The work path must not be inside the"
" pmbootstrap path. Please specify another"
" location.")
@ -60,12 +81,18 @@ def ask_for_work_path(args):
# Create the folder with a version file
if not exists:
os.makedirs(work, 0o700, True)
with open(work + "/version", "w") as handle:
handle.write(str(pmb.config.work_version) + "\n")
# If the version file doesn't exists yet because we either just
# created the work directory or the user has deleted it for
# whatever reason then we need to write initialize it.
work_version_file = f"{work}/version"
if not os.path.isfile(work_version_file):
with open(work_version_file, "w") as handle:
handle.write(f"{pmb.config.work_version}\n")
# Create cache_git dir, so it is owned by the host system's user
# (otherwise pmb.helpers.mount.bind would create it as root)
os.makedirs(work + "/cache_git", 0o700, True)
os.makedirs(f"{work}/cache_git", 0o700, True)
return (work, exists)
except OSError:
logging.fatal("ERROR: Could not create this folder, or write"
@ -76,14 +103,17 @@ def ask_for_channel(args):
""" Ask for the postmarketOS release channel. The channel dictates, which
pmaports branch pmbootstrap will check out, and which repository URLs
will be used when initializing chroots.
:returns: channel name (e.g. "edge", "stable") """
:returns: channel name (e.g. "edge", "v21.03") """
channels_cfg = pmb.helpers.git.parse_channels_cfg(args)
count = len(channels_cfg["channels"])
# List channels
logging.info("Choose the postmarketOS release channel.")
logging.info(f"Available ({count}):")
for channel, channel_data in channels_cfg["channels"].items():
# Only show the first 3 releases. This includes edge, the latest supported
# release plus one. Should be a good solution until new needs arrive when
# we might want to have a custom channels.cfg attribute.
for channel, channel_data in list(channels_cfg["channels"].items())[:3]:
logging.info(f"* {channel}: {channel_data['description']}")
# Default for first run: "recommended" from channels.cfg
@ -97,7 +127,7 @@ def ask_for_channel(args):
# Ask until user gives valid channel
while True:
ret = pmb.helpers.cli.ask(args, "Channel", None, default,
ret = pmb.helpers.cli.ask("Channel", None, default,
complete=choices)
if ret in choices:
return ret
@ -105,17 +135,36 @@ def ask_for_channel(args):
" from the list above.")
def ask_for_ui(args, device):
info = pmb.parse.deviceinfo(args, device)
def ask_for_ui(args, info):
ui_list = pmb.helpers.ui.list(args, info["arch"])
logging.info("Available user interfaces (" +
str(len(ui_list) - 1) + "): ")
hidden_ui_count = 0
device_is_accelerated = info.get("gpu_accelerated") == "true"
if not device_is_accelerated:
for i in reversed(range(len(ui_list))):
pkgname = f"postmarketos-ui-{ui_list[i][0]}"
apkbuild = pmb.helpers.pmaports.get(args, pkgname,
subpackages=False,
must_exist=False)
if apkbuild and "pmb:gpu-accel" in apkbuild["options"]:
ui_list.pop(i)
hidden_ui_count += 1
# Get default
default = args.ui
if default not in dict(ui_list).keys():
default = pmb.config.defaults["ui"]
logging.info(f"Available user interfaces ({len(ui_list) - 1}): ")
ui_completion_list = []
for ui in ui_list:
logging.info("* " + ui[0] + ": " + ui[1])
logging.info(f"* {ui[0]}: {ui[1]}")
ui_completion_list.append(ui[0])
if hidden_ui_count > 0:
logging.info(f"NOTE: {hidden_ui_count} UIs are hidden because"
" \"deviceinfo_gpu_accelerated\" is not set (see"
" https://postmarketos.org/deviceinfo).")
while True:
ret = pmb.helpers.cli.ask(args, "User interface", None, args.ui, True,
ret = pmb.helpers.cli.ask("User interface", None, default, True,
complete=ui_completion_list)
if ret in dict(ui_list).keys():
return ret
@ -124,33 +173,33 @@ def ask_for_ui(args, device):
def ask_for_ui_extras(args, ui):
apkbuild = pmb.helpers.pmaports.get(args, "postmarketos-ui-" + ui,
apkbuild = pmb.helpers.pmaports.get(args, f"postmarketos-ui-{ui}",
subpackages=False, must_exist=False)
if not apkbuild:
return False
extra = apkbuild["subpackages"].get("postmarketos-ui-" + ui + "-extras")
extra = apkbuild["subpackages"].get(f"postmarketos-ui-{ui}-extras")
if extra is None:
return False
logging.info("This user interface has an extra package: " + extra["pkgdesc"])
logging.info("This user interface has an extra package:"
f" {extra['pkgdesc']}")
return pmb.helpers.cli.confirm(args, "Enable this package?",
default=args.ui_extras)
def ask_for_keymaps(args, device):
info = pmb.parse.deviceinfo(args, device)
def ask_for_keymaps(args, info):
if "keymaps" not in info or info["keymaps"].strip() == "":
return ""
options = info["keymaps"].split(' ')
logging.info("Available keymaps for device (" + str(len(options)) +
"): " + ", ".join(options))
logging.info(f"Available keymaps for device ({len(options)}): "
f"{', '.join(options)}")
if args.keymap == "":
args.keymap = options[0]
while True:
ret = pmb.helpers.cli.ask(args, "Keymap", None, args.keymap,
ret = pmb.helpers.cli.ask("Keymap", None, args.keymap,
True, complete=options)
if ret in options:
return ret
@ -174,8 +223,9 @@ def ask_for_timezone(args):
except:
pass
if tz:
logging.info("Your host timezone: " + tz)
if pmb.helpers.cli.confirm(args, "Use this timezone instead of GMT?",
logging.info(f"Your host timezone: {tz}")
if pmb.helpers.cli.confirm(args,
"Use this timezone instead of GMT?",
default="y"):
return tz
logging.info("WARNING: Unable to determine timezone configuration on host,"
@ -183,6 +233,80 @@ def ask_for_timezone(args):
return "GMT"
def ask_for_provider_select(args, apkbuild, providers_cfg):
"""
Ask for selectable providers that are specified using "_pmb_select"
in a APKBUILD.
:param apkbuild: the APKBUILD with the _pmb_select
:param providers_cfg: the configuration section with previously selected
providers. Updated with new providers after selection
"""
for select in apkbuild["_pmb_select"]:
providers = pmb.helpers.pmaports.find_providers(args, select)
logging.info(f"Available providers for {select} ({len(providers)}):")
has_default = False
providers_short = {}
last_selected = providers_cfg.get(select, 'default')
for pkgname, pkg in providers:
# Strip provider prefix if possible
short = pkgname
if short.startswith(f'{select}-'):
short = short[len(f"{select}-"):]
# Allow selecting the package using both short and long name
providers_short[pkgname] = pkgname
providers_short[short] = pkgname
if pkgname == last_selected:
last_selected = short
if not has_default and pkg.get('provider_priority', 0) != 0:
# Display as default provider
styles = pmb.config.styles
logging.info(f"* {short}: {pkg['pkgdesc']} "
f"{styles['BOLD']}(default){styles['END']}")
has_default = True
else:
logging.info(f"* {short}: {pkg['pkgdesc']}")
while True:
ret = pmb.helpers.cli.ask("Provider", None, last_selected, True,
complete=providers_short.keys())
if has_default and ret == 'default':
# Selecting default means to not select any provider explicitly
# In other words, apk chooses it automatically based on
# "provider_priority"
if select in providers_cfg:
del providers_cfg[select]
break
if ret in providers_short:
providers_cfg[select] = providers_short[ret]
break
logging.fatal("ERROR: Invalid provider specified, please type in"
" one from the list above.")
def ask_for_provider_select_pkg(args, pkgname, providers_cfg):
"""
Look up the APKBUILD for the specified pkgname and ask for selectable
providers that are specified using "_pmb_select".
:param pkgname: name of the package to search APKBUILD for
:param providers_cfg: the configuration section with previously selected
providers. Updated with new providers after selection
"""
apkbuild = pmb.helpers.pmaports.get(args, pkgname,
subpackages=False, must_exist=False)
if not apkbuild:
return
ask_for_provider_select(args, apkbuild, providers_cfg)
def ask_for_device_kernel(args, device):
"""
Ask for the kernel that should be used with the device.
@ -212,11 +336,11 @@ def ask_for_device_kernel(args, device):
" downstream kernels.")
# List kernels
logging.info("Available kernels (" + str(len(kernels)) + "):")
logging.info(f"Available kernels ({len(kernels)}):")
for type in sorted(kernels.keys()):
logging.info("* " + type + ": " + kernels[type])
logging.info(f"* {type}: {kernels[type]}")
while True:
ret = pmb.helpers.cli.ask(args, "Kernel", None, default, True,
ret = pmb.helpers.cli.ask("Kernel", None, default, True,
complete=kernels)
if ret in kernels.keys():
return ret
@ -241,12 +365,12 @@ def ask_for_device_nonfree(args, device):
"userland": args.nonfree_userland}
if not apkbuild_path:
return ret
apkbuild = pmb.parse.apkbuild(args, apkbuild_path)
apkbuild = pmb.parse.apkbuild(apkbuild_path)
# Only run when there is a "nonfree" subpackage
nonfree_found = False
for subpackage in apkbuild["subpackages"].keys():
if subpackage.startswith("device-" + device + "-nonfree"):
if subpackage.startswith(f"device-{device}-nonfree"):
nonfree_found = True
if not nonfree_found:
return ret
@ -260,12 +384,13 @@ def ask_for_device_nonfree(args, device):
# Ask for firmware and userland individually
for type in ["firmware", "userland"]:
subpkgname = "device-" + device + "-nonfree-" + type
subpkgname = f"device-{device}-nonfree-{type}"
subpkg = apkbuild["subpackages"].get(subpkgname, {})
if subpkg is None:
raise RuntimeError("Cannot find subpackage function for " + subpkgname)
raise RuntimeError("Cannot find subpackage function for "
f"{subpkgname}")
if subpkg:
logging.info(subpkgname + ": " + subpkg["pkgdesc"])
logging.info(f"{subpkgname}: {subpkg['pkgdesc']}")
ret[type] = pmb.helpers.cli.confirm(args, "Enable this package?",
default=ret[type])
return ret
@ -275,8 +400,7 @@ def ask_for_device(args):
vendors = sorted(pmb.helpers.devices.list_vendors(args))
logging.info("Choose your target device vendor (either an "
"existing one, or a new one for porting).")
logging.info("Available vendors (" + str(len(vendors)) + "): " +
", ".join(vendors))
logging.info(f"Available vendors ({len(vendors)}): {', '.join(vendors)}")
current_vendor = None
current_codename = None
@ -285,7 +409,7 @@ def ask_for_device(args):
current_codename = args.device.split("-", 1)[1]
while True:
vendor = pmb.helpers.cli.ask(args, "Vendor", None, current_vendor,
vendor = pmb.helpers.cli.ask("Vendor", None, current_vendor,
False, r"[a-z0-9]+", vendors)
new_vendor = vendor not in vendors
@ -297,36 +421,45 @@ def ask_for_device(args):
if not pmb.helpers.cli.confirm(args, default=True):
continue
else:
devices = sorted(pmb.helpers.devices.list_codenames(args, vendor))
# Unmaintained devices can be selected, but are not displayed
devices = sorted(pmb.helpers.devices.list_codenames(
args, vendor, unmaintained=False))
# Remove "vendor-" prefixes from device list
codenames = [x.split('-', 1)[1] for x in devices]
logging.info("Available codenames (" + str(len(codenames)) + "): " +
logging.info(f"Available codenames ({len(codenames)}): " +
", ".join(codenames))
if current_vendor != vendor:
current_codename = ''
codename = pmb.helpers.cli.ask(args, "Device codename", None,
codename = pmb.helpers.cli.ask("Device codename", None,
current_codename, False, r"[a-z0-9]+",
codenames)
device = vendor + '-' + codename
device_exists = pmb.helpers.devices.find_path(args, device, 'deviceinfo') is not None
device = f"{vendor}-{codename}"
device_path = pmb.helpers.devices.find_path(args, device, 'deviceinfo')
device_exists = device_path is not None
if not device_exists:
if device == args.device:
raise RuntimeError(
"This device does not exist anymore, check"
" <https://postmarketos.org/renamed>"
" to see if it was renamed")
logging.info("You are about to do a new device port for '" +
device + "'.")
logging.info("You are about to do"
f" a new device port for '{device}'.")
if not pmb.helpers.cli.confirm(args, default=True):
current_vendor = vendor
continue
# New port creation confirmed
logging.info("Generating new aports for: {}...".format(device))
pmb.aportgen.generate(args, "device-" + device)
pmb.aportgen.generate(args, "linux-" + device)
pmb.aportgen.generate(args, f"device-{device}")
pmb.aportgen.generate(args, f"linux-{device}")
elif "/unmaintained/" in device_path:
apkbuild = f"{device_path[:-len('deviceinfo')]}APKBUILD"
unmaintained = pmb.parse._apkbuild.unmaintained(apkbuild)
logging.info(f"WARNING: {device} is unmaintained: {unmaintained}")
if not pmb.helpers.cli.confirm(args):
continue
break
kernel = ask_for_device_kernel(args, device)
@ -337,41 +470,135 @@ def ask_for_device(args):
def ask_for_additional_options(args, cfg):
# Allow to skip additional options
logging.info("Additional options:"
f" extra free space: {args.extra_space} MB,"
f" boot partition size: {args.boot_size} MB,"
f" parallel jobs: {args.jobs},"
f" ccache per arch: {args.ccache_size}")
f" ccache per arch: {args.ccache_size},"
f" sudo timer: {args.sudo_timer},"
f" mirror: {','.join(args.mirrors_postmarketos)}")
if not pmb.helpers.cli.confirm(args, "Change them?",
default=False):
return
# Extra space
logging.info("Set extra free space to 0, unless you ran into a 'No space"
" left on device' error. In that case, the size of the"
" rootfs could not be calculated properly on your machine,"
" and we need to add extra free space to make the image big"
" enough to fit the rootfs (pmbootstrap#1904)."
" How much extra free space do you want to add to the image"
" (in MB)?")
answer = pmb.helpers.cli.ask("Extra space size", None,
args.extra_space, validation_regex="^[0-9]+$")
cfg["pmbootstrap"]["extra_space"] = answer
# Boot size
logging.info("What should be the boot partition size (in MB)?")
answer = pmb.helpers.cli.ask(args, "Boot size", None, args.boot_size,
validation_regex="[1-9][0-9]*")
answer = pmb.helpers.cli.ask("Boot size", None, args.boot_size,
validation_regex="^[1-9][0-9]*$")
cfg["pmbootstrap"]["boot_size"] = answer
# Parallel job count
logging.info("How many jobs should run parallel on this machine, when"
" compiling?")
answer = pmb.helpers.cli.ask(args, "Jobs", None, args.jobs,
validation_regex="[1-9][0-9]*")
answer = pmb.helpers.cli.ask("Jobs", None, args.jobs,
validation_regex="^[1-9][0-9]*$")
cfg["pmbootstrap"]["jobs"] = answer
# Ccache size
logging.info("We use ccache to speed up building the same code multiple"
" times. How much space should the ccache folder take up per"
" architecture? After init is through, you can check the current"
" usage with 'pmbootstrap stats'. Answer with 0 for infinite.")
" architecture? After init is through, you can check the"
" current usage with 'pmbootstrap stats'. Answer with 0 for"
" infinite.")
regex = "0|[0-9]+(k|M|G|T|Ki|Mi|Gi|Ti)"
answer = pmb.helpers.cli.ask(args, "Ccache size", None, args.ccache_size,
lowercase_answer=False, validation_regex=regex)
answer = pmb.helpers.cli.ask("Ccache size", None, args.ccache_size,
lowercase_answer=False,
validation_regex=regex)
cfg["pmbootstrap"]["ccache_size"] = answer
# Sudo timer
logging.info("pmbootstrap does everything in Alpine Linux chroots, so"
" your host system does not get modified. In order to"
" work with these chroots, pmbootstrap calls 'sudo'"
" internally. For long running operations, it is possible"
" that you'll have to authorize sudo more than once.")
answer = pmb.helpers.cli.confirm(args, "Enable background timer to prevent"
" repeated sudo authorization?",
default=args.sudo_timer)
cfg["pmbootstrap"]["sudo_timer"] = str(answer)
# Mirrors
# prompt for mirror change
logging.info("Selected mirror:"
f" {','.join(args.mirrors_postmarketos)}")
if pmb.helpers.cli.confirm(args, "Change mirror?", default=False):
mirrors = ask_for_mirror(args)
cfg["pmbootstrap"]["mirrors_postmarketos"] = ",".join(mirrors)
def ask_for_mirror(args):
regex = "^[1-9][0-9]*$" # single non-zero number only
json_path = pmb.helpers.http.download(
args, "https://postmarketos.org/mirrors.json", "pmos_mirrors",
cache=False)
with open(json_path, "rt") as handle:
s = handle.read()
logging.info("List of available mirrors:")
mirrors = json.loads(s)
keys = mirrors.keys()
i = 1
for key in keys:
logging.info(f"[{i}]\t{key} ({mirrors[key]['location']})")
i += 1
urls = []
for key in keys:
# accept only http:// or https:// urls
http_count = 0 # remember if we saw any http:// only URLs
link_list = []
for k in mirrors[key]["urls"]:
if k.startswith("http"):
link_list.append(k)
if k.startswith("http://"):
http_count += 1
# remove all https urls if there is more that one URL and one of
# them was http://
if http_count > 0 and len(link_list) > 1:
link_list = [k for k in link_list if not k.startswith("https")]
if len(link_list) > 0:
urls.append(link_list[0])
mirror_indexes = []
for mirror in args.mirrors_postmarketos:
for i in range(len(urls)):
if urls[i] == mirror:
mirror_indexes.append(str(i + 1))
break
mirrors_list = []
# require one valid mirror index selected by user
while len(mirrors_list) != 1:
answer = pmb.helpers.cli.ask("Select a mirror", None,
",".join(mirror_indexes),
validation_regex=regex)
mirrors_list = []
for i in answer.split(","):
idx = int(i) - 1
if 0 <= idx < len(urls):
mirrors_list.append(urls[idx])
if len(mirrors_list) != 1:
logging.info("You must select one valid mirror!")
return mirrors_list
def ask_for_hostname(args, device):
while True:
ret = pmb.helpers.cli.ask(args, "Device hostname (short form, e.g. 'foo')",
ret = pmb.helpers.cli.ask("Device hostname (short form, e.g. 'foo')",
None, (args.hostname or device), True)
if not pmb.helpers.other.validate_hostname(ret):
continue
@ -385,10 +612,52 @@ def ask_for_ssh_keys(args):
if not len(glob.glob(os.path.expanduser("~/.ssh/id_*.pub"))):
return False
return pmb.helpers.cli.confirm(args,
"Would you like to copy your SSH public keys to the device?",
"Would you like to copy your SSH public"
" keys to the device?",
default=args.ssh_keys)
def ask_build_pkgs_on_install(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.build_pkgs_on_install)
def get_locales():
ret = []
list_path = f"{pmb.config.pmb_src}/pmb/data/locales"
with open(list_path, "r") as handle:
for line in handle:
ret += [line.rstrip()]
return ret
def ask_for_locale(args):
locales = get_locales()
logging.info("Choose your preferred locale, like e.g. en_US. Only UTF-8"
" is supported, it gets appended automatically. Use"
" tab-completion if needed.")
while True:
ret = pmb.helpers.cli.ask("Locale",
choices=None,
default=args.locale.replace(".UTF-8", ""),
lowercase_answer=False,
complete=locales)
ret = ret.replace(".UTF-8", "")
if ret not in locales:
logging.info("WARNING: this locale is not in the list of known"
" valid locales.")
if pmb.helpers.cli.ask() != "y":
# Ask again
continue
return f"{ret}.UTF-8"
def frontend(args):
require_programs()
@ -412,6 +681,15 @@ def frontend(args):
pmb.config.pmaports.switch_to_channel_branch(args, channel)
cfg["pmbootstrap"]["is_default_channel"] = "False"
# Copy the git hooks if master was checked out. (Don't symlink them and
# only do it on master, so the git hooks don't change unexpectedly when
# having a random branch checked out.)
branch_current = pmb.helpers.git.rev_parse(args, args.aports,
extra_args=["--abbrev-ref"])
if branch_current == "master":
logging.info("NOTE: pmaports is on master branch, copying git hooks.")
pmb.config.pmaports.install_githooks(args)
# Device
device, device_exists, kernel, nonfree = ask_for_device(args)
cfg["pmbootstrap"]["device"] = device
@ -419,25 +697,32 @@ def frontend(args):
cfg["pmbootstrap"]["nonfree_firmware"] = str(nonfree["firmware"])
cfg["pmbootstrap"]["nonfree_userland"] = str(nonfree["userland"])
info = pmb.parse.deviceinfo(args, device)
apkbuild_path = pmb.helpers.devices.find_path(args, device, 'APKBUILD')
if apkbuild_path:
apkbuild = pmb.parse.apkbuild(apkbuild_path)
ask_for_provider_select(args, apkbuild, cfg["providers"])
# Device keymap
if device_exists:
cfg["pmbootstrap"]["keymap"] = ask_for_keymaps(args, device)
cfg["pmbootstrap"]["keymap"] = ask_for_keymaps(args, info)
cfg["pmbootstrap"]["user"] = ask_for_username(args)
ask_for_provider_select_pkg(args, "postmarketos-base", cfg["providers"])
# Username
cfg["pmbootstrap"]["user"] = pmb.helpers.cli.ask(args, "Username", None,
args.user, False,
"[a-z_][a-z0-9_-]*")
# UI and various build options
ui = ask_for_ui(args, device)
ui = ask_for_ui(args, info)
cfg["pmbootstrap"]["ui"] = ui
cfg["pmbootstrap"]["ui_extras"] = str(ask_for_ui_extras(args, ui))
ask_for_provider_select_pkg(args, f"postmarketos-ui-{ui}",
cfg["providers"])
ask_for_additional_options(args, cfg)
# Extra packages to be installed to rootfs
logging.info("Additional packages that will be installed to rootfs."
" Specify them in a comma separated list (e.g.: vim,file)"
" or \"none\"")
extra = pmb.helpers.cli.ask(args, "Extra packages", None,
extra = pmb.helpers.cli.ask("Extra packages", None,
args.extra_packages,
validation_regex=r"^([-.+\w]+)(,[-.+\w]+)*$")
cfg["pmbootstrap"]["extra_packages"] = extra
@ -445,6 +730,9 @@ def frontend(args):
# Configure timezone info
cfg["pmbootstrap"]["timezone"] = ask_for_timezone(args)
# Locale
cfg["pmbootstrap"]["locale"] = ask_for_locale(args)
# Hostname
cfg["pmbootstrap"]["hostname"] = ask_for_hostname(args, device)
@ -454,14 +742,20 @@ 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"]["build_pkgs_on_install"] = str(
ask_build_pkgs_on_install(args))
# Save config
pmb.config.save(args, cfg)
# Zap existing chroots
if (work_exists and device_exists and
len(glob.glob(args.work + "/chroot_*")) and
pmb.helpers.cli.confirm(args, "Zap existing chroots to apply configuration?", default=True)):
setattr(args, "deviceinfo", pmb.parse.deviceinfo(args, device=device))
pmb.helpers.cli.confirm(
args, "Zap existing chroots to apply configuration?",
default=True)):
setattr(args, "deviceinfo", info)
# Do not zap any existing packages or cache_http directories
pmb.chroot.zap(args, confirm=False)
@ -470,4 +764,4 @@ def frontend(args):
" not get updated automatically.")
logging.info("Run 'pmbootstrap status' once a day before working with"
" pmbootstrap to make sure that everything is up-to-date.")
logging.info("Done!")
logging.info("DONE!")

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import configparser
@ -13,6 +13,8 @@ def load(args):
if "pmbootstrap" not in cfg:
cfg["pmbootstrap"] = {}
if "providers" not in cfg:
cfg["providers"] = {}
for key in pmb.config.defaults:
if key in pmb.config.config_keys and key not in cfg["pmbootstrap"]:
@ -20,12 +22,13 @@ def load(args):
# We used to save default values in the config, which can *not* be
# configured in "pmbootstrap init". That doesn't make sense, we always
# want to use the defaults from pmb/config/__init__.py in that case, not
# some outdated version we saved some time back (eg. aports folder,
# want to use the defaults from pmb/config/__init__.py in that case,
# not some outdated version we saved some time back (eg. aports folder,
# postmarketOS binary packages mirror).
if key not in pmb.config.config_keys and key in cfg["pmbootstrap"]:
logging.debug("Ignored unconfigurable and possibly outdated default"
" value from config: " + str(cfg["pmbootstrap"][key]))
logging.debug("Ignored unconfigurable and possibly outdated"
" default value from config:"
f" {cfg['pmbootstrap'][key]}")
del cfg["pmbootstrap"][key]
return cfg

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.config
@ -6,7 +6,8 @@ import pmb.config
def merge_with_args(args):
"""
We have the internal config (pmb/config/__init__.py) and the user config
(usually ~/.config/pmbootstrap.cfg, can be changed with the '-c' parameter).
(usually ~/.config/pmbootstrap.cfg, can be changed with the '-c'
parameter).
Args holds the variables parsed from the commandline (e.g. -j fills out
args.jobs), and values specified on the commandline count the most.
@ -28,6 +29,7 @@ def merge_with_args(args):
if isinstance(default, bool):
value = (value.lower() == "true")
setattr(args, key, value)
setattr(args, 'selected_providers', cfg['providers'])
# Use defaults from pmb.config.defaults
for key, value in pmb.config.defaults.items():

View File

@ -1,11 +1,13 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import configparser
import logging
import os
import sys
import pmb.config
import pmb.helpers.git
import pmb.helpers.pmaports
def check_legacy_folder():
@ -23,17 +25,11 @@ def check_legacy_folder():
def clone(args):
# Explain sudo-usage before using it the first time
logging.info("pmbootstrap does everything in Alpine Linux chroots, so your"
" host system does not get modified. In order to work with"
" these chroots, pmbootstrap calls 'sudo' internally. To see"
" the commands it runs, you can run 'pmbootstrap log' in a"
" second terminal.")
logging.info("Setting up the native chroot and cloning the package build"
" recipes (pmaports)...")
# Set up the native chroot and clone pmaports
pmb.helpers.git.clone(args, "pmaports", False)
pmb.helpers.git.clone(args, "pmaports")
def symlink(args):
@ -63,7 +59,7 @@ def check_version_pmaports(real):
def check_version_pmbootstrap(min):
# Compare versions
real = pmb.config.version
real = pmb.__version__
if pmb.parse.version.compare(real, min) >= 0:
return
@ -89,14 +85,14 @@ def read_config(args):
""" Read and verify pmaports.cfg. """
# Try cache first
cache_key = "pmb.config.pmaports.read_config"
if args.cache[cache_key]:
return args.cache[cache_key]
if pmb.helpers.other.cache[cache_key]:
return pmb.helpers.other.cache[cache_key]
# Migration message
if not os.path.exists(args.aports):
raise RuntimeError("We have split the aports repository from the"
" pmbootstrap repository (#383). Please run"
" 'pmbootstrap init' again to clone it.")
logging.error(f"ERROR: pmaports dir not found: {args.aports}")
logging.error("Did you run 'pmbootstrap init'?")
sys.exit(1)
# Require the config
path_cfg = args.aports + "/pmaports.cfg"
@ -113,8 +109,11 @@ def read_config(args):
check_version_pmaports(ret["version"])
check_version_pmbootstrap(ret["pmbootstrap_min_version"])
# Translate legacy channel names
ret["channel"] = pmb.helpers.pmaports.get_channel_new(ret["channel"])
# Cache and return
args.cache[cache_key] = ret
pmb.helpers.other.cache[cache_key] = ret
return ret
@ -159,7 +158,7 @@ def init(args):
def switch_to_channel_branch(args, channel_new):
""" Checkout the channel's branch in pmaports.git.
:channel_new: channel name (e.g. "edge", "stable")
:channel_new: channel name (e.g. "edge", "v21.03")
:returns: True if another branch was checked out, False otherwise """
# Check current pmaports branch channel
channel_current = read_config(args)["channel"]
@ -188,8 +187,22 @@ def switch_to_channel_branch(args, channel_new):
f"{args.aports}")
# Invalidate all caches
pmb.helpers.args.add_cache(args)
pmb.helpers.other.init_cache()
# Verify pmaports.cfg on new branch
read_config(args)
return True
def install_githooks(args):
hooks_dir = os.path.join(args.aports, ".githooks")
if not os.path.exists(hooks_dir):
logging.info("No .githooks dir found")
return
for h in os.listdir(hooks_dir):
src = os.path.join(hooks_dir, h)
# Use git default hooks dir so users can ignore our hooks
# if they dislike them by setting "core.hooksPath" git config
dst = os.path.join(args.aports, ".git", "hooks", h)
if pmb.helpers.run.user(args, ["cp", src, dst], check=False):
logging.warning(f"WARNING: Copying git hook failed: {dst}")

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging

36
pmb/config/sudo.py Normal file
View File

@ -0,0 +1,36 @@
# Copyright 2023 Anjandev Momi
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import shutil
from functools import lru_cache
from typing import Optional
@lru_cache()
def which_sudo() -> Optional[str]:
"""Returns a command required to run commands as root, if any.
Find whether sudo or doas is installed for commands that require root.
Allows user to override preferred sudo with PMB_SUDO env variable.
"""
if os.getuid() == 0:
return None
supported_sudos = ['doas', 'sudo']
user_set_sudo = os.getenv("PMB_SUDO")
if user_set_sudo is not None:
if shutil.which(user_set_sudo) is None:
raise RuntimeError("PMB_SUDO environmental variable is set to"
f" {user_set_sudo} but pmbootstrap cannot find"
" this command on your system.")
return user_set_sudo
for sudo in supported_sudos:
if shutil.which(sudo) is not None:
return sudo
raise RuntimeError("Can't find sudo or doas required to run pmbootstrap."
" Please install sudo, doas, or specify your own sudo"
" with the PMB_SUDO environmental variable.")

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
""" Save, read, verify workdir state related information in $WORK/workdir.cfg,
for example the init dates of the chroots. This is not saved in

View File

@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwXEJ8uVwJPODshTkf2BH
pH5fVVDppOa974+IQJsZDmGd3Ny0dcd+WwYUhNFUW3bAfc3/egaMWCaprfaHn+oS
4ddbOFgbX8JCHdru/QMAAU0aEWSMybfJGA569c38fNUF/puX6XK/y0lD2SS3YQ/a
oJ5jb5eNrQGR1HHMAd0G9WC4JeZ6WkVTkrcOw55F00aUPGEjejreXBerhTyFdabo
dSfc1TILWIYD742Lkm82UBOPsOSdSfOdsMOOkSXxhdCJuCQQ70DHkw7Epy9r+X33
ybI4r1cARcV75OviyhD8CFhAlapLKaYnRFqFxlA515e6h8i8ih/v3MSEW17cCK0b
QwIDAQAB
-----END PUBLIC KEY-----

View File

@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwR4uJVtJOnOFGchnMW5Y
j5/waBdG1u5BTMlH+iQMcV5+VgWhmpZHJCBz3ocD+0IGk2I68S5TDOHec/GSC0lv
6R9o6F7h429GmgPgVKQsc8mPTPtbjJMuLLs4xKc+viCplXc0Nc0ZoHmCH4da6fCV
tdpHQjVe6F9zjdquZ4RjV6R6JTiN9v924dGMAkbW/xXmamtz51FzondKC52Gh8Mo
/oA0/T0KsCMCi7tb4QNQUYrf+Xcha9uus4ww1kWNZyfXJB87a2kORLiWMfs2IBBJ
TmZ2Fnk0JnHDb8Oknxd9PvJPT0mvyT8DA+KIAPqNvOjUXP4bnjEHJcoCP9S5HkGC
IQIDAQAB
-----END PUBLIC KEY-----

View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAutQkua2CAig4VFSJ7v54
ALyu/J1WB3oni7qwCZD3veURw7HxpNAj9hR+S5N/pNeZgubQvJWyaPuQDm7PTs1+
tFGiYNfAsiibX6Rv0wci3M+z2XEVAeR9Vzg6v4qoofDyoTbovn2LztaNEjTkB+oK
tlvpNhg1zhou0jDVYFniEXvzjckxswHVb8cT0OMTKHALyLPrPOJzVtM9C1ew2Nnc
3848xLiApMu3NBk0JqfcS3Bo5Y2b1FRVBvdt+2gFoKZix1MnZdAEZ8xQzL/a0YS5
Hd0wj5+EEKHfOd3A75uPa/WQmA+o0cBFfrzm69QDcSJSwGpzWrD1ScH3AK8nWvoj
v7e9gukK/9yl1b4fQQ00vttwJPSgm9EnfPHLAtgXkRloI27H6/PuLoNvSAMQwuCD
hQRlyGLPBETKkHeodfLoULjhDi1K2gKJTMhtbnUcAA7nEphkMhPWkBpgFdrH+5z4
Lxy+3ek0cqcI7K68EtrffU8jtUj9LFTUC8dERaIBs7NgQ/LfDbDfGh9g6qVj1hZl
k9aaIPTm/xsi8v3u+0qaq7KzIBc9s59JOoA8TlpOaYdVgSQhHHLBaahOuAigH+VI
isbC9vmqsThF2QdDtQt37keuqoda2E6sL7PUvIyVXDRfwX7uMDjlzTxHTymvq2Ck
htBqojBnThmjJQFgZXocHG8CAwEAAQ==
-----END PUBLIC KEY-----

View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAlEyxkHggKCXC2Wf5Mzx4
nZLFZvU2bgcA3exfNPO/g1YunKfQY+Jg4fr6tJUUTZ3XZUrhmLNWvpvSwDS19ZmC
IXOu0+V94aNgnhMsk9rr59I8qcbsQGIBoHzuAl8NzZCgdbEXkiY90w1skUw8J57z
qCsMBydAueMXuWqF5nGtYbi5vHwK42PffpiZ7G5Kjwn8nYMW5IZdL6ZnMEVJUWC9
I4waeKg0yskczYDmZUEAtrn3laX9677ToCpiKrvmZYjlGl0BaGp3cxggP2xaDbUq
qfFxWNgvUAb3pXD09JM6Mt6HSIJaFc9vQbrKB9KT515y763j5CC2KUsilszKi3mB
HYe5PoebdjS7D1Oh+tRqfegU2IImzSwW3iwA7PJvefFuc/kNIijfS/gH/cAqAK6z
bhdOtE/zc7TtqW2Wn5Y03jIZdtm12CxSxwgtCF1NPyEWyIxAQUX9ACb3M0FAZ61n
fpPrvwTaIIxxZ01L3IzPLpbc44x/DhJIEU+iDt6IMTrHOphD9MCG4631eIdB0H1b
6zbNX1CXTsafqHRFV9XmYYIeOMggmd90s3xIbEujA6HKNP/gwzO6CDJ+nHFDEqoF
SkxRdTkEqjTjVKieURW7Swv7zpfu5PrsrrkyGnsRrBJJzXlm2FOOxnbI2iSL1B5F
rO5kbUxFeZUIDq+7Yv4kLWcCAwEAAQ==
-----END PUBLIC KEY-----

View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnC+bR4bHf/L6QdU4puhQ
gl1MHePszRC38bzvVFDUJsmCaMCL2suCs2A2yxAgGb9pu9AJYLAmxQC4mM3jNqhg
/E7yuaBbek3O02zN/ctvflJ250wZCy+z0ZGIp1ak6pu1j14IwHokl9j36zNfGtfv
ADVOcdpWITFFlPqwq1qt/H3UsKVmtiF3BNWWTeUEQwKvlU8ymxgS99yn0+4OPyNT
L3EUeS+NQJtDS01unau0t7LnjUXn+XIneWny8bIYOQCuVR6s/gpIGuhBaUqwaJOw
7jkJZYF2Ij7uPb4b5/R3vX2FfxxqEHqssFSg8FFUNTZz3qNZs0CRVyfA972g9WkJ
hPfn31pQYil4QGRibCMIeU27YAEjXoqfJKEPh4UWMQsQLrEfdGfb8VgwrPbniGfU
L3jKJR3VAafL9330iawzVQDlIlwGl6u77gEXMl9K0pfazunYhAp+BMP+9ot5ckK+
osmrqj11qMESsAj083GeFdfV3pXEIwUytaB0AKEht9DbqUfiE/oeZ/LAXgySMtVC
sbC4ESmgVeY2xSBIJdDyUap7FR49GGrw0W49NUv9gRgQtGGaNVQQO9oGL2PBC41P
iWF9GLoX30HIz1P8PF/cZvicSSPkQf2Z6TV+t0ebdGNS5DjapdnCrq8m9Z0pyKsQ
uxAL2a7zX8l5i1CZh1ycUGsCAwEAAQ==
-----END PUBLIC KEY-----

View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0MfCDrhODRCIxR9Dep1s
eXafh5CE5BrF4WbCgCsevyPIdvTeyIaW4vmO3bbG4VzhogDZju+R3IQYFuhoXP5v
Y+zYJGnwrgz3r5wYAvPnLEs1+dtDKYOgJXQj+wLJBW1mzRDL8FoRXOe5iRmn1EFS
wZ1DoUvyu7/J5r0itKicZp3QKED6YoilXed+1vnS4Sk0mzN4smuMR9eO1mMCqNp9
9KTfRDHTbakIHwasECCXCp50uXdoW6ig/xUAFanpm9LtK6jctNDbXDhQmgvAaLXZ
LvFqoaYJ/CvWkyYCgL6qxvMvVmPoRv7OPcyni4xR/WgWa0MSaEWjgPx3+yj9fiMA
1S02pFWFDOr5OUF/O4YhFJvUCOtVsUPPfA/Lj6faL0h5QI9mQhy5Zb9TTaS9jB6p
Lw7u0dJlrjFedk8KTJdFCcaGYHP6kNPnOxMylcB/5WcztXZVQD5WpCicGNBxCGMm
W64SgrV7M07gQfL/32QLsdqPUf0i8hoVD8wfQ3EpbQzv6Fk1Cn90bZqZafg8XWGY
wddhkXk7egrr23Djv37V2okjzdqoyLBYBxMz63qQzFoAVv5VoY2NDTbXYUYytOvG
GJ1afYDRVWrExCech1mX5ZVUB1br6WM+psFLJFoBFl6mDmiYt0vMYBddKISsvwLl
IJQkzDwtXzT2cSjoj3T5QekCAwEAAQ==
-----END PUBLIC KEY-----

View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvaaoSLab+IluixwKV5Od
0gib2YurjPatGIbn5Ov2DLUFYiebj2oJINXJSwUOO+4WcuHFEqiL/1rya+k5hLZt
hnPL1tn6QD4rESznvGSasRCQNT2vS/oyZbTYJRyAtFkEYLlq0t3S3xBxxHWuvIf0
qVxVNYpQWyM3N9RIeYBR/euXKJXileSHk/uq1I5wTC0XBIHWcthczGN0m9wBEiWS
0m3cnPk4q0Ea8mUJ91Rqob19qETz6VbSPYYpZk3qOycjKosuwcuzoMpwU8KRiMFd
5LHtX0Hx85ghGsWDVtS0c0+aJa4lOMGvJCAOvDfqvODv7gKlCXUpgumGpLdTmaZ8
1RwqspAe3IqBcdKTqRD4m2mSg23nVx2FAY3cjFvZQtfooT7q1ItRV5RgH6FhQSl7
+6YIMJ1Bf8AAlLdRLpg+doOUGcEn+pkDiHFgI8ylH1LKyFKw+eXaAml/7DaWZk1d
dqggwhXOhc/UUZFQuQQ8A8zpA13PcbC05XxN2hyP93tCEtyynMLVPtrRwDnHxFKa
qKzs3rMDXPSXRn3ZZTdKH3069ApkEjQdpcwUh+EmJ1Ve/5cdtzT6kKWCjKBFZP/s
91MlRrX2BTRdHaU5QJkUheUtakwxuHrdah2F94lRmsnQlpPr2YseJu6sIE+Dnx4M
CfhdVbQL2w54R645nlnohu8CAwEAAQ==
-----END PUBLIC KEY-----

View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAq0BFD1D4lIxQcsqEpQzU
pNCYM3aP1V/fxxVdT4DWvSI53JHTwHQamKdMWtEXetWVbP5zSROniYKFXd/xrD9X
0jiGHey3lEtylXRIPxe5s+wXoCmNLcJVnvTcDtwx/ne2NLHxp76lyc25At+6RgE6
ADjLVuoD7M4IFDkAsd8UQ8zM0Dww9SylIk/wgV3ZkifecvgUQRagrNUdUjR56EBZ
raQrev4hhzOgwelT0kXCu3snbUuNY/lU53CoTzfBJ5UfEJ5pMw1ij6X0r5S9IVsy
KLWH1hiO0NzU2c8ViUYCly4Fe9xMTFc6u2dy/dxf6FwERfGzETQxqZvSfrRX+GLj
/QZAXiPg5178hT/m0Y3z5IGenIC/80Z9NCi+byF1WuJlzKjDcF/TU72zk0+PNM/H
Kuppf3JT4DyjiVzNC5YoWJT2QRMS9KLP5iKCSThwVceEEg5HfhQBRT9M6KIcFLSs
mFjx9kNEEmc1E8hl5IR3+3Ry8G5/bTIIruz14jgeY9u5jhL8Vyyvo41jgt9sLHR1
/J1TxKfkgksYev7PoX6/ZzJ1ksWKZY5NFoDXTNYUgzFUTOoEaOg3BAQKadb3Qbbq
XIrxmPBdgrn9QI7NCgfnAY3Tb4EEjs3ON/BNyEhUENcXOH6I1NbcuBQ7g9P73kE4
VORdoc8MdJ5eoKBpO8Ww8HECAwEAAQ==
-----END PUBLIC KEY-----

View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAyduVzi1mWm+lYo2Tqt/0
XkCIWrDNP1QBMVPrE0/ZlU2bCGSoo2Z9FHQKz/mTyMRlhNqTfhJ5qU3U9XlyGOPJ
piM+b91g26pnpXJ2Q2kOypSgOMOPA4cQ42PkHBEqhuzssfj9t7x47ppS94bboh46
xLSDRff/NAbtwTpvhStV3URYkxFG++cKGGa5MPXBrxIp+iZf9GnuxVdST5PGiVGP
ODL/b69sPJQNbJHVquqUTOh5Ry8uuD2WZuXfKf7/C0jC/ie9m2+0CttNu9tMciGM
EyKG1/Xhk5iIWO43m4SrrT2WkFlcZ1z2JSf9Pjm4C2+HovYpihwwdM/OdP8Xmsnr
DzVB4YvQiW+IHBjStHVuyiZWc+JsgEPJzisNY0Wyc/kNyNtqVKpX6dRhMLanLmy+
f53cCSI05KPQAcGj6tdL+D60uKDkt+FsDa0BTAobZ31OsFVid0vCXtsbplNhW1IF
HwsGXBTVcfXg44RLyL8Lk/2dQxDHNHzAUslJXzPxaHBLmt++2COa2EI1iWlvtznk
Ok9WP8SOAIj+xdqoiHcC4j72BOVVgiITIJNHrbppZCq6qPR+fgXmXa+sDcGh30m6
9Wpbr28kLMSHiENCWTdsFij+NQTd5S47H7XTROHnalYDuF1RpS+DpQidT5tUimaT
JZDr++FjKrnnijbyNF8b98UCAwEAAQ==
-----END PUBLIC KEY-----

View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnpUpyWDWjlUk3smlWeA0
lIMW+oJ38t92CRLHH3IqRhyECBRW0d0aRGtq7TY8PmxjjvBZrxTNDpJT6KUk4LRm
a6A6IuAI7QnNK8SJqM0DLzlpygd7GJf8ZL9SoHSH+gFsYF67Cpooz/YDqWrlN7Vw
tO00s0B+eXy+PCXYU7VSfuWFGK8TGEv6HfGMALLjhqMManyvfp8hz3ubN1rK3c8C
US/ilRh1qckdbtPvoDPhSbTDmfU1g/EfRSIEXBrIMLg9ka/XB9PvWRrekrppnQzP
hP9YE3x/wbFc5QqQWiRCYyQl/rgIMOXvIxhkfe8H5n1Et4VAorkpEAXdsfN8KSVv
LSMazVlLp9GYq5SUpqYX3KnxdWBgN7BJoZ4sltsTpHQ/34SXWfu3UmyUveWj7wp0
x9hwsPirVI00EEea9AbP7NM2rAyu6ukcm4m6ATd2DZJIViq2es6m60AE6SMCmrQF
wmk4H/kdQgeAELVfGOm2VyJ3z69fQuywz7xu27S6zTKi05Qlnohxol4wVb6OB7qG
LPRtK9ObgzRo/OPumyXqlzAi/Yvyd1ZQk8labZps3e16bQp8+pVPiumWioMFJDWV
GZjCmyMSU8V6MB6njbgLHoyg2LCukCAeSjbPGGGYhnKLm1AKSoJh3IpZuqcKCk5C
8CM1S15HxV78s9dFntEqIokCAwEAAQ==
-----END PUBLIC KEY-----

304
pmb/data/locales Normal file
View File

@ -0,0 +1,304 @@
C
a_DJ
aa_ER
aa_ET
af_ZA
agr_PE
ak_GH
am_ET
an_ES
anp_IN
ar_AE
ar_BH
ar_DZ
ar_EG
ar_IN
ar_IQ
ar_JO
ar_KW
ar_LB
ar_LY
ar_MA
ar_OM
ar_QA
ar_SA
ar_SD
ar_SS
ar_SY
ar_TN
ar_YE
as_IN
ast_ES
ayc_PE
az_AZ
az_IR
be_BY
bem_ZM
ber_DZ
ber_MA
bg_BG
bhb_IN
bho_IN
bho_NP
bi_VU
bn_BD
bn_IN
bo_CN
bo_IN
br_FR
brx_IN
bs_BA
byn_ER
ca_AD
ca_ES
ca_FR
ca_IT
ce_RU
ch_DE
chr_US
cmn_TW
crh_UA
cs_CZ
csb_PL
cv_RU
cy_GB
da_DK
de_AT
de_BE
de_CH
de_DE
de_IT
de_LI
de_LU
doi_IN
dsb_DE
dv_MV
dz_BT
el_CY
el_GR
en_AG
en_AU
en_BW
en_CA
en_DK
en_GB
en_HK
en_IE
en_IL
en_IN
en_NG
en_NZ
en_PH
en_SC
en_SG
en_US
en_ZA
en_ZM
en_ZW
eo
es_AR
es_BO
es_CL
es_CO
es_CR
es_CU
es_DO
es_EC
es_ES
es_GT
es_HN
es_MX
es_NI
es_PA
es_PE
es_PR
es_PY
es_SV
es_US
es_UY
es_VE
et_EE
eu_ES
fa_IR
ff_SN
fi_FI
fil_PH
fo_FO
fr_BE
fr_CA
fr_CH
fr_FR
fr_LU
fur_IT
fy_DE
fy_NL
ga_IE
gd_GB
gez_ER
gez_ET
gl_ES
gu_IN
gv_GB
ha_NG
hak_TW
he_IL
hi_IN
hif_FJ
hne_IN
hr_HR
hsb_DE
ht_HT
hu_HU
hy_AM
ia_FR
id_ID
ig_NG
ik_CA
is_IS
it_CH
it_IT
iu_CA
ja_JP
ka_GE
kab_DZ
kk_KZ
kl_GL
km_KH
kn_IN
ko_KR
kok_IN
ks_IN
ku_TR
kw_GB
ky_KG
lb_LU
lg_UG
li_BE
li_NL
lij_IT
ln_CD
lo_LA
lt_LT
lv_LV
lzh_TW
mag_IN
mai_IN
mai_NP
mfe_MU
mg_MG
mhr_RU
mi_NZ
miq_NI
mjw_IN
mk_MK
ml_IN
mn_MN
mni_IN
mnw_MM
mr_IN
ms_MY
mt_MT
my_MM
nan_TW
nb_NO
nds_DE
nds_NL
ne_NP
nhn_MX
niu_NU
niu_NZ
nl_AW
nl_BE
nl_NL
nn_NO
nr_ZA
nso_ZA
oc_FR
om_ET
om_KE
or_IN
os_RU
pa_IN
pa_PK
pap_AW
pap_CW
pl_PL
ps_AF
pt_BR
pt_PT
quz_PE
raj_IN
ro_RO
ru_RU
ru_UA
rw_RW
sa_IN
sah_RU
sat_IN
sc_IT
sd_IN
se_NO
sgs_LT
shn_MM
shs_CA
si_LK
sid_ET
sk_SK
sl_SI
sm_WS
so_DJ
so_ET
so_KE
so_SO
sq_AL
sq_MK
sr_ME
sr_RS
ss_ZA
st_ZA
sv_FI
sv_SE
sw_KE
sw_TZ
szl_PL
ta_IN
ta_LK
tcy_IN
te_IN
tg_TJ
th_TH
the_NP
ti_ER
ti_ET
tig_ER
tk_TM
tl_PH
tn_ZA
to_TO
tpi_PG
tr_CY
tr_TR
ts_ZA
tt_RU
ug_CN
uk_UA
unm_US
ur_IN
ur_PK
uz_UZ
ve_ZA
vi_VN
wa_BE
wae_CH
wal_ET
wo_SN
xh_ZA
yi_US
yo_NG
yue_HK
yuw_PG
zh_CN
zh_HK
zh_SG
zh_TW
zu_ZA

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb.export.frontend import frontend
from pmb.export.odin import odin

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
@ -12,58 +12,71 @@ import pmb.helpers.file
def odin(args, flavor, folder):
"""
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'
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'
"""
pmb.flasher.init(args)
suffix = "rootfs_" + args.device
# Backwards compatibility with old mkinitfs (pma#660)
suffix_flavor = f"-{flavor}"
pmaports_cfg = pmb.config.pmaports.read_config(args)
if pmaports_cfg.get("supported_mkinitfs_without_flavors", False):
suffix_flavor = ""
# Validate method
method = args.deviceinfo["flash_method"]
if not method.startswith("heimdall-"):
raise RuntimeError("An odin flashable tar is not supported for the flash"
" method '" + method + "' specified in the current configuration."
raise RuntimeError("An odin flashable tar is not supported"
f" for the flash method '{method}' specified"
" in the current configuration."
" Only 'heimdall' methods are supported.")
# Partitions
partition_kernel = args.deviceinfo["flash_heimdall_partition_kernel"] or "KERNEL"
partition_initfs = args.deviceinfo["flash_heimdall_partition_initfs"] or "RECOVERY"
partition_kernel = \
args.deviceinfo["flash_heimdall_partition_kernel"] or "KERNEL"
partition_initfs = \
args.deviceinfo["flash_heimdall_partition_initfs"] or "RECOVERY"
# Temporary folder
temp_folder = "/tmp/odin-flashable-tar"
if os.path.exists(args.work + "/chroot_native" + temp_folder):
if os.path.exists(f"{args.work}/chroot_native{temp_folder}"):
pmb.chroot.root(args, ["rm", "-rf", temp_folder])
# Odin flashable tar generation script (because redirecting stdin/stdout is not allowed
# Odin flashable tar generation script
# (because redirecting stdin/stdout is not allowed
# in pmbootstrap's chroot/shell functions for security reasons)
with open(args.work + "/chroot_rootfs_" + args.device + "/tmp/_odin.sh", "w") as handle:
odin_kernel_md5 = partition_kernel + ".bin.md5"
odin_initfs_md5 = partition_initfs + ".bin.md5"
odin_device_tar = args.device + ".tar"
odin_device_tar_md5 = args.device + ".tar.md5"
odin_script = f"{args.work}/chroot_rootfs_{args.device}/tmp/_odin.sh"
with open(odin_script, "w") as handle:
odin_kernel_md5 = f"{partition_kernel}.bin.md5"
odin_initfs_md5 = f"{partition_initfs}.bin.md5"
odin_device_tar = f"{args.device}.tar"
odin_device_tar_md5 = f"{args.device}.tar.md5"
handle.write(
"#!/bin/sh\n"
"cd " + temp_folder + "\n")
f"cd {temp_folder}\n")
if method == "heimdall-isorec":
handle.write(
# Kernel: copy and append md5
"cp /boot/vmlinuz-" + flavor + " " + odin_kernel_md5 + "\n"
"md5sum -t " + odin_kernel_md5 + " >> " + odin_kernel_md5 + "\n"
f"cp /boot/vmlinuz{suffix_flavor} {odin_kernel_md5}\n"
f"md5sum -t {odin_kernel_md5} >> {odin_kernel_md5}\n"
# Initramfs: recompress with lzop, append md5
"gunzip -c /boot/initramfs-" + flavor + " | lzop > " + odin_initfs_md5 + "\n"
"md5sum -t " + odin_initfs_md5 + " >> " + odin_initfs_md5 + "\n")
f"gunzip -c /boot/initramfs{suffix_flavor}"
f" | lzop > {odin_initfs_md5}\n"
f"md5sum -t {odin_initfs_md5} >> {odin_initfs_md5}\n")
elif method == "heimdall-bootimg":
handle.write(
# boot.img: copy and append md5
"cp /boot/boot.img-" + flavor + " " + odin_kernel_md5 + "\n"
"md5sum -t " + odin_kernel_md5 + " >> " + odin_kernel_md5 + "\n")
f"cp /boot/boot.img{suffix_flavor} {odin_kernel_md5}\n"
f"md5sum -t {odin_kernel_md5} >> {odin_kernel_md5}\n")
handle.write(
# Create tar, remove included files and append md5
"tar -c -f " + odin_device_tar + " *.bin.md5\n"
f"tar -c -f {odin_device_tar} *.bin.md5\n"
"rm *.bin.md5\n"
"md5sum -t " + odin_device_tar + " >> " + odin_device_tar + "\n"
"mv " + odin_device_tar + " " + odin_device_tar_md5 + "\n")
f"md5sum -t {odin_device_tar} >> {odin_device_tar}\n"
f"mv {odin_device_tar} {odin_device_tar_md5}\n")
commands = [["mkdir", "-p", temp_folder],
["cat", "/tmp/_odin.sh"], # for the log
@ -75,19 +88,19 @@ def odin(args, flavor, folder):
# Move Odin flashable tar to native chroot and cleanup temp folder
pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"])
pmb.chroot.root(args, ["mv", "/mnt/rootfs_" + args.device + temp_folder +
"/" + odin_device_tar_md5, "/home/pmos/rootfs/"]),
pmb.chroot.root(args, ["mv", f"/mnt/rootfs_{args.device}{temp_folder}"
f"/{odin_device_tar_md5}", "/home/pmos/rootfs/"]),
pmb.chroot.root(args, ["chown", "pmos:pmos",
"/home/pmos/rootfs/" + odin_device_tar_md5])
f"/home/pmos/rootfs/{odin_device_tar_md5}"])
pmb.chroot.root(args, ["rmdir", temp_folder], suffix)
# Create the symlink
file = args.work + "/chroot_native/home/pmos/rootfs/" + odin_device_tar_md5
link = folder + "/" + odin_device_tar_md5
file = f"{args.work}/chroot_native/home/pmos/rootfs/{odin_device_tar_md5}"
link = f"{folder}/{odin_device_tar_md5}"
pmb.helpers.file.symlink(args, file, link)
# Display a readable message
msg = " * " + odin_device_tar_md5
msg = f" * {odin_device_tar_md5}"
if method == "heimdall-isorec":
msg += " (Odin flashable file, contains initramfs and kernel)"
elif method == "heimdall-bootimg":

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
@ -7,6 +7,7 @@ import glob
import pmb.build
import pmb.chroot.apk
import pmb.config
import pmb.config.pmaports
import pmb.flasher
import pmb.helpers.file
@ -16,34 +17,45 @@ def symlinks(args, flavor, folder):
Create convenience symlinks to the rootfs and boot files.
"""
# Backwards compatibility with old mkinitfs (pma#660)
suffix = f"-{flavor}"
pmaports_cfg = pmb.config.pmaports.read_config(args)
if pmaports_cfg.get("supported_mkinitfs_without_flavors", False):
suffix = ""
# File descriptions
info = {
"boot.img-" + flavor: "Fastboot compatible boot.img file,"
" contains initramfs and kernel",
"blob-" + flavor: "Asus boot blob for TF101",
"initramfs-" + flavor: "Initramfs",
"initramfs-" + flavor + "-extra": "Extra initramfs files in /boot",
"uInitrd-" + flavor: "Initramfs, legacy u-boot image format",
"uImage-" + flavor: "Kernel, legacy u-boot image format",
"vmlinuz-" + flavor: "Linux kernel",
args.device + ".img": "Rootfs with partitions for /boot and /",
args.device + "-boot.img": "Boot partition image",
args.device + "-root.img": "Root partition image",
"pmos-" + args.device + ".zip": "Android recovery flashable zip",
f"boot.img{suffix}": ("Fastboot compatible boot.img file,"
" contains initramfs and kernel"),
"dtbo.img": "Fastboot compatible dtbo image",
f"initramfs{suffix}": "Initramfs",
f"initramfs{suffix}-extra": "Extra initramfs files in /boot",
f"uInitrd{suffix}": "Initramfs, legacy u-boot image format",
f"uImage{suffix}": "Kernel, legacy u-boot image format",
f"vmlinuz{suffix}": "Linux kernel",
f"{args.device}.img": "Rootfs with partitions for /boot and /",
f"{args.device}-boot.img": "Boot partition image",
f"{args.device}-root.img": "Root partition image",
f"pmos-{args.device}.zip": "Android recovery flashable zip",
"lk2nd.img": "Secondary Android bootloader",
}
# 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_boot + "/*-" + flavor + "-extra",
path_native + "/home/pmos/rootfs/" + args.device + ".img",
path_native + "/home/pmos/rootfs/" + args.device + "-boot.img",
path_native + "/home/pmos/rootfs/" + args.device + "-root.img",
path_buildroot +
"/var/lib/postmarketos-android-recovery-installer/pmos-" +
args.device + ".zip"]
patterns = [f"{path_boot}/boot.img{suffix}",
f"{path_boot}/initramfs{suffix}*",
f"{path_boot}/uInitrd{suffix}",
f"{path_boot}/uImage{suffix}",
f"{path_boot}/vmlinuz{suffix}",
f"{path_boot}/dtbo.img",
f"{path_native}/home/pmos/rootfs/{args.device}.img",
f"{path_native}/home/pmos/rootfs/{args.device}-boot.img",
f"{path_native}/home/pmos/rootfs/{args.device}-root.img",
f"{path_buildroot}/var/lib/postmarketos-android-recovery-" +
f"installer/pmos-{args.device}.zip",
f"{path_boot}/lk2nd.img"]
# Generate a list of files from the patterns
files = []

View File

@ -1,6 +1,7 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb.flasher.init import init
from pmb.flasher.init import install_depends
from pmb.flasher.run import run
from pmb.flasher.run import check_partition_blacklist
from pmb.flasher.variables import variables

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
@ -20,7 +20,7 @@ def kernel(args):
pmb.chroot.initfs.build(args, flavor, "rootfs_" + args.device)
# Check kernel config
pmb.parse.kconfig.check(args, flavor)
pmb.parse.kconfig.check(args, flavor, must_exist=False)
# Generate the paths and run the flasher
if args.action_flasher == "boot":
@ -31,17 +31,18 @@ def kernel(args):
pmb.flasher.run(args, "flash_kernel", flavor)
logging.info("You will get an IP automatically assigned to your "
"USB interface shortly.")
logging.info("Then you can connect to your device using ssh after pmOS has booted:")
logging.info("Then you can connect to your device using ssh after pmOS has"
" booted:")
logging.info("ssh {}@{}".format(args.user, pmb.config.default_ip))
logging.info("NOTE: If you enabled full disk encryption, you should make sure that"
" osk-sdl has been properly configured for your device")
logging.info("NOTE: If you enabled full disk encryption, you should make"
" sure that osk-sdl has been properly configured for your"
" device")
def list_flavors(args):
suffix = "rootfs_" + args.device
logging.info("(" + suffix + ") installed kernel flavors:")
for flavor in pmb.chroot.other.kernel_flavors_installed(args, suffix):
logging.info("* " + flavor)
logging.info("* " + pmb.chroot.other.kernel_flavor_installed(args, suffix))
def rootfs(args):
@ -52,13 +53,15 @@ def rootfs(args):
if pmb.config.flashers.get(method, {}).get("split", False):
suffix = "-root.img"
img_path = args.work + "/chroot_native/home/pmos/rootfs/" + args.device + suffix
img_path = f"{args.work}/chroot_native/home/pmos/rootfs/{args.device}"\
f"{suffix}"
if not os.path.exists(img_path):
raise RuntimeError("The rootfs has not been generated yet, please run"
" 'pmbootstrap install' first.")
# Do not flash if using fastboot & image is too large
if method.startswith("fastboot") and args.deviceinfo["flash_fastboot_max_size"]:
if method.startswith("fastboot") \
and args.deviceinfo["flash_fastboot_max_size"]:
img_size = os.path.getsize(img_path) / 1024**2
max_size = int(args.deviceinfo["flash_fastboot_max_size"])
if img_size > max_size:
@ -75,16 +78,18 @@ def flash_vbmeta(args):
pmb.flasher.run(args, "flash_vbmeta")
def flash_dtbo(args):
logging.info("(native) flash dtbo image")
pmb.flasher.run(args, "flash_dtbo")
def list_devices(args):
pmb.flasher.run(args, "list_devices")
def sideload(args):
method = args.flash_method or args.deviceinfo["flash_method"]
cfg = pmb.config.flashers[method]
# Install depends
pmb.chroot.apk.install(args, cfg["depends"])
pmb.flasher.install_depends(args)
# Mount the buildroot
suffix = "buildroot_" + args.deviceinfo["arch"]
@ -104,27 +109,63 @@ def sideload(args):
pmb.flasher.run(args, "sideload")
def flash_lk2nd(args):
method = args.flash_method or args.deviceinfo["flash_method"]
if method == "fastboot":
# In the future this could be expanded to use "fastboot flash lk2nd $img"
# which reflashes/updates lk2nd from itself. For now let the user handle this
# manually since supporting the codepath with heimdall requires more effort.
pmb.flasher.init(args)
logging.info("(native) checking current fastboot product")
output = pmb.chroot.root(args, ["fastboot", "getvar", "product"],
output="interactive", output_return=True)
# Variable "product" is e.g. "LK2ND_MSM8974" or "lk2nd-msm8226" depending
# on the lk2nd version.
if "lk2nd" in output.lower():
raise RuntimeError("You are currently running lk2nd. Please reboot into the regular"
" bootloader mode to re-flash lk2nd.")
# Get the lk2nd package (which is a dependency of the device package)
device_pkg = f"device-{args.device}"
apkbuild = pmb.helpers.pmaports.get(args, device_pkg)
lk2nd_pkg = None
for dep in apkbuild["depends"]:
if dep.startswith("lk2nd"):
lk2nd_pkg = dep
break
if not lk2nd_pkg:
raise RuntimeError(f"{device_pkg} does not depend on any lk2nd package")
suffix = "rootfs_" + args.device
pmb.chroot.apk.install(args, [lk2nd_pkg], suffix)
logging.info("(native) flash lk2nd image")
pmb.flasher.run(args, "flash_lk2nd")
def frontend(args):
action = args.action_flasher
method = args.flash_method or args.deviceinfo["flash_method"]
# Legacy alias
if action == "flash_system":
action = "flash_rootfs"
if method == "none" and action in ["boot", "flash_kernel", "flash_rootfs"]:
if method == "none" and action in ["boot", "flash_kernel", "flash_rootfs",
"flash_lk2nd"]:
logging.info("This device doesn't support any flash method.")
return
if action in ["boot", "flash_kernel"]:
kernel(args)
if action == "flash_rootfs":
elif action == "flash_rootfs":
rootfs(args)
if action == "flash_vbmeta":
elif action == "flash_vbmeta":
flash_vbmeta(args)
if action == "list_flavors":
elif action == "flash_dtbo":
flash_dtbo(args)
elif action == "flash_lk2nd":
flash_lk2nd(args)
elif action == "list_flavors":
list_flavors(args)
if action == "list_devices":
elif action == "list_devices":
list_devices(args)
if action == "sideload":
elif action == "sideload":
sideload(args)

View File

@ -1,27 +1,47 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.config
import pmb.chroot.apk
import pmb.config
import pmb.config.pmaports
import pmb.helpers.mount
def init(args):
# Validate method
def install_depends(args):
if hasattr(args, 'flash_method'):
method = args.flash_method or args.deviceinfo["flash_method"]
else:
method = args.deviceinfo["flash_method"]
if method not in pmb.config.flashers:
raise RuntimeError("Flash method " + method + " is not supported by the"
" current configuration. However, adding a new flash method is "
" not that hard, when the flashing application already exists.\n"
"Make sure, it is packaged for Alpine Linux, or package it "
" yourself, and then add it to pmb/config/__init__.py.")
cfg = pmb.config.flashers[method]
raise RuntimeError(f"Flash method {method} is not supported by the"
" current configuration. However, adding a new"
" flash method is not that hard, when the flashing"
" application already exists.\n"
"Make sure, it is packaged for Alpine Linux, or"
" package it yourself, and then add it to"
" pmb/config/__init__.py.")
depends = pmb.config.flashers[method]["depends"]
# Install depends
pmb.chroot.apk.install(args, cfg["depends"])
# Depends for some flash methods may be different for various pmaports
# branches, so read them from pmaports.cfg.
if method == "fastboot":
pmaports_cfg = pmb.config.pmaports.read_config(args)
depends = pmaports_cfg.get("supported_fastboot_depends",
"android-tools,avbtool").split(",")
elif method == "heimdall-bootimg":
pmaports_cfg = pmb.config.pmaports.read_config(args)
depends = pmaports_cfg.get("supported_heimdall_depends",
"heimdall,avbtool").split(",")
elif method == "mtkclient":
pmaports_cfg = pmb.config.pmaports.read_config(args)
depends = pmaports_cfg.get("supported_mtkclient_depends",
"mtkclient,android-tools").split(",")
pmb.chroot.apk.install(args, depends)
def init(args):
install_depends(args)
# Mount folders from host system
for folder in pmb.config.flash_mount_bind:

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.flasher
import pmb.chroot.initfs
@ -42,17 +42,27 @@ def run(args, action, flavor=None):
" <https://wiki.postmarketos.org/wiki/"
"Deviceinfo_reference>")
# dtbo flasher requires dtbo partition to be explicitly specified
if action == "flash_dtbo" and not vars["$PARTITION_DTBO"]:
raise RuntimeError("Your device does not have 'dtbo' partition"
" specified; set"
" 'deviceinfo_flash_fastboot_partition_dtbo'"
" in deviceinfo file. See also:"
" <https://wiki.postmarketos.org/wiki/"
"Deviceinfo_reference>")
# Run the commands of each action
for command in cfg["actions"][action]:
# Variable replacement
for key, value in vars.items():
for i in range(len(command)):
if key in command[i]:
if not value and key != "$KERNEL_CMDLINE":
raise RuntimeError("Variable " + key + " found in"
" action " + action + " for method " + method + ","
" but the value for this variable is None! Is that"
" missing in your deviceinfo?")
if value is None:
raise RuntimeError(f"Variable {key} found in action"
f" {action} for method {method},"
" but the value for this variable"
" is None! Is that missing in your"
" deviceinfo?")
check_partition_blacklist(args, key, value)
command[i] = command[i].replace(key, value)

View File

@ -1,40 +1,80 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.config.pmaports
def variables(args, flavor, method):
_cmdline = args.deviceinfo["kernel_cmdline"]
_cmdline = args.deviceinfo["kernel_cmdline"] or ""
if "cmdline" in args and args.cmdline:
_cmdline = args.cmdline
flash_pagesize = args.deviceinfo['flash_pagesize']
# TODO Remove _partition_system deviceinfo support once pmaports has been
# updated and minimum pmbootstrap version bumped.
# See also https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2243
if method.startswith("fastboot"):
_partition_kernel = args.deviceinfo["flash_fastboot_partition_kernel"] or "boot"
_partition_system = args.deviceinfo["flash_fastboot_partition_system"] or "system"
_partition_vbmeta = args.deviceinfo["flash_fastboot_partition_vbmeta"] or None
_partition_kernel = args.deviceinfo["flash_fastboot_partition_kernel"]\
or "boot"
_partition_rootfs = args.deviceinfo["flash_fastboot_partition_rootfs"]\
or args.deviceinfo["flash_fastboot_partition_system"] or "userdata"
_partition_vbmeta = args.deviceinfo["flash_fastboot_partition_vbmeta"]\
or None
_partition_dtbo = args.deviceinfo["flash_fastboot_partition_dtbo"]\
or None
# Require that the partitions are specified in deviceinfo for now
elif method.startswith("rkdeveloptool"):
_partition_kernel = args.deviceinfo["flash_rk_partition_kernel"]\
or None
_partition_rootfs = args.deviceinfo["flash_rk_partition_rootfs"]\
or args.deviceinfo["flash_rk_partition_system"] or None
_partition_vbmeta = None
_partition_dtbo = None
elif method.startswith("mtkclient"):
_partition_kernel = args.deviceinfo["flash_mtkclient_partition_kernel"]\
or "boot"
_partition_rootfs = args.deviceinfo["flash_mtkclient_partition_rootfs"]\
or "userdata"
_partition_vbmeta = args.deviceinfo["flash_mtkclient_partition_vbmeta"]\
or None
_partition_dtbo = args.deviceinfo["flash_mtkclient_partition_dtbo"]\
or None
else:
_partition_kernel = args.deviceinfo["flash_heimdall_partition_kernel"] or "KERNEL"
_partition_system = args.deviceinfo["flash_heimdall_partition_system"] or "SYSTEM"
_partition_vbmeta = args.deviceinfo["flash_heimdall_partition_vbmeta"] or None
_partition_kernel = args.deviceinfo["flash_heimdall_partition_kernel"]\
or "KERNEL"
_partition_rootfs = args.deviceinfo["flash_heimdall_partition_rootfs"]\
or args.deviceinfo["flash_heimdall_partition_system"] or "SYSTEM"
_partition_vbmeta = args.deviceinfo["flash_heimdall_partition_vbmeta"]\
or None
_partition_dtbo = args.deviceinfo["flash_heimdall_partition_dtbo"]\
or None
if "partition" in args and args.partition:
# Only one of operations is done at same time so it doesn't matter sharing the arg
# Only one operation is done at same time so it doesn't matter
# sharing the arg
_partition_kernel = args.partition
_partition_system = args.partition
_partition_rootfs = args.partition
_partition_vbmeta = args.partition
_partition_dtbo = args.partition
_dtb = ""
if args.deviceinfo["append_dtb"] == "true":
_dtb = "-dtb"
vars = {
"$BOOT": "/mnt/rootfs_" + args.device + "/boot",
"$FLAVOR": flavor if flavor is not None else "",
"$DTB": _dtb,
"$IMAGE_SPLIT_BOOT": "/home/pmos/rootfs/" + args.device + "-boot.img",
"$IMAGE_SPLIT_ROOT": "/home/pmos/rootfs/" + args.device + "-root.img",
"$IMAGE": "/home/pmos/rootfs/" + args.device + ".img",
"$KERNEL_CMDLINE": _cmdline,
"$PARTITION_KERNEL": _partition_kernel,
"$PARTITION_INITFS": args.deviceinfo["flash_heimdall_partition_initfs"] or "RECOVERY",
"$PARTITION_SYSTEM": _partition_system,
"$PARTITION_INITFS": args.deviceinfo[
"flash_heimdall_partition_initfs"] or "RECOVERY",
"$PARTITION_ROOTFS": _partition_rootfs,
"$PARTITION_VBMETA": _partition_vbmeta,
"$PARTITION_DTBO": _partition_dtbo,
"$FLASH_PAGESIZE": flash_pagesize,
"$RECOVERY_ZIP": "/mnt/buildroot_" + args.deviceinfo["arch"] +
"/var/lib/postmarketos-android-recovery-installer"
@ -43,4 +83,11 @@ def variables(args, flavor, method):
"/usr/share/uuu/flash_script.lst"
}
# Backwards compatibility with old mkinitfs (pma#660)
pmaports_cfg = pmb.config.pmaports.read_config(args)
if pmaports_cfg.get("supported_mkinitfs_without_flavors", False):
vars["$FLAVOR"] = ""
else:
vars["$FLAVOR"] = f"-{flavor}" if flavor is not None else "-"
return vars

View File

@ -1,2 +1,2 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later

134
pmb/helpers/apk.py Normal file
View File

@ -0,0 +1,134 @@
# Copyright 2023 Johannes Marbach, Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import pmb.chroot.root
import pmb.config.pmaports
import pmb.helpers.cli
import pmb.helpers.run
import pmb.helpers.run_core
import pmb.parse.version
def _run(args, command, chroot=False, suffix="native", output="log"):
"""
Run a command.
:param command: command in list form
:param chroot: whether to run the command inside the chroot or on the host
:param suffix: chroot suffix. Only applies if the "chroot" parameter is
set to True.
See pmb.helpers.run_core.core() for a detailed description of all other
arguments and the return value.
"""
if chroot:
return pmb.chroot.root(args, command, output=output, suffix=suffix,
disable_timeout=True)
return pmb.helpers.run.root(args, command, output=output)
def _prepare_fifo(args, chroot=False, suffix="native"):
"""
Prepare the progress fifo for reading / writing.
:param chroot: whether to run the command inside the chroot or on the host
:param suffix: chroot suffix. Only applies if the "chroot" parameter is
set to True.
:returns: A tuple consisting of the path to the fifo as needed by apk to
write into it (relative to the chroot, if applicable) and the
path of the fifo as needed by cat to read from it (always
relative to the host)
"""
if chroot:
fifo = "/tmp/apk_progress_fifo"
fifo_outside = f"{args.work}/chroot_{suffix}{fifo}"
else:
_run(args, ["mkdir", "-p", f"{args.work}/tmp"])
fifo = fifo_outside = f"{args.work}/tmp/apk_progress_fifo"
if os.path.exists(fifo_outside):
_run(args, ["rm", "-f", fifo_outside])
_run(args, ["mkfifo", fifo_outside])
return (fifo, fifo_outside)
def _create_command_with_progress(command, fifo):
"""
Build a full apk command from a subcommand, set up to redirect progress
into a fifo.
:param command: apk subcommand in list form
:param fifo: path of the fifo
:returns: full command in list form
"""
flags = ["--no-progress", "--progress-fd", "3"]
command_full = [command[0]] + flags + command[1:]
command_flat = pmb.helpers.run_core.flat_cmd(command_full)
command_flat = f"exec 3>{fifo}; {command_flat}"
return ["sh", "-c", command_flat]
def _compute_progress(line):
"""
Compute the progress as a number between 0 and 1.
:param line: line as read from the progress fifo
:returns: progress as a number between 0 and 1
"""
if not line:
return 1
cur_tot = line.rstrip().split('/')
if len(cur_tot) != 2:
return 0
cur = float(cur_tot[0])
tot = float(cur_tot[1])
return cur / tot if tot > 0 else 0
def apk_with_progress(args, command, chroot=False, suffix="native"):
"""
Run an apk subcommand while printing a progress bar to STDOUT.
:param command: apk subcommand in list form
:param chroot: whether to run commands inside the chroot or on the host
:param suffix: chroot suffix. Only applies if the "chroot" parameter is
set to True.
:raises RuntimeError: when the apk command fails
"""
fifo, fifo_outside = _prepare_fifo(args, chroot, suffix)
command_with_progress = _create_command_with_progress(command, fifo)
log_msg = " ".join(command)
with _run(args, ['cat', fifo], chroot=chroot, suffix=suffix,
output="pipe") as p_cat:
with _run(args, command_with_progress, chroot=chroot, suffix=suffix,
output="background") as p_apk:
while p_apk.poll() is None:
line = p_cat.stdout.readline().decode('utf-8')
progress = _compute_progress(line)
pmb.helpers.cli.progress_print(args, progress)
pmb.helpers.cli.progress_flush(args)
pmb.helpers.run_core.check_return_code(args, p_apk.returncode,
log_msg)
def check_outdated(args, version_installed, action_msg):
"""
Check if the provided alpine version is outdated, depending on the alpine
mirrordir (edge, v3.12, ...) related to currently checked out pmaports
branch.
:param version_installed: currently installed apk version, e.g. "2.12.1-r0"
:param action_msg: string explaining what the user should do to resolve
this
:raises: RuntimeError if the version is outdated
"""
channel_cfg = pmb.config.pmaports.read_config_channel(args)
mirrordir_alpine = channel_cfg["mirrordir_alpine"]
version_min = pmb.config.apk_tools_min_version[mirrordir_alpine]
if pmb.parse.version.compare(version_installed, version_min) >= 0:
return
raise RuntimeError("Found an outdated version of the 'apk' package"
f" manager ({version_installed}, expected at least:"
f" {version_min}). {action_msg}")

View File

@ -1,4 +1,4 @@
# Copyright 2020 Luca Weiss
# Copyright 2023 Luca Weiss
# SPDX-License-Identifier: GPL-3.0-or-later
import datetime
import fnmatch
@ -6,6 +6,7 @@ import logging
import os
import re
import urllib
from typing import Optional
import pmb.helpers.file
import pmb.helpers.http
@ -18,9 +19,10 @@ ANITYA_API_BASE = "https://release-monitoring.org/api/v2"
GITHUB_API_BASE = "https://api.github.com"
GITLAB_HOSTS = [
"https://gitlab.com",
"https://gitlab.freedesktop.org",
"https://gitlab.gnome.org",
"https://invent.kde.org",
"https://source.puri.sm",
"https://gitlab.freedesktop.org",
]
@ -31,43 +33,31 @@ def init_req_headers() -> None:
if req_headers is not None and req_headers_github is not None:
return
# Generic request headers
req_headers = {'User-Agent': 'pmbootstrap/{} aportupgrade'.format(pmb.config.version)}
req_headers = {
'User-Agent': f'pmbootstrap/{pmb.__version__} aportupgrade'}
# Request headers specific to GitHub
req_headers_github = dict(req_headers)
if os.getenv("GITHUB_TOKEN") is not None:
req_headers_github['Authorization'] = 'token ' + os.getenv("GITHUB_TOKEN")
token = os.getenv("GITHUB_TOKEN")
req_headers_github['Authorization'] = f'token {token}'
else:
logging.info("NOTE: Consider using a GITHUB_TOKEN environment variable to increase your rate limit")
logging.info("NOTE: Consider using a GITHUB_TOKEN environment variable"
" to increase your rate limit")
def get_github_branch_arg(repo: str) -> str:
"""
Get the branch to query for the latest commit
:param repo: the repository name
:returns: e.g. "?sha=bionic" or ""
"""
if "ubports" not in repo:
return ""
# Get a list of branches to see if a 'bionic' branch exists
branches = pmb.helpers.http.retrieve_json(GITHUB_API_BASE + "/repos/" + repo + "/branches",
headers=req_headers_github)
for branch_o in branches:
if branch_o["name"] == "bionic":
return "?sha=bionic"
# Return no branch if 'bionic' does not exist
return ""
def get_package_version_info_github(repo_name: str):
def get_package_version_info_github(repo_name: str, ref: Optional[str]):
logging.debug("Trying GitHub repository: {}".format(repo_name))
# Special case for ubports Unity 8 repos, we want to use the 'bionic' branch (where available)
branch = get_github_branch_arg(repo_name)
# Get the URL argument to request a special ref, if needed
ref_arg = ""
if ref is not None:
ref_arg = f"?sha={ref}"
# Get the commits for the repository
commits = pmb.helpers.http.retrieve_json(GITHUB_API_BASE + "/repos/" + repo_name + "/commits" + branch,
headers=req_headers_github)
commits = pmb.helpers.http.retrieve_json(
f"{GITHUB_API_BASE}/repos/{repo_name}/commits{ref_arg}",
headers=req_headers_github)
latest_commit = commits[0]
commit_date = latest_commit["commit"]["committer"]["date"]
# Extract the time from the field
@ -78,12 +68,21 @@ def get_package_version_info_github(repo_name: str):
}
def get_package_version_info_gitlab(gitlab_host: str, repo_name: str):
def get_package_version_info_gitlab(gitlab_host: str, repo_name: str,
ref: Optional[str]):
logging.debug("Trying GitLab repository: {}".format(repo_name))
repo_name_safe = urllib.parse.quote(repo_name, safe='')
# Get the URL argument to request a special ref, if needed
ref_arg = ""
if ref is not None:
ref_arg = f"?ref_name={ref}"
# Get the commits for the repository
commits = pmb.helpers.http.retrieve_json(
gitlab_host + "/api/v4/projects/" + urllib.parse.quote(repo_name, safe='') + "/repository/commits",
f"{gitlab_host}/api/v4/projects/{repo_name_safe}/repository"
f"/commits{ref_arg}",
headers=req_headers)
latest_commit = commits[0]
commit_date = latest_commit["committed_date"]
@ -98,7 +97,8 @@ def get_package_version_info_gitlab(gitlab_host: str, repo_name: str):
def upgrade_git_package(args, pkgname: str, package) -> bool:
"""
Update _commit/pkgver/pkgrel in a git-APKBUILD (or pretend to do it if args.dry is set).
Update _commit/pkgver/pkgrel in a git-APKBUILD (or pretend to do it if
args.dry is set).
:param pkgname: the package name
:param package: a dict containing package information
:returns: if something (would have) been changed
@ -109,16 +109,21 @@ def upgrade_git_package(args, pkgname: str, package) -> bool:
if 1 <= len(source) <= 2:
source = source[-1]
else:
raise RuntimeError("Unhandled number of source elements. Please open a bug report: {}".format(source))
raise RuntimeError("Unhandled number of source elements. Please open"
f" a bug report: {source}")
verinfo = None
github_match = re.match(r"https://github\.com/(.+)/(?:archive|releases)", source)
gitlab_match = re.match(r"(" + '|'.join(GITLAB_HOSTS) + ")/(.+)/-/archive/", source)
github_match = re.match(
r"https://github\.com/(.+)/(?:archive|releases)", source)
gitlab_match = re.match(
fr"({'|'.join(GITLAB_HOSTS)})/(.+)/-/archive/", source)
if github_match:
verinfo = get_package_version_info_github(github_match.group(1))
verinfo = get_package_version_info_github(
github_match.group(1), args.ref)
elif gitlab_match:
verinfo = get_package_version_info_gitlab(gitlab_match.group(1), gitlab_match.group(2))
verinfo = get_package_version_info_gitlab(
gitlab_match.group(1), gitlab_match.group(2), args.ref)
if verinfo is None:
# ignore for now
@ -130,10 +135,14 @@ def upgrade_git_package(args, pkgname: str, package) -> bool:
sha_new = verinfo["sha"]
# Format the new pkgver, keep the value before _git the same
pkgver = package["pkgver"]
if package["pkgver"] == "9999":
pkgver = package["_pkgver"]
else:
pkgver = package["pkgver"]
pkgver_match = re.match(r"([\d.]+)_git", pkgver)
date_pkgver = verinfo["date"].strftime("%Y%m%d")
pkgver_new = pkgver_match.group(1) + "_git" + date_pkgver
pkgver_new = f"{pkgver_match.group(1)}_git{date_pkgver}"
# pkgrel will be zero
pkgrel = int(package["pkgrel"])
@ -145,12 +154,15 @@ def upgrade_git_package(args, pkgname: str, package) -> bool:
logging.info("{}: upgrading pmaport".format(pkgname))
if args.dry:
logging.info(" Would change _commit from {} to {}".format(sha, sha_new))
logging.info(" Would change pkgver from {} to {}".format(pkgver, pkgver_new))
logging.info(" Would change pkgrel from {} to {}".format(pkgrel, pkgrel_new))
logging.info(f" Would change _commit from {sha} to {sha_new}")
logging.info(f" Would change pkgver from {pkgver} to {pkgver_new}")
logging.info(f" Would change pkgrel from {pkgrel} to {pkgrel_new}")
return True
pmb.helpers.file.replace_apkbuild(args, pkgname, "pkgver", pkgver_new)
if package["pkgver"] == "9999":
pmb.helpers.file.replace_apkbuild(args, pkgname, "_pkgver", pkgver_new)
else:
pmb.helpers.file.replace_apkbuild(args, pkgname, "pkgver", pkgver_new)
pmb.helpers.file.replace_apkbuild(args, pkgname, "pkgrel", pkgrel_new)
pmb.helpers.file.replace_apkbuild(args, pkgname, "_commit", sha_new, True)
return True
@ -158,55 +170,83 @@ def upgrade_git_package(args, pkgname: str, package) -> bool:
def upgrade_stable_package(args, pkgname: str, package) -> bool:
"""
Update _commit/pkgver/pkgrel in an APKBUILD (or pretend to do it if args.dry is set).
Update _commit/pkgver/pkgrel in an APKBUILD (or pretend to do it if
args.dry is set).
:param pkgname: the package name
:param package: a dict containing package information
:returns: if something (would have) been changed
"""
projects = pmb.helpers.http.retrieve_json(ANITYA_API_BASE + "/projects/?name=" + pkgname, headers=req_headers)
if projects["total_items"] < 1:
# There is no Anitya project with the package name.
# Looking up if there's a custom mapping from postmarketOS package name to Anitya project name.
mappings = pmb.helpers.http.retrieve_json(
ANITYA_API_BASE + "/packages/?distribution=postmarketOS&name=" + pkgname, headers=req_headers)
if mappings["total_items"] < 1:
logging.warning("{}: failed to get Anitya project".format(pkgname))
return False
project_name = mappings["items"][0]["project"]
# Looking up if there's a custom mapping from postmarketOS package name
# to Anitya project name.
mappings = pmb.helpers.http.retrieve_json(
f"{ANITYA_API_BASE}/packages/?distribution=postmarketOS"
f"&name={pkgname}", headers=req_headers)
if mappings["total_items"] < 1:
projects = pmb.helpers.http.retrieve_json(
ANITYA_API_BASE + "/projects/?name=" + project_name, headers=req_headers)
f"{ANITYA_API_BASE}/projects/?name={pkgname}", headers=req_headers)
if projects["total_items"] < 1:
logging.warning(f"{pkgname}: failed to get Anitya project")
return False
else:
project_name = mappings["items"][0]["project"]
ecosystem = mappings["items"][0]["ecosystem"]
projects = pmb.helpers.http.retrieve_json(
f"{ANITYA_API_BASE}/projects/?name={project_name}&"
f"ecosystem={ecosystem}",
headers=req_headers)
if projects["total_items"] < 1:
logging.warning(f"{pkgname}: didn't find any projects, can't upgrade!")
return False
if projects["total_items"] > 1:
logging.warning(f"{pkgname}: found more than one project, can't "
f"upgrade! Please create an explicit mapping of "
f"\"project\" to the package name.")
return False
# Get the first, best-matching item
project = projects["items"][0]
# Check that we got a version number
if project["version"] is None:
if len(project["stable_versions"]) < 1:
logging.warning("{}: got no version number, ignoring".format(pkgname))
return False
version = project["stable_versions"][0]
# Compare the pmaports version with the project version
if package["pkgver"] == project["version"]:
if package["pkgver"] == version:
logging.info("{}: up-to-date".format(pkgname))
return False
pkgver = package["pkgver"]
pkgver_new = project["version"]
if package["pkgver"] == "9999":
pkgver = package["_pkgver"]
else:
pkgver = package["pkgver"]
pkgver_new = version
pkgrel = package["pkgrel"]
pkgrel_new = 0
if not pmb.parse.version.validate(pkgver_new):
logging.warning("{}: would upgrade to invalid pkgver: {}, ignoring".format(pkgname, pkgver_new))
logging.warning(f"{pkgname}: would upgrade to invalid pkgver:"
f" {pkgver_new}, ignoring")
return False
logging.info("{}: upgrading pmaport".format(pkgname))
if args.dry:
logging.info(" Would change pkgver from {} to {}".format(pkgver, pkgver_new))
logging.info(" Would change pkgrel from {} to {}".format(pkgrel, pkgrel_new))
logging.info(f" Would change pkgver from {pkgver} to {pkgver_new}")
logging.info(f" Would change pkgrel from {pkgrel} to {pkgrel_new}")
return True
pmb.helpers.file.replace_apkbuild(args, pkgname, "pkgver", pkgver_new)
if package["pkgver"] == "9999":
pmb.helpers.file.replace_apkbuild(args, pkgname, "_pkgver", pkgver_new)
else:
pmb.helpers.file.replace_apkbuild(args, pkgname, "pkgver", pkgver_new)
pmb.helpers.file.replace_apkbuild(args, pkgname, "pkgrel", pkgrel_new)
return True
@ -238,7 +278,8 @@ def upgrade_all(args) -> None:
Upgrade all packages, based on args.all, args.all_git and args.all_stable.
"""
for pkgname in pmb.helpers.pmaports.get_list(args):
# Always ignore postmarketOS-specific packages that have no upstream source
# Always ignore postmarketOS-specific packages that have no upstream
# source
skip = False
for pattern in pmb.config.upgrade_ignore:
if fnmatch.fnmatch(pkgname, pattern):
@ -246,4 +287,5 @@ def upgrade_all(args) -> None:
if skip:
continue
upgrade(args, pkgname, args.all or args.all_git, args.all or args.all_stable)
upgrade(args, pkgname, args.all or args.all_git,
args.all or args.all_stable)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import copy
import os
@ -20,7 +20,7 @@ import pmb.helpers.git
...
2. Argparse merged with others
Variables from the user's config file (~/.config/pmbootstrap.cfg), that
Variables from the user's config file (~/.config/pmbootstrap.cfg) that
can be overridden from the command line (pmb/parse/arguments.py) and
fall back to the defaults defined in pmb/config/__init__.py (see
"defaults = {..."). The user's config file gets generated interactively
@ -31,30 +31,7 @@ import pmb.helpers.git
args.device ("samsung-i9100", "qemu-amd64" etc.)
args.work ("/home/user/.local/var/pmbootstrap", override with --work)
3. Shortcuts
Long variables or function calls that always return the same information
may have a shortcut defined, to make the code more readable (see
add_shortcuts() below).
Example:
args.arch_native ("x86_64" etc.)
4. Cache
pmbootstrap uses this dictionary to save the result of expensive
results, so they work a lot faster the next time they are needed in the
same session. Usually the cache is written to and read from in the same
Python file, with code similar to the following:
def lookup(args, key):
if key in args.cache["mycache"]:
return args.cache["mycache"][key]
ret = expensive_operation(args, key)
args.cache["mycache"][key] = ret
return ret
See add_cache() below for details.
5. Parsed configs
3. Parsed configs
Similar to the cache above, specific config files get parsed and added
to args, so they can get accessed quickly (without parsing the configs
over and over). These configs are not only used in one specific
@ -79,7 +56,9 @@ def fix_mirrors_postmarketos(args):
subparsers: <https://bugs.python.org/issue9338> """
# -mp not specified: use default mirrors
if not args.mirrors_postmarketos:
args.mirrors_postmarketos = pmb.config.defaults["mirrors_postmarketos"]
cfg = pmb.config.load(args)
args.mirrors_postmarketos = \
cfg["pmbootstrap"]["mirrors_postmarketos"].split(",")
# -mp="": use no postmarketOS mirrors (build everything locally)
if args.mirrors_postmarketos == [""]:
@ -114,33 +93,11 @@ def replace_placeholders(args):
setattr(args, key, os.path.expanduser(getattr(args, key)))
def add_shortcuts(args):
""" Add convenience shortcuts """
setattr(args, "arch_native", pmb.parse.arch.alpine_native())
def add_cache(args):
""" Add a caching dict (caches parsing of files etc. for the current
session) """
repo_update = {"404": [], "offline_msg_shown": False}
setattr(args, "cache", {"apkindex": {},
"apkbuild": {},
"apk_min_version_checked": [],
"apk_repository_list_updated": [],
"built": {},
"find_aport": {},
"pmb.helpers.package.depends_recurse": {},
"pmb.helpers.package.get": {},
"pmb.helpers.repo.update": repo_update,
"pmb.helpers.git.parse_channels_cfg": {},
"pmb.config.pmaports.read_config": None})
def add_deviceinfo(args):
""" Add and verify the deviceinfo (only after initialization) """
setattr(args, "deviceinfo", pmb.parse.deviceinfo(args))
arch = args.deviceinfo["arch"]
if (arch != args.arch_native and
if (arch != pmb.config.arch_native and
arch not in pmb.config.build_device_architectures):
raise ValueError("Arch '" + arch + "' is not available in"
" postmarketOS. If you would like to add it, see:"
@ -152,8 +109,7 @@ def init(args):
fix_mirrors_postmarketos(args)
pmb.config.merge_with_args(args)
replace_placeholders(args)
add_shortcuts(args)
add_cache(args)
pmb.helpers.other.init_cache()
# Initialize logs (we could raise errors below)
pmb.helpers.logging.init(args)
@ -175,9 +131,7 @@ def update_work(args, work):
args_new = copy.deepcopy(args.from_argparse)
# Keep from the modified args:
# * the old log file descriptor (so we can close it)
# * the unmodified args from argparse (to check if --aports was specified)
args_new.logfd = args.logfd
args_new.from_argparse = args.from_argparse
# Generate modified args again, replacing $WORK with the new work folder

View File

@ -1,9 +1,13 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import datetime
import logging
import os
import re
import readline
import sys
import pmb.config
class ReadlineTabCompleter:
@ -23,7 +27,8 @@ class ReadlineTabCompleter:
# First time: build match list
if iteration == 0:
if input_text:
self.matches = [s for s in self.options if s and s.startswith(input_text)]
self.matches = [s for s in self.options
if s and s.startswith(input_text)]
else:
self.matches = self.options[:]
@ -33,42 +38,53 @@ class ReadlineTabCompleter:
return None
def ask(args, question="Continue?", choices=["y", "n"], default="n",
def ask(question="Continue?", choices=["y", "n"], default="n",
lowercase_answer=True, validation_regex=None, complete=None):
"""
Ask a question on the terminal.
:param question: display prompt
:param choices: short list of possible answers, displayed after prompt if set
:param choices: short list of possible answers,
displayed after prompt if set
:param default: default value to return if user doesn't input anything
:param lowercase_answer: if True, convert return value to lower case
:param validation_regex: if set, keep asking until regex matches
:param complete: set to a list to enable tab completion
"""
styles = pmb.config.styles
while True:
date = datetime.datetime.now().strftime("%H:%M:%S")
question_full = "[" + date + "] " + question
line = question
if choices:
question_full += " (" + str.join("/", choices) + ")"
line += f" ({str.join('/', choices)})"
if default:
question_full += " [" + str(default) + "]"
line += f" [{default}]"
line_color = f"[{date}] {styles['BOLD']}{line}{styles['END']}"
line = f"[{date}] {line}"
if complete:
readline.parse_and_bind('tab: complete')
readline.set_completer(ReadlineTabCompleter(complete).completer_func)
delims = readline.get_completer_delims()
if '-' in delims:
delims = delims.replace('-', '')
readline.set_completer_delims(delims)
readline.set_completer(
ReadlineTabCompleter(complete).completer_func)
ret = input(question_full + ": ")
ret = input(f"{line_color}: ")
# Stop completing (question is answered)
if complete:
readline.set_completer(None)
# set_completer(None) would use the default file system completer
readline.set_completer(lambda text, state: None)
if lowercase_answer:
ret = ret.lower()
if ret == "":
ret = str(default)
args.logfd.write(question_full + " " + ret + "\n")
args.logfd.flush()
pmb.helpers.logging.logfd.write(f"{line}: {ret}\n")
pmb.helpers.logging.logfd.flush()
# Validate with regex
if not validation_regex:
@ -82,14 +98,49 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n",
validation_regex + "). Please try again.")
def confirm(args, question="Continue?", default=False):
def confirm(args, question="Continue?", default=False, no_assumptions=False):
"""
Convenience wrapper around ask for simple yes-no questions with validation.
:param no_assumptions: ask for confirmation, even if "pmbootstrap -y'
is set
:returns: True for "y", False for "n"
"""
default_str = "y" if default else "n"
if (args.assume_yes):
if args.assume_yes and not no_assumptions:
logging.info(question + " (y/n) [" + default_str + "]: y")
return True
answer = ask(args, question, ["y", "n"], default_str, True, "(y|n)")
answer = ask(question, ["y", "n"], default_str, True, "(y|n)")
return answer == "y"
def progress_print(args, progress):
"""
Print a snapshot of a progress bar to STDOUT. Call progress_flush to end
printing progress and clear the line. No output is printed in
non-interactive mode.
:param progress: completion percentage as a number between 0 and 1
"""
width = 79
try:
width = os.get_terminal_size().columns - 6
except OSError:
pass
chars = int(width * progress)
filled = "\u2588" * chars
empty = " " * (width - chars)
percent = int(progress * 100)
if pmb.config.is_interactive and not args.details_to_stdout:
sys.stdout.write(f"\u001b7{percent:>3}% {filled}{empty}")
sys.stdout.flush()
sys.stdout.write("\u001b8\u001b[0K")
def progress_flush(args):
"""
Finish printing a progress bar. This will erase the line. Does nothing in
non-interactive mode.
"""
if pmb.config.is_interactive and not args.details_to_stdout:
sys.stdout.flush()

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import glob
@ -23,14 +23,17 @@ def find_path(args, codename, file=''):
return g[0]
def list_codenames(args, vendor=None):
def list_codenames(args, vendor=None, unmaintained=True):
"""
Get all devices, for which aports are available
:param vendor: vendor name to choose devices from, or None for all vendors
:param unmaintained: include unmaintained devices
:returns: ["first-device", "second-device", ...]
"""
ret = []
for path in glob.glob(args.aports + "/device/*/device-*"):
if not unmaintained and '/unmaintained/' in path:
continue
device = os.path.basename(path).split("-", 1)[1]
if (vendor is None) or device.startswith(vendor + '-'):
ret.append(device)
@ -55,8 +58,8 @@ def list_apkbuilds(args):
"""
ret = {}
for device in list_codenames(args):
apkbuild_path = args.aports + "/device/*/device-" + device + "/APKBUILD"
ret[device] = pmb.parse.apkbuild(args, apkbuild_path)
apkbuild_path = f"{args.aports}/device/*/device-{device}/APKBUILD"
ret[device] = pmb.parse.apkbuild(apkbuild_path)
return ret

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
@ -26,7 +26,7 @@ def replace_apkbuild(args, pkgname, key, new, in_quotes=False):
:param in_quotes: expect the value to be in quotation marks ("") """
# Read old value
path = pmb.helpers.pmaports.find(args, pkgname) + "/APKBUILD"
apkbuild = pmb.parse.apkbuild(args, path)
apkbuild = pmb.parse.apkbuild(path)
old = apkbuild[key]
# Prepare old/new strings
@ -41,8 +41,8 @@ def replace_apkbuild(args, pkgname, key, new, in_quotes=False):
replace(path, "\n" + line_old + "\n", "\n" + line_new + "\n")
# Verify
del (args.cache["apkbuild"][path])
apkbuild = pmb.parse.apkbuild(args, path)
del (pmb.helpers.other.cache["apkbuild"][path])
apkbuild = pmb.parse.apkbuild(path)
if apkbuild[key] != str(new):
raise RuntimeError("Failed to set '{}' for pmaport '{}'. Make sure"
" that there's a line with exactly the string '{}'"

View File

@ -1,5 +1,6 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import json
import logging
import os
@ -11,9 +12,12 @@ import pmb.build.autodetect
import pmb.chroot
import pmb.chroot.initfs
import pmb.chroot.other
import pmb.ci
import pmb.config
import pmb.export
import pmb.flasher
import pmb.helpers.aportupgrade
import pmb.helpers.devices
import pmb.helpers.git
import pmb.helpers.lint
import pmb.helpers.logging
@ -22,11 +26,13 @@ import pmb.helpers.pmaports
import pmb.helpers.repo
import pmb.helpers.repo_missing
import pmb.helpers.run
import pmb.helpers.aportupgrade
import pmb.helpers.status
import pmb.install
import pmb.install.blockdevice
import pmb.netboot
import pmb.parse
import pmb.qemu
import pmb.sideload
def _parse_flavor(args, autoinstall=True):
@ -34,22 +40,19 @@ def _parse_flavor(args, autoinstall=True):
Verify the flavor argument if specified, or return a default value.
:param autoinstall: make sure that at least one kernel flavor is installed
"""
# Install at least one kernel and get installed flavors
# Install a kernel and get its "flavor", where flavor is a pmOS-specific
# identifier that is typically in the form
# "postmarketos-<manufacturer>-<device/chip>", e.g.
# "postmarketos-qcom-sdm845"
suffix = "rootfs_" + args.device
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix, autoinstall)
flavor = pmb.chroot.other.kernel_flavor_installed(
args, suffix, autoinstall)
# Parse and verify the flavor argument
flavor = args.flavor
if flavor:
if flavor not in flavors:
raise RuntimeError("No kernel installed with flavor " + flavor + "!" +
" Run 'pmbootstrap flasher list_flavors' to get a list.")
return flavor
if not len(flavors):
if not flavor:
raise RuntimeError(
"No kernel flavors installed in chroot " + suffix + "! Please let"
" your device package depend on a package starting with 'linux-'.")
return flavors[0]
return flavor
def _parse_suffix(args):
@ -66,6 +69,24 @@ def _parse_suffix(args):
return "native"
def _install_ondev_verify_no_rootfs(args):
chroot_dest = "/var/lib/rootfs.img"
dest = f"{args.work}/chroot_installer_{args.device}{chroot_dest}"
if os.path.exists(dest):
return
if args.ondev_cp:
for _, chroot_dest_cp in args.ondev_cp:
if chroot_dest_cp == chroot_dest:
return
raise ValueError(f"--no-rootfs set, but rootfs.img not found in install"
" chroot. Either run 'pmbootstrap install' without"
" --no-rootfs first to let it generate the postmarketOS"
" rootfs once, or supply a rootfs file with:"
f" --cp os.img:{chroot_dest}")
def aportgen(args):
for package in args.packages:
logging.info("Generate aport: " + package)
@ -82,7 +103,8 @@ def build(args):
return
# Set src and force
src = os.path.realpath(os.path.expanduser(args.src[0])) if args.src else None
src = os.path.realpath(os.path.expanduser(args.src[0])) \
if args.src else None
force = True if src else args.force
if src and not os.path.exists(src):
raise RuntimeError("Invalid path specified for --src: " + src)
@ -110,6 +132,21 @@ def checksum(args):
pmb.build.checksum.update(args, package)
def sideload(args):
arch = args.deviceinfo["arch"]
if args.arch:
arch = args.arch
user = args.user
host = args.host
pmb.sideload.sideload(args, user, host, args.port, arch, args.install_key,
args.packages)
def netboot(args):
if args.action_netboot == "serve":
pmb.netboot.start_nbd_server(args)
def chroot(args):
# Suffix
suffix = _parse_suffix(args)
@ -132,6 +169,14 @@ def chroot(args):
env["DISPLAY"] = os.environ.get("DISPLAY")
env["XAUTHORITY"] = "/home/pmos/.Xauthority"
# Install blockdevice
if args.install_blockdev:
size_boot = 128 # 128 MiB
size_root = 4096 # 4 GiB
size_reserve = 2048 # 2 GiB
pmb.install.blockdevice.create_and_mount_image(args, size_boot,
size_root, size_reserve)
# Run the command as user/root
if args.user:
logging.info("(" + suffix + ") % su pmos -c '" +
@ -156,7 +201,7 @@ def config(args):
raise RuntimeError("config --reset requires a name to be given.")
value = pmb.config.defaults[args.name]
cfg["pmbootstrap"][args.name] = value
logging.info("Config changed to default: " + args.name + "='" + value + "'")
logging.info(f"Config changed to default: {args.name}='{value}'")
pmb.config.save(args, cfg)
elif args.value is not None:
cfg["pmbootstrap"][args.name] = args.value
@ -188,19 +233,95 @@ def initfs(args):
def install(args):
if args.no_fde:
logging.warning("WARNING: --no-fde is deprecated, as it is now the default.")
logging.warning("WARNING: --no-fde is deprecated,"
" as it is now the default.")
if args.rsync and args.full_disk_encryption:
raise ValueError("Installation using rsync is not compatible with full"
" disk encryption.")
if args.rsync and not args.sdcard:
raise ValueError("Installation using rsync only works on sdcard.")
# On-device installer checks
# Note that this can't be in the mutually exclusive group that has most of
# the conflicting options, because then it would not work with --sdcard.
if args.on_device_installer:
if args.full_disk_encryption:
raise ValueError("--on-device-installer cannot be combined with"
" --fde. The user can choose to encrypt their"
" installation later in the on-device installer.")
if args.android_recovery_zip:
raise ValueError("--on-device-installer cannot be combined with"
" --android-recovery-zip (patches welcome)")
if args.no_image:
raise ValueError("--on-device-installer cannot be combined with"
" --no-image")
if args.rsync:
raise ValueError("--on-device-installer cannot be combined with"
" --rsync")
if args.filesystem:
raise ValueError("--on-device-installer cannot be combined with"
" --filesystem")
if args.deviceinfo["cgpt_kpart"]:
raise ValueError("--on-device-installer cannot be used with"
" ChromeOS devices")
else:
if args.ondev_cp:
raise ValueError("--cp can only be combined with --ondev")
if args.ondev_no_rootfs:
raise ValueError("--no-rootfs can only be combined with --ondev."
" Do you mean --no-image?")
if args.ondev_no_rootfs:
_install_ondev_verify_no_rootfs(args)
# 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
# Android recovery zip related
if args.android_recovery_zip and args.filesystem:
raise ValueError("--android-recovery-zip cannot be combined with"
" --filesystem (patches welcome)")
if args.android_recovery_zip and args.full_disk_encryption:
logging.info("WARNING: --fde is rarely used in combination with"
" --android-recovery-zip. If this does not work, consider"
" using another method (e.g. installing via netcat)")
logging.info("WARNING: the kernel of the recovery system (e.g. TWRP)"
f" must support the cryptsetup cipher '{args.cipher}'.")
logging.info("If you know what you are doing, consider setting a"
" different cipher with 'pmbootstrap install --cipher=..."
" --fde --android-recovery-zip'.")
# 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.build_pkgs_on_install = 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.")
# Verify that the root filesystem is supported by current pmaports branch
pmb.install.get_root_filesystem(args)
pmb.install.install(args)
@ -256,11 +377,17 @@ def newapkbuild(args):
def kconfig(args):
if args.action_kconfig == "check":
details = args.kconfig_check_details
# Build the components list from cli arguments (--waydroid etc.)
components_list = []
for name in pmb.parse.kconfig.get_all_component_names():
if getattr(args, f"kconfig_check_{name}"):
components_list += [name]
# Handle passing a file directly
if args.file:
if pmb.parse.kconfig.check_file(args, args.package,
force_anbox_check=args.anbox,
details=True):
if pmb.parse.kconfig.check_file(args.package, components_list,
details=details):
logging.info("kconfig check succeeded!")
return
raise RuntimeError("kconfig check failed!")
@ -280,15 +407,15 @@ def kconfig(args):
packages.sort()
for package in packages:
if not args.force:
pkgname = package if package.startswith("linux-") else "linux-" + package
pkgname = package if package.startswith("linux-") \
else "linux-" + package
aport = pmb.helpers.pmaports.find(args, pkgname)
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
apkbuild = pmb.parse.apkbuild(f"{aport}/APKBUILD")
if "!pmb:kconfigcheck" in apkbuild["options"]:
skipped += 1
continue
if not pmb.parse.kconfig.check(args, package,
force_anbox_check=args.anbox,
details=True):
if not pmb.parse.kconfig.check(args, package, components_list,
details=details):
error = True
# At least one failure
@ -299,8 +426,27 @@ def kconfig(args):
logging.info("NOTE: " + str(skipped) + " kernel(s) was skipped"
" (consider 'pmbootstrap kconfig check -f')")
logging.info("kconfig check succeeded!")
elif args.action_kconfig == "edit":
pmb.build.menuconfig(args, args.package)
elif args.action_kconfig in ["edit", "migrate"]:
if args.package:
pkgname = args.package
else:
pkgname = args.deviceinfo["codename"]
use_oldconfig = args.action_kconfig == "migrate"
pmb.build.menuconfig(args, pkgname, use_oldconfig)
def deviceinfo_parse(args):
# Default to all devices
devices = args.devices
if not devices:
devices = pmb.helpers.devices.list_codenames(args)
# Iterate over all devices
kernel = args.deviceinfo_parse_kernel
for device in devices:
print(f"{device}, with kernel={kernel}:")
print(json.dumps(pmb.parse.deviceinfo(args, device, kernel), indent=4,
sort_keys=True))
def apkbuild_parse(args):
@ -314,12 +460,12 @@ def apkbuild_parse(args):
print(package + ":")
aport = pmb.helpers.pmaports.find(args, package)
path = aport + "/APKBUILD"
print(json.dumps(pmb.parse.apkbuild(args, path), indent=4,
print(json.dumps(pmb.parse.apkbuild(path), indent=4,
sort_keys=True))
def apkindex_parse(args):
result = pmb.parse.apkindex.parse(args, args.apkindex_path)
result = pmb.parse.apkindex.parse(args.apkindex_path)
if args.package:
if args.package not in result:
raise RuntimeError("Package not found in the APKINDEX: " +
@ -370,7 +516,7 @@ def shutdown(args):
def stats(args):
# Chroot suffix
suffix = "native"
if args.arch != args.arch_native:
if args.arch != pmb.config.arch_native:
suffix = "buildroot_" + args.arch
# Install ccache and display stats
@ -385,18 +531,25 @@ def work_migrate(args):
def log(args):
log_testsuite = f"{args.work}/log_testsuite.txt"
if args.clear_log:
pmb.helpers.run.user(args, ["truncate", "-s", "0", args.log])
pmb.helpers.run.user(args, ["tail", "-f", args.log, "-n", args.lines],
output="tui")
pmb.helpers.run.user(args, ["truncate", "-s", "0", log_testsuite])
cmd = ["tail", "-n", args.lines, "-F"]
def log_distccd(args):
logpath = "/home/pmos/distccd.log"
if args.clear_log:
pmb.chroot.user(args, ["truncate", "-s", "0", logpath])
pmb.chroot.user(args, ["tail", "-f", logpath, "-n", args.lines],
output="tui")
# Follow the testsuite's log file too if it exists. It will be created when
# starting a test case that writes to it (git -C test grep log_testsuite).
if os.path.exists(log_testsuite):
cmd += [log_testsuite]
# tail writes the last lines of the files to the terminal. Put the regular
# log at the end, so that output is visible at the bottom (where the user
# looks for an error / what's currently going on).
cmd += [args.log]
pmb.helpers.run.user(args, cmd, output="tui")
def zap(args):
@ -404,7 +557,7 @@ def zap(args):
distfiles=args.distfiles, pkgs_local=args.pkgs_local,
pkgs_local_mismatch=args.pkgs_local_mismatch,
pkgs_online_mismatch=args.pkgs_online_mismatch,
rust=args.rust)
rust=args.rust, netboot=args.netboot)
# Don't write the "Done" message
pmb.helpers.logging.disable()
@ -413,7 +566,8 @@ def zap(args):
def bootimg_analyze(args):
bootimg = pmb.parse.bootimg(args, args.path)
tmp_output = "Put these variables in the deviceinfo file of your device:\n"
for line in pmb.aportgen.device.generate_deviceinfo_fastboot_content(args, bootimg).split("\n"):
for line in pmb.aportgen.device.\
generate_deviceinfo_fastboot_content(bootimg).split("\n"):
tmp_output += "\n" + line.lstrip()
logging.info(tmp_output)
@ -449,10 +603,53 @@ def lint(args):
if not packages:
packages = pmb.helpers.pmaports.get_list(args)
for package in packages:
pmb.helpers.lint.check(args, package)
pmb.helpers.lint.check(args, packages)
def status(args):
if not pmb.helpers.status.print_status(args, args.details):
sys.exit(1)
def ci(args):
topdir = pmb.helpers.git.get_topdir(args, os.getcwd())
if not os.path.exists(topdir):
logging.error("ERROR: change your current directory to a git"
" repository (e.g. pmbootstrap, pmaports) before running"
" 'pmbootstrap ci'.")
exit(1)
scripts_available = pmb.ci.get_ci_scripts(topdir)
scripts_available = pmb.ci.sort_scripts_by_speed(scripts_available)
if not scripts_available:
logging.error("ERROR: no supported CI scripts found in current git"
" repository, see https://postmarketos.org/pmb-ci")
exit(1)
scripts_selected = {}
if args.scripts:
if args.all:
raise RuntimeError("Combining --all with script names doesn't"
" make sense")
for script in args.scripts:
if script not in scripts_available:
logging.error(f"ERROR: script '{script}' not found in git"
" repository, found these:"
f" {', '.join(scripts_available.keys())}")
exit(1)
scripts_selected[script] = scripts_available[script]
elif args.all:
scripts_selected = scripts_available
if args.fast:
for script, script_data in scripts_available.items():
if "slow" not in script_data["options"]:
scripts_selected[script] = script_data
if not pmb.helpers.git.clean_worktree(args, topdir):
logging.warning("WARNING: this git repository has uncommitted changes")
if not scripts_selected:
scripts_selected = pmb.ci.ask_which_scripts_to_run(scripts_available)
pmb.ci.run_scripts(args, topdir, scripts_selected)

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import configparser
import logging
@ -8,6 +8,7 @@ import time
import pmb.build
import pmb.chroot.apk
import pmb.config
import pmb.helpers.pmaports
import pmb.helpers.run
@ -21,15 +22,13 @@ def get_path(args, name_repo):
return args.work + "/cache_git/" + name_repo
def clone(args, name_repo, shallow=True):
def clone(args, name_repo):
""" Clone a git repository to $WORK/cache_git/$name_repo (or to the
overridden path set in args, as with pmbootstrap --aports).
:param name_repo: short alias used for the repository name, from
pmb.config.git_repos (e.g. "aports_upstream",
"pmaports")
:param shallow: only clone the last revision of the repository, instead
of the entire repository (faster, saves bandwith) """
"pmaports") """
# Check for repo name in the config
if name_repo not in pmb.config.git_repos:
raise ValueError("No git repository configured for " + name_repo)
@ -39,8 +38,6 @@ def clone(args, name_repo, shallow=True):
# Build git command
url = pmb.config.git_repos[name_repo]
command = ["git", "clone"]
if shallow:
command += ["--depth=1"]
command += [url, path]
# Create parent dir and clone
@ -112,8 +109,8 @@ def parse_channels_cfg(args):
...}} """
# Cache during one pmbootstrap run
cache_key = "pmb.helpers.git.parse_channels_cfg"
if args.cache[cache_key]:
return args.cache[cache_key]
if pmb.helpers.other.cache[cache_key]:
return pmb.helpers.other.cache[cache_key]
# Read with configparser
cfg = configparser.ConfigParser()
@ -142,13 +139,15 @@ def parse_channels_cfg(args):
if channel == "channels.cfg":
continue # meta section
ret["channels"][channel] = {}
channel_new = pmb.helpers.pmaports.get_channel_new(channel)
ret["channels"][channel_new] = {}
for key in ["description", "branch_pmaports", "branch_aports",
"mirrordir_alpine"]:
value = cfg.get(channel, key)
ret["channels"][channel][key] = value
ret["channels"][channel_new][key] = value
args.cache[cache_key] = ret
pmb.helpers.other.cache[cache_key] = ret
return ret
@ -230,12 +229,12 @@ def pull(args, name_repo):
return 0
def is_outdated(args, path):
def is_outdated(path):
# FETCH_HEAD always exists in repositories cloned by pmbootstrap.
# Usually it does not (before first git fetch/pull), but there is no good
# fallback. For exampe, getting the _creation_ date of .git/HEAD is non-
# trivial with python on linux (https://stackoverflow.com/a/39501288).
# Note that we have to assume here, that the user had fetched the "origin"
# Note that we have to assume here that the user had fetched the "origin"
# repository. If the user fetched another repository, FETCH_HEAD would also
# get updated, even though "origin" may be outdated. For pmbootstrap status
# it is good enough, because it should help the users that are not doing
@ -247,3 +246,29 @@ def is_outdated(args, path):
date_outdated = time.time() - pmb.config.git_repo_outdated
return date_head <= date_outdated
def get_topdir(args, path):
""" :returns: a string with the top dir of the git repository, or an
empty string if it's not a git repository. """
return pmb.helpers.run.user(args, ["git", "rev-parse", "--show-toplevel"],
path, output_return=True, check=False).rstrip()
def get_files(args, path):
""" Get all files inside a git repository, that are either already in the
git tree or are not in gitignore. Do not list deleted files. To be used
for creating a tarball of the git repository.
:param path: top dir of the git repository
:returns: all files in a git repository as list, relative to path """
ret = []
files = pmb.helpers.run.user(args, ["git", "ls-files"], path,
output_return=True).split("\n")
files += pmb.helpers.run.user(args, ["git", "ls-files",
"--exclude-standard", "--other"], path,
output_return=True).split("\n")
for file in files:
if os.path.exists(f"{path}/{file}"):
ret += [file]
return ret

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import hashlib
import json
@ -17,6 +17,7 @@ def download(args, url, prefix, cache=True, loglevel=logging.INFO,
:param url: the http(s) address of to the file to download
:param prefix: for the cache, to make it easier to find (cache files
get a hash of the URL after the prefix)
:param cache: if True, and url is cached, do not download it again
:param loglevel: change to logging.DEBUG to only display the download
message in 'pmbootstrap log', not in stdout. We use
this when downloading many APKINDEX files at once, no
@ -40,7 +41,8 @@ def download(args, url, prefix, cache=True, loglevel=logging.INFO,
# Offline and not cached
if args.offline:
raise RuntimeError(f"File not found in cache and offline flag is enabled: {url}")
raise RuntimeError("File not found in cache and offline flag is"
f" enabled: {url}")
# Download the file
logging.log(loglevel, "Download " + url)
@ -87,6 +89,6 @@ def retrieve(url, headers=None, allow_404=False):
def retrieve_json(*args, **kwargs):
""" Fetch the contents of a URL, parse it as JSON and return it. See retrieve() for the
list of all parameters. """
""" Fetch the contents of a URL, parse it as JSON and return it. See
retrieve() for the list of all parameters. """
return json.loads(retrieve(*args, **kwargs))

View File

@ -1,6 +1,7 @@
# Copyright 2020 Danct12 <danct12@disroot.org>
# Copyright 2023 Danct12 <danct12@disroot.org>
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
import pmb.chroot
import pmb.chroot.apk
@ -9,16 +10,38 @@ import pmb.helpers.run
import pmb.helpers.pmaports
def check(args, pkgname):
def check(args, pkgnames):
"""
Run apkbuild-lint on the supplied packages
:param pkgnames: Names of the packages to lint
"""
pmb.chroot.apk.install(args, ["atools"])
# Run apkbuild-lint on copy of pmaport in chroot
pmb.build.init(args)
pmb.build.copy_to_buildpath(args, pkgname)
logging.info("(native) linting " + pkgname + " with apkbuild-lint")
# Mount pmaports.git inside the chroot so that we don't have to copy the
# package folders
pmaports = "/mnt/pmaports"
pmb.build.mount_pmaports(args, pmaports)
# Locate all APKBUILDs and make the paths be relative to the pmaports
# root
apkbuilds = []
for pkgname in pkgnames:
aport = pmb.helpers.pmaports.find(args, pkgname)
if not os.path.exists(aport + "/APKBUILD"):
raise ValueError("Path does not contain an APKBUILD file:" +
aport)
relpath = os.path.relpath(aport, args.aports)
apkbuilds.append(f"{relpath}/APKBUILD")
# Run apkbuild-lint in chroot from the pmaports mount point. This will
# print a nice source identifier à la "./cross/grub-x86/APKBUILD" for
# each violation.
pkgstr = ", ".join(pkgnames)
logging.info(f"(native) linting {pkgstr} with apkbuild-lint")
options = pmb.config.apkbuild_custom_valid_options
return pmb.chroot.user(args, ["apkbuild-lint", "APKBUILD"],
return pmb.chroot.root(args, ["apkbuild-lint"] + apkbuilds,
check=False, output="stdout",
output_return=True,
working_dir="/home/pmos/build",
working_dir=pmaports,
env={"CUSTOM_VALID_OPTIONS": " ".join(options)})

View File

@ -1,8 +1,11 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
import sys
import pmb.config
logfd = None
class log_handler(logging.StreamHandler):
@ -20,14 +23,40 @@ class log_handler(logging.StreamHandler):
not self._args.quiet and
record.levelno >= logging.INFO):
stream = self.stream
stream.write(msg)
styles = pmb.config.styles
msg_col = (
msg.replace(
"NOTE:",
f"{styles['BLUE']}NOTE:{styles['END']}",
1,
)
.replace(
"WARNING:",
f"{styles['YELLOW']}WARNING:{styles['END']}",
1,
)
.replace(
"ERROR:",
f"{styles['RED']}ERROR:{styles['END']}",
1,
)
.replace(
"DONE!",
f"{styles['GREEN']}DONE!{styles['END']}",
1,
)
)
stream.write(msg_col)
stream.write(self.terminator)
self.flush()
# Everything: Write to logfd
msg = "(" + str(os.getpid()).zfill(6) + ") " + msg
self._args.logfd.write(msg + "\n")
self._args.logfd.flush()
logfd.write(msg + "\n")
logfd.flush()
except (KeyboardInterrupt, SystemExit):
raise
@ -49,29 +78,31 @@ def add_verbose_log_level():
logging.addLevelName(logging.VERBOSE, "VERBOSE")
logging.Logger.verbose = lambda inst, msg, * \
args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs)
logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg,
*args, **kwargs)
logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE,
msg, *args,
**kwargs)
def init(args):
"""
Set log format and add the log file descriptor to args.logfd, add the
Set log format and add the log file descriptor to logfd, add the
verbose log level.
"""
global logfd
# Set log file descriptor (logfd)
if args.details_to_stdout:
setattr(args, "logfd", sys.stdout)
logfd = sys.stdout
else:
# Require containing directory to exist (so we don't create the work
# folder and break the folder migration logic, which needs to set the
# version upon creation)
dir = os.path.dirname(args.log)
if os.path.exists(dir):
setattr(args, "logfd", open(args.log, "a+"))
logfd = open(args.log, "a+")
else:
setattr(args, "logfd", open(os.devnull, "a+"))
logfd = open(os.devnull, "a+")
if args.action != "init":
print("WARNING: Can't create log file in '" + dir + "', path"
print(f"WARNING: Can't create log file in '{dir}', path"
" does not exist!")
# Set log format

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import pmb.helpers.run
@ -6,7 +6,7 @@ import pmb.helpers.run
def ismount(folder):
"""
Ismount() implementation, that works for mount --bind.
Ismount() implementation that works for mount --bind.
Workaround for: https://bugs.python.org/issue29707
"""
folder = os.path.realpath(os.path.realpath(folder))
@ -45,7 +45,7 @@ def bind(args, source, destination, create_folders=True, umount=False):
# Actually mount the folder
pmb.helpers.run.root(args, ["mount", "--bind", source, destination])
# Verify, that it has worked
# Verify that it has worked
if not ismount(destination):
raise RuntimeError("Mount failed: " + source + " -> " + destination)
@ -77,7 +77,7 @@ def umount_all_list(prefix, source="/proc/mounts"):
"""
Parses `/proc/mounts` for all folders beginning with a prefix.
:source: can be changed for testcases
:returns: a list of folders, that need to be umounted
:returns: a list of folders that need to be umounted
"""
ret = []
prefix = os.path.realpath(prefix)
@ -100,7 +100,7 @@ def umount_all_list(prefix, source="/proc/mounts"):
def umount_all(args, folder):
"""
Umount all folders, that are mounted inside a given folder.
Umount all folders that are mounted inside a given folder.
"""
for mountpoint in umount_all_list(folder):
pmb.helpers.run.root(args, ["umount", mountpoint])

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import logging
@ -17,10 +17,9 @@ def folder_size(args, path):
faster than doing the same task in pure Python). This result is only
approximatelly right, but good enough for pmbootstrap's use case (#760).
:returns: folder size in bytes
:returns: folder size in kilobytes
"""
output = pmb.helpers.run.root(args, ["du", "--summarize",
"--block-size=1",
output = pmb.helpers.run.root(args, ["du", "-ks",
path], output_return=True)
# Only look at last line to filter out sudo garbage (#1766)
@ -30,7 +29,7 @@ def folder_size(args, path):
return ret
def check_grsec(args):
def check_grsec():
"""
Check if the current kernel is based on the grsec patchset, and if
the chroot_deny_chmod option is enabled. Raise an exception in that
@ -48,17 +47,23 @@ def check_binfmt_misc(args):
"""
Check if the 'binfmt_misc' module is loaded by checking, if
/proc/sys/fs/binfmt_misc/ exists. If it exists, then do nothing.
Otherwise, raise an exception pointing to user to the Wiki.
Otherwise, load the module and mount binfmt_misc.
If that fails as well, raise an exception pointing the user to the wiki.
"""
path = "/proc/sys/fs/binfmt_misc/status"
if os.path.exists(path):
return
link = "https://postmarketos.org/binfmt_misc"
raise RuntimeError("It appears that your system has not loaded the"
" module 'binfmt_misc'. This is required to run"
" foreign architecture programs with QEMU (eg."
" armhf on x86_64):\n See: <" + link + ">")
# check=False: this might be built-in instead of being a module
pmb.helpers.run.root(args, ["modprobe", "binfmt_misc"], check=False)
# check=False: we check it below and print a more helpful message on error
pmb.helpers.run.root(args, ["mount", "-t", "binfmt_misc", "none",
"/proc/sys/fs/binfmt_misc"], check=False)
if not os.path.exists(path):
link = "https://postmarketos.org/binfmt_misc"
raise RuntimeError(f"Failed to set up binfmt_misc, see: {link}")
def migrate_success(args, version):
@ -197,6 +202,34 @@ def migrate_work_folder(args):
migrate_success(args, 5)
current = 5
if current == 5:
# Ask for confirmation
logging.info("Changelog:")
logging.info("* besides edge, pmaports channels have the same name")
logging.info(" as the branch now (pmbootstrap#2015)")
logging.info("Migration will do the following:")
logging.info("* Zap your chroots")
logging.info("* Adjust subdirs of your locally built packages dir:")
logging.info(f" {args.work}/packages")
logging.info(" stable => v20.05")
logging.info(" stable-next => v21.03")
if not pmb.helpers.cli.confirm(args):
raise RuntimeError("Aborted.")
# Zap chroots to avoid potential "ERROR: Chroot 'native' was created
# for the 'stable' channel, but you are on the 'v20.05' channel now."
pmb.chroot.zap(args, False)
# Migrate
packages_dir = f"{args.work}/packages"
for old, new in pmb.config.pmaports_channels_legacy.items():
if os.path.exists(f"{packages_dir}/{old}"):
pmb.helpers.run.root(args, ["mv", old, new], packages_dir)
# Update version file
migrate_success(args, 6)
current = 6
# Can't migrate, user must delete it
if current != required:
raise RuntimeError("Sorry, we can't migrate that automatically. Please"
@ -234,13 +267,49 @@ def validate_hostname(hostname):
return False
# Check that it only contains valid chars
if not re.match("^[0-9a-z-]*$", hostname):
if not re.match(r"^[0-9a-z-\.]*$", hostname):
logging.fatal("ERROR: Hostname must only contain letters (a-z),"
" digits (0-9) or minus signs (-)")
" digits (0-9), minus signs (-), or periods (.)")
return False
# Check that doesn't begin or end with a minus sign
if hostname[:1] == "-" or hostname[-1:] == "-":
logging.fatal("ERROR: Hostname must not begin or end with a minus sign")
# Check that doesn't begin or end with a minus sign or period
if re.search(r"^-|^\.|-$|\.$", hostname):
logging.fatal("ERROR: Hostname must not begin or end with a minus"
" sign or period")
return False
return True
"""
pmbootstrap uses this dictionary to save the result of expensive
results, so they work a lot faster the next time they are needed in the
same session. Usually the cache is written to and read from in the same
Python file, with code similar to the following:
def lookup(key):
if key in pmb.helpers.other.cache["mycache"]:
return pmb.helpers.other.cache["mycache"][key]
ret = expensive_operation(args, key)
pmb.helpers.other.cache["mycache"][key] = ret
return ret
"""
cache = None
def init_cache():
global cache
""" Add a caching dict (caches parsing of files etc. for the current
session) """
repo_update = {"404": [], "offline_msg_shown": False}
cache = {"apkindex": {},
"apkbuild": {},
"apk_min_version_checked": [],
"apk_repository_list_updated": [],
"built": {},
"find_aport": {},
"pmb.helpers.package.depends_recurse": {},
"pmb.helpers.package.get": {},
"pmb.helpers.repo.update": repo_update,
"pmb.helpers.git.parse_channels_cfg": {},
"pmb.config.pmaports.read_config": None}

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Functions that work with both pmaports and binary package repos. See also:
@ -33,10 +33,16 @@ def get(args, pkgname, arch, replace_subpkgnames=False, must_exist=True):
* None if the package was not found """
# Cached result
cache_key = "pmb.helpers.package.get"
if (arch in args.cache[cache_key] and
pkgname in args.cache[cache_key][arch] and
replace_subpkgnames in args.cache[cache_key][arch][pkgname]):
return args.cache[cache_key][arch][pkgname][replace_subpkgnames]
if (
arch in pmb.helpers.other.cache[cache_key] and
pkgname in pmb.helpers.other.cache[cache_key][arch] and
replace_subpkgnames in pmb.helpers.other.cache[cache_key][arch][
pkgname
]
):
return pmb.helpers.other.cache[cache_key][arch][pkgname][
replace_subpkgnames
]
# Find in pmaports
ret = None
@ -96,11 +102,13 @@ def get(args, pkgname, arch, replace_subpkgnames=False, must_exist=True):
# Save to cache and return
if ret:
if arch not in args.cache[cache_key]:
args.cache[cache_key][arch] = {}
if pkgname not in args.cache[cache_key][arch]:
args.cache[cache_key][arch][pkgname] = {}
args.cache[cache_key][arch][pkgname][replace_subpkgnames] = ret
if arch not in pmb.helpers.other.cache[cache_key]:
pmb.helpers.other.cache[cache_key][arch] = {}
if pkgname not in pmb.helpers.other.cache[cache_key][arch]:
pmb.helpers.other.cache[cache_key][arch][pkgname] = {}
pmb.helpers.other.cache[cache_key][arch][pkgname][
replace_subpkgnames
] = ret
return ret
# Could not find the package
@ -119,9 +127,9 @@ def depends_recurse(args, pkgname, arch):
"linux-samsung-i9100", ...] """
# Cached result
cache_key = "pmb.helpers.package.depends_recurse"
if (arch in args.cache[cache_key] and
pkgname in args.cache[cache_key][arch]):
return args.cache[cache_key][arch][pkgname]
if (arch in pmb.helpers.other.cache[cache_key] and
pkgname in pmb.helpers.other.cache[cache_key][arch]):
return pmb.helpers.other.cache[cache_key][arch][pkgname]
# Build ret (by iterating over the queue)
queue = [pkgname]
@ -141,9 +149,9 @@ def depends_recurse(args, pkgname, arch):
ret.sort()
# Save to cache and return
if arch not in args.cache[cache_key]:
args.cache[cache_key][arch] = {}
args.cache[cache_key][arch][pkgname] = ret
if arch not in pmb.helpers.other.cache[cache_key]:
pmb.helpers.other.cache[cache_key][arch] = {}
pmb.helpers.other.cache[cache_key][arch][pkgname] = ret
return ret

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
@ -18,7 +18,7 @@ def package(args, pkgname, reason="", dry=False):
"""
# Current and new pkgrel
path = pmb.helpers.pmaports.find(args, pkgname) + "/APKBUILD"
apkbuild = pmb.parse.apkbuild(args, path)
apkbuild = pmb.parse.apkbuild(path)
pkgrel = int(apkbuild["pkgrel"])
pkgrel_new = pkgrel + 1
@ -34,8 +34,8 @@ def package(args, pkgname, reason="", dry=False):
pmb.helpers.file.replace(path, old, new)
# Verify
del(args.cache["apkbuild"][path])
apkbuild = pmb.parse.apkbuild(args, path)
del pmb.helpers.other.cache["apkbuild"][path]
apkbuild = pmb.parse.apkbuild(path)
if int(apkbuild["pkgrel"]) != pkgrel_new:
raise RuntimeError("Failed to bump pkgrel for package '" + pkgname +
"'. Make sure that there's a line with exactly the"
@ -81,6 +81,10 @@ def auto_apkindex_package(args, arch, aport, apk, dry=False):
", ".join(depends)))
missing = []
for depend in depends:
if depend.startswith("!"):
# Ignore conflict-dependencies
continue
providers = pmb.parse.apkindex.providers(args, depend, arch,
must_exist=False)
if providers == {}:
@ -107,20 +111,20 @@ def auto(args, dry=False):
paths = pmb.helpers.repo.apkindex_files(args, arch, alpine=False)
for path in paths:
logging.info("scan " + path)
index = pmb.parse.apkindex.parse(args, path, False)
index = pmb.parse.apkindex.parse(path, False)
for pkgname, apk in index.items():
origin = apk["origin"]
# Only increase once!
if origin in ret:
logging.verbose("{}: origin '{}' found again".format(pkgname,
origin))
logging.verbose(
f"{pkgname}: origin '{origin}' found again")
continue
aport_path = pmb.helpers.pmaports.find(args, origin, False)
if not aport_path:
logging.warning("{}: origin '{}' aport not found".format(
pkgname, origin))
continue
aport = pmb.parse.apkbuild(args, aport_path + "/APKBUILD")
aport = pmb.parse.apkbuild(f"{aport_path}/APKBUILD")
if auto_apkindex_package(args, arch, aport, apk, dry):
ret.append(pkgname)
return ret

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Functions that work with pmaports. See also:
@ -13,9 +13,9 @@ import pmb.parse
def _find_apkbuilds(args):
# Try to get a cached result first (we assume, that the aports don't change
# Try to get a cached result first (we assume that the aports don't change
# in one pmbootstrap call)
apkbuilds = args.cache.get("pmb.helpers.pmaports.apkbuilds")
apkbuilds = pmb.helpers.other.cache.get("pmb.helpers.pmaports.apkbuilds")
if apkbuilds is not None:
return apkbuilds
@ -27,11 +27,12 @@ def _find_apkbuilds(args):
"subfolders. Please put it only in one folder.")
apkbuilds[package] = apkbuild
# Sort dictionary so we don't need to do it over and over again in get_list()
# Sort dictionary so we don't need to do it over and over again in
# get_list()
apkbuilds = dict(sorted(apkbuilds.items()))
# Save result in cache
args.cache["pmb.helpers.pmaports.apkbuilds"] = apkbuilds
pmb.helpers.other.cache["pmb.helpers.pmaports.apkbuilds"] = apkbuilds
return apkbuilds
@ -99,19 +100,54 @@ def guess_main(args, subpkgname):
return os.path.dirname(path)
def _find_package_in_apkbuild(package, path):
"""
Look through subpackages and all provides to see if the APKBUILD at the
specified path contains (or provides) the specified package.
:param package: The package to search for
:param path: The path to the apkbuild
:return: True if the APKBUILD contains or provides the package
"""
apkbuild = pmb.parse.apkbuild(path)
# Subpackages
if package in apkbuild["subpackages"]:
return True
# Search for provides in both package and subpackages
apkbuild_pkgs = [apkbuild, *apkbuild["subpackages"].values()]
for apkbuild_pkg in apkbuild_pkgs:
if not apkbuild_pkg:
continue
# Provides (cut off before equals sign for entries like
# "mkbootimg=0.0.1")
for provides_i in apkbuild_pkg["provides"]:
# Ignore provides without version, they shall never be
# automatically selected
if "=" not in provides_i:
continue
if package == provides_i.split("=", 1)[0]:
return True
return False
def find(args, package, must_exist=True):
"""
Find the aport path, that provides a certain subpackage.
Find the aport path that provides a certain subpackage.
If you want the parsed APKBUILD instead, use pmb.helpers.pmaports.get().
:param must_exist: Raise an exception, when not found
:returns: the full path to the aport folder
"""
# Try to get a cached result first (we assume, that the aports don't change
# Try to get a cached result first (we assume that the aports don't change
# in one pmbootstrap call)
ret = None
if package in args.cache["find_aport"]:
ret = args.cache["find_aport"][package]
if package in pmb.helpers.other.cache["find_aport"]:
ret = pmb.helpers.other.cache["find_aport"][package]
else:
# Sanity check
if "*" in package:
@ -122,36 +158,23 @@ def find(args, package, must_exist=True):
if path:
ret = os.path.dirname(path)
# Try to guess based on the subpackage name
guess = guess_main(args, package)
if guess:
# ... but see if we were right
if _find_package_in_apkbuild(package, f'{guess}/APKBUILD'):
ret = guess
# Search in subpackages and provides
if not ret:
for path_current in _find_apkbuilds(args).values():
apkbuild = pmb.parse.apkbuild(args, path_current)
found = False
# Subpackages
if package in apkbuild["subpackages"]:
found = True
# Provides (cut off before equals sign for entries like
# "mkbootimg=0.0.1")
if not found:
for provides_i in apkbuild["provides"]:
# Ignore provides without version, they shall never be
# automatically selected
if "=" not in provides_i:
continue
if package == provides_i.split("=", 1)[0]:
found = True
break
if found:
if _find_package_in_apkbuild(package, path_current):
ret = os.path.dirname(path_current)
break
# Guess a main package
# Use the guess otherwise
if not ret:
ret = guess_main(args, package)
ret = guess
# Crash when necessary
if ret is None and must_exist:
@ -159,7 +182,7 @@ def find(args, package, must_exist=True):
package)
# Save result in cache
args.cache["find_aport"][package] = ret
pmb.helpers.other.cache["find_aport"][package] = ret
return ret
@ -170,8 +193,9 @@ def get(args, pkgname, must_exist=True, subpackages=True):
:param pkgname: the package name to find
:param must_exist: raise an exception when it can't be found
:param subpackages: also search for subpackages with the specified names
(slow! might need to parse all APKBUILDs to find it)
:param subpackages: also search for subpackages with the specified
names (slow! might need to parse all APKBUILDs to
find it)
:returns: relevant variables from the APKBUILD as dictionary, e.g.:
{ "pkgname": "hello-world",
"arch": ["all"],
@ -183,17 +207,42 @@ def get(args, pkgname, must_exist=True, subpackages=True):
if subpackages:
aport = find(args, pkgname, must_exist)
if aport:
return pmb.parse.apkbuild(args, aport + "/APKBUILD")
return pmb.parse.apkbuild(f"{aport}/APKBUILD")
else:
path = _find_apkbuilds(args).get(pkgname)
if path:
return pmb.parse.apkbuild(args, path)
return pmb.parse.apkbuild(path)
if must_exist:
raise RuntimeError(f"Could not find APKBUILD for package: {pkgname}")
raise RuntimeError("Could not find APKBUILD for package:"
f" {pkgname}")
return None
def find_providers(args, provide):
"""
Search for providers of the specified (virtual) package in pmaports.
Note: Currently only providers from a single APKBUILD are returned.
:param provide: the (virtual) package to search providers for
:returns: tuple list (pkgname, apkbuild_pkg) with providers, sorted by
provider_priority. The provider with the highest priority
(which would be selected by default) comes first.
"""
providers = {}
apkbuild = get(args, provide)
for subpkgname, subpkg in apkbuild["subpackages"].items():
for provides in subpkg["provides"]:
# Strip provides version (=$pkgver-r$pkgrel)
if provides.split("=", 1)[0] == provide:
providers[subpkgname] = subpkg
return sorted(providers.items(), reverse=True,
key=lambda p: p[1].get('provider_priority', 0))
def get_repo(args, pkgname, must_exist=True):
""" Get the repository folder of an aport.
@ -222,3 +271,19 @@ def check_arches(arches, arch):
if value in arches:
return True
return False
def get_channel_new(channel):
""" Translate legacy channel names to the new ones. Legacy names are still
supported for compatibility with old branches (pmb#2015).
:param channel: name as read from pmaports.cfg or channels.cfg, like
"edge", "v21.03" etc., or potentially a legacy name
like "stable".
:returns: name in the new format, e.g. "edge" or "v21.03"
"""
legacy_cfg = pmb.config.pmaports_channels_legacy
if channel in legacy_cfg:
ret = legacy_cfg[channel]
logging.verbose(f"Legacy channel '{channel}' translated to '{ret}'")
return ret
return channel

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Functions that work with binary package repos. See also:
@ -15,7 +15,7 @@ import pmb.helpers.run
def hash(url, length=8):
"""
Generate the hash, that APK adds to the APKINDEX and apk packages
Generate the hash that APK adds to the APKINDEX and apk packages
in its apk cache folder. It is the "12345678" part in this example:
"APKINDEX.12345678.tar.gz".
@ -43,10 +43,10 @@ def hash(url, length=8):
def urls(args, user_repository=True, postmarketos_mirror=True, alpine=True):
"""
Get a list of repository URLs, as they are in /etc/apk/repositories.
:param user_repository: add /mnt/pmbootstrap-packages
:param user_repository: add /mnt/pmbootstrap/packages
:param postmarketos_mirror: add postmarketos mirror URLs
:param alpine: add alpine mirror URLs
:returns: list of mirror strings, like ["/mnt/pmbootstrap-packages",
:returns: list of mirror strings, like ["/mnt/pmbootstrap/packages",
"http://...", ...]
"""
ret = []
@ -59,7 +59,7 @@ def urls(args, user_repository=True, postmarketos_mirror=True, alpine=True):
# Local user repository (for packages compiled with pmbootstrap)
if user_repository:
ret.append("/mnt/pmbootstrap-packages")
ret.append("/mnt/pmbootstrap/packages")
# Upstream postmarketOS binary repository
if postmarketos_mirror:
@ -96,7 +96,7 @@ def apkindex_files(args, arch=None, user_repository=True, pmos=True,
:returns: list of absolute APKINDEX.tar.gz file paths
"""
if not arch:
arch = args.arch_native
arch = pmb.config.arch_native
ret = []
# Local user repository (for packages compiled with pmbootstrap)
@ -127,9 +127,9 @@ def update(args, arch=None, force=False, existing_only=False):
# Skip in offline mode, only show once
cache_key = "pmb.helpers.repo.update"
if args.offline:
if not args.cache[cache_key]["offline_msg_shown"]:
if not pmb.helpers.other.cache[cache_key]["offline_msg_shown"]:
logging.info("NOTE: skipping package index update (offline mode)")
args.cache[cache_key]["offline_msg_shown"] = True
pmb.helpers.other.cache[cache_key]["offline_msg_shown"] = True
return False
# Architectures and retention time
@ -151,7 +151,7 @@ def update(args, arch=None, force=False, existing_only=False):
# Find update reason, possibly skip non-existing or known 404 files
reason = None
if url_full in args.cache[cache_key]["404"]:
if url_full in pmb.helpers.other.cache[cache_key]["404"]:
# We already attempted to download this file once in this
# session
continue
@ -179,16 +179,18 @@ def update(args, arch=None, force=False, existing_only=False):
" (" + str(len(outdated)) + " file(s))")
# Download and move to right location
for url, target in outdated.items():
for (i, (url, target)) in enumerate(outdated.items()):
pmb.helpers.cli.progress_print(args, i / len(outdated))
temp = pmb.helpers.http.download(args, url, "APKINDEX", False,
logging.DEBUG, True)
if not temp:
args.cache[cache_key]["404"].append(url)
pmb.helpers.other.cache[cache_key]["404"].append(url)
continue
target_folder = os.path.dirname(target)
if not os.path.exists(target_folder):
pmb.helpers.run.root(args, ["mkdir", "-p", target_folder])
pmb.helpers.run.root(args, ["cp", temp, target])
pmb.helpers.cli.progress_flush(args)
return True
@ -207,7 +209,7 @@ def alpine_apkindex_path(args, repo="main", arch=None):
raise RuntimeError("Invalid Alpine repository: " + repo)
# Download the file
arch = arch or args.arch_native
arch = arch or pmb.config.arch_native
update(args, arch)
# Find it on disk

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging

View File

@ -1,40 +1,10 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import shlex
import pmb.helpers.run_core
def flat_cmd(cmd, working_dir=None, env={}):
"""
Convert a shell command passed as list into a flat shell string with
proper escaping.
:param cmd: command as list, e.g. ["echo", "string with spaces"]
:param working_dir: when set, prepend "cd ...;" to execute the command
in the given working directory
:param env: dict of environment variables to be passed to the command, e.g.
{"JOBS": "5"}
:returns: the flat string, e.g.
echo 'string with spaces'
cd /home/pmos;echo 'string with spaces'
"""
# Merge env and cmd into escaped list
escaped = []
for key, value in env.items():
escaped.append(key + "=" + shlex.quote(value))
for i in range(len(cmd)):
escaped.append(shlex.quote(cmd[i]))
# Prepend working dir
ret = " ".join(escaped)
if working_dir:
ret = "cd " + shlex.quote(working_dir) + ";" + ret
return ret
def user(args, cmd, working_dir=None, output="log", output_return=False,
check=None, env={}, kill_as_root=False):
check=None, env={}, sudo=False):
"""
Run a command on the host system as user.
@ -54,15 +24,15 @@ def user(args, cmd, working_dir=None, output="log", output_return=False,
# Add environment variables and run
if env:
cmd = ["sh", "-c", flat_cmd(cmd, env=env)]
cmd = ["sh", "-c", pmb.helpers.run_core.flat_cmd(cmd, env=env)]
return pmb.helpers.run_core.core(args, msg, cmd, working_dir, output,
output_return, check, kill_as_root)
output_return, check, sudo)
def root(args, cmd, working_dir=None, output="log", output_return=False,
check=None, env={}):
"""
Run a command on the host system as root, with sudo.
Run a command on the host system as root, with sudo or doas.
:param env: dict of environment variables to be passed to the command, e.g.
{"JOBS": "5"}
@ -71,7 +41,8 @@ def root(args, cmd, working_dir=None, output="log", output_return=False,
arguments and the return value.
"""
if env:
cmd = ["sh", "-c", flat_cmd(cmd, env=env)]
cmd = ["sudo"] + cmd
cmd = ["sh", "-c", pmb.helpers.run_core.flat_cmd(cmd, env=env)]
cmd = pmb.config.sudo(cmd)
return user(args, cmd, working_dir, output, output_return, check, env,
True)

View File

@ -1,12 +1,14 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import fcntl
import logging
import os
import selectors
import shlex
import subprocess
import sys
import threading
import time
import os
import pmb.helpers.run
""" For a detailed description of all output modes, read the description of
@ -14,13 +16,42 @@ import pmb.helpers.run
called by core(). """
def sanity_checks(output="log", output_return=False, check=None,
kill_as_root=False):
def flat_cmd(cmd, working_dir=None, env={}):
"""
Convert a shell command passed as list into a flat shell string with
proper escaping.
:param cmd: command as list, e.g. ["echo", "string with spaces"]
:param working_dir: when set, prepend "cd ...;" to execute the command
in the given working directory
:param env: dict of environment variables to be passed to the command, e.g.
{"JOBS": "5"}
:returns: the flat string, e.g.
echo 'string with spaces'
cd /home/pmos;echo 'string with spaces'
"""
# Merge env and cmd into escaped list
escaped = []
for key, value in env.items():
escaped.append(key + "=" + shlex.quote(value))
for i in range(len(cmd)):
escaped.append(shlex.quote(cmd[i]))
# Prepend working dir
ret = " ".join(escaped)
if working_dir:
ret = "cd " + shlex.quote(working_dir) + ";" + ret
return ret
def sanity_checks(output="log", output_return=False, check=None):
"""
Raise an exception if the parameters passed to core() don't make sense
(all parameters are described in core() below).
"""
if output not in ["log", "stdout", "interactive", "tui", "background"]:
vals = ["log", "stdout", "interactive", "tui", "background", "pipe"]
if output not in vals:
raise RuntimeError("Invalid output value: " + str(output))
# Prevent setting the check parameter with output="background".
@ -33,19 +64,25 @@ def sanity_checks(output="log", output_return=False, check=None,
if output_return and output in ["tui", "background"]:
raise RuntimeError("Can't use output_return with output: " + output)
if kill_as_root and output in ["interactive", "tui", "background"]:
raise RuntimeError("Can't use kill_as_root with output: " + output)
def background(args, cmd, working_dir=None):
def background(cmd, working_dir=None):
""" Run a subprocess in background and redirect its output to the log. """
ret = subprocess.Popen(cmd, stdout=args.logfd, stderr=args.logfd,
cwd=working_dir)
logging.debug("Started process in background with PID " + str(ret.pid))
ret = subprocess.Popen(cmd, stdout=pmb.helpers.logging.logfd,
stderr=pmb.helpers.logging.logfd, cwd=working_dir)
logging.debug(f"New background process: pid={ret.pid}, output=background")
return ret
def pipe_read(args, process, output_to_stdout=False, output_return=False,
def pipe(cmd, working_dir=None):
""" Run a subprocess in background and redirect its output to a pipe. """
ret = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stdin=subprocess.DEVNULL,
stderr=pmb.helpers.logging.logfd, cwd=working_dir)
logging.verbose(f"New background process: pid={ret.pid}, output=pipe")
return ret
def pipe_read(process, output_to_stdout=False, output_return=False,
output_return_buffer=False):
"""
Read all available output from a subprocess and copy it to the log and
@ -63,7 +100,7 @@ def pipe_read(args, process, output_to_stdout=False, output_return=False,
# Copy available output
out = process.stdout.readline()
if len(out):
args.logfd.buffer.write(out)
pmb.helpers.logging.logfd.buffer.write(out)
if output_to_stdout:
sys.stdout.buffer.write(out)
if output_return:
@ -71,21 +108,21 @@ def pipe_read(args, process, output_to_stdout=False, output_return=False,
continue
# No more output (flush buffers)
args.logfd.flush()
pmb.helpers.logging.logfd.flush()
if output_to_stdout:
sys.stdout.flush()
return
def kill_process_tree(args, pid, ppids, kill_as_root):
def kill_process_tree(args, pid, ppids, sudo):
"""
Recursively kill a pid and its child processes
:param pid: process id that will be killed
:param ppids: list of process id and parent process id tuples (pid, ppid)
:param kill_as_root: use sudo to kill the process
:param sudo: use sudo to kill the process
"""
if kill_as_root:
if sudo:
pmb.helpers.run.root(args, ["kill", "-9", str(pid)],
check=False)
else:
@ -94,32 +131,32 @@ def kill_process_tree(args, pid, ppids, kill_as_root):
for (child_pid, child_ppid) in ppids:
if child_ppid == str(pid):
kill_process_tree(args, child_pid, ppids, kill_as_root)
kill_process_tree(args, child_pid, ppids, sudo)
def kill_command(args, pid, kill_as_root):
def kill_command(args, pid, sudo):
"""
Kill a command process and recursively kill its child processes
:param pid: process id that will be killed
:param kill_as_root: use sudo to kill the process
:param sudo: use sudo to kill the process
"""
cmd = ["ps", "-e", "-o", "pid=,ppid=", "--noheaders"]
cmd = ["ps", "-e", "-o", "pid,ppid"]
ret = subprocess.run(cmd, check=True, stdout=subprocess.PIPE)
ppids = []
proc_entries = ret.stdout.decode("utf-8").rstrip().split('\n')
proc_entries = ret.stdout.decode("utf-8").rstrip().split('\n')[1:]
for row in proc_entries:
items = row.split()
if len(items) != 2:
raise RuntimeError("Unexpected ps output: " + row)
ppids.append(items)
kill_process_tree(args, pid, ppids, kill_as_root)
kill_process_tree(args, pid, ppids, sudo)
def foreground_pipe(args, cmd, working_dir=None, output_to_stdout=False,
output_return=False, output_timeout=True,
kill_as_root=False):
sudo=False, stdin=None):
"""
Run a subprocess in foreground with redirected output and optionally kill
it after being silent for too long.
@ -131,7 +168,7 @@ def foreground_pipe(args, cmd, working_dir=None, output_to_stdout=False,
:param output_timeout: kill the process when it doesn't print any output
after a certain time (configured with --timeout)
and raise a RuntimeError exception
:param kill_as_root: use sudo to kill the process when it hits the timeout
:param sudo: use sudo to kill the process when it hits the timeout
:returns: (code, output)
* code: return code of the program
* output: ""
@ -139,7 +176,8 @@ def foreground_pipe(args, cmd, working_dir=None, output_to_stdout=False,
"""
# Start process in background (stdout and stderr combined)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=working_dir)
stderr=subprocess.STDOUT, cwd=working_dir,
stdin=stdin)
# Make process.stdout non-blocking
handle = process.stdout.fileno()
@ -165,15 +203,15 @@ def foreground_pipe(args, cmd, working_dir=None, output_to_stdout=False,
str(args.timeout) + " seconds. Killing it.")
logging.info("NOTE: The timeout can be increased with"
" 'pmbootstrap -t'.")
kill_command(args, process.pid, kill_as_root)
kill_command(args, process.pid, sudo)
continue
# Read all currently available output
pipe_read(args, process, output_to_stdout, output_return,
pipe_read(process, output_to_stdout, output_return,
output_buffer)
# There may still be output after the process quit
pipe_read(args, process, output_to_stdout, output_return, output_buffer)
pipe_read(process, output_to_stdout, output_return, output_buffer)
# Return the return code and output (the output gets built as list of
# output chunks and combined at the end, this is faster than extending the
@ -195,8 +233,55 @@ def foreground_tui(cmd, working_dir=None):
return process.wait()
def check_return_code(args, code, log_message):
"""
Check the return code of a command.
:param code: exit code to check
:param log_message: simplified and more readable form of the command, e.g.
"(native) % echo test" instead of the full command with
entering the chroot and more escaping
:raises RuntimeError: when the code indicates that the command failed
"""
if code:
logging.debug("^" * 70)
logging.info("NOTE: The failed command's output is above the ^^^ line"
" in the log file: " + args.log)
raise RuntimeError(f"Command failed (exit code {str(code)}): " +
log_message)
def sudo_timer_iterate():
"""
Run sudo -v and schedule a new timer to repeat the same.
"""
if pmb.config.which_sudo() == "sudo":
subprocess.Popen(["sudo", "-v"]).wait()
else:
subprocess.Popen(pmb.config.sudo(["true"])).wait()
timer = threading.Timer(interval=60, function=sudo_timer_iterate)
timer.daemon = True
timer.start()
def sudo_timer_start():
"""
Start a timer to call sudo -v periodically, so that the password is only
needed once.
"""
if "sudo_timer_active" in pmb.helpers.other.cache:
return
pmb.helpers.other.cache["sudo_timer_active"] = True
sudo_timer_iterate()
def core(args, log_message, cmd, working_dir=None, output="log",
output_return=False, check=None, kill_as_root=False, disable_timeout=False):
output_return=False, check=None, sudo=False, disable_timeout=False):
"""
Run a command and create a log entry.
@ -215,41 +300,57 @@ def core(args, log_message, cmd, working_dir=None, output="log",
"stdout", "interactive", "background"), so it's easy to
trace what pmbootstrap does.
The exception is "tui" (text-based user interface), where
The exceptions are "tui" (text-based user interface), where
it does not make sense to write to the log file (think of
ncurses UIs, such as "menuconfig").
ncurses UIs, such as "menuconfig") and "pipe" where the
output is written to a pipe for manual asynchronous
consumption by the caller.
When the output is not set to "interactive", "tui" or
"background", we kill the process if it does not output
anything for 5 minutes (time can be set with "pmbootstrap
--timeout").
When the output is not set to "interactive", "tui",
"background" or "pipe", we kill the process if it does not
output anything for 5 minutes (time can be set with
"pmbootstrap --timeout").
The table below shows all possible values along with
their properties. "wait" indicates that we wait for the
process to complete.
output value | timeout | out to log | out to stdout | wait
-----------------------------------------------------------
"log" | x | x | | x
"stdout" | x | x | x | x
"interactive" | | x | x | x
"tui" | | | x | x
"background" | | x | |
output value | timeout | out to log | out to stdout | wait | pass stdin
------------------------------------------------------------------------
"log" | x | x | | x |
"stdout" | x | x | x | x |
"interactive" | | x | x | x | x
"tui" | | | x | x | x
"background" | | x | | |
"pipe" | | | | |
:param output_return: in addition to writing the program's output to the
destinations above in real time, write to a buffer
and return it as string when the command has
completed. This is not possible when output is
"background" or "tui".
"background", "pipe" or "tui".
:param check: an exception will be raised when the command's return code
is not 0. Set this to False to disable the check. This
parameter can not be used when the output is "background".
:param kill_as_root: use sudo to kill the process when it hits the timeout.
parameter can not be used when the output is "background" or
"pipe".
:param sudo: use sudo to kill the process when it hits the timeout.
:returns: * program's return code (default)
* subprocess.Popen instance (output is "background")
* subprocess.Popen instance (output is "background" or "pipe")
* the program's entire output (output_return is True)
"""
sanity_checks(output, output_return, check, kill_as_root)
sanity_checks(output, output_return, check)
# Preserve proxy environment variables
env = {}
for var in ["FTP_PROXY", "ftp_proxy", "HTTP_PROXY", "http_proxy",
"HTTPS_PROXY", "https_proxy", "HTTP_PROXY_AUTH"]:
if var in os.environ:
env[var] = os.environ[var]
if env:
cmd = ["sh", "-c", flat_cmd(cmd, env=env)]
if args.sudo_timer and sudo:
sudo_timer_start()
# Log simplified and full command (pmbootstrap -v)
logging.debug(log_message)
@ -257,7 +358,11 @@ def core(args, log_message, cmd, working_dir=None, output="log",
# Background
if output == "background":
return background(args, cmd, working_dir)
return background(cmd, working_dir)
# Pipe
if output == "pipe":
return pipe(cmd, working_dir)
# Foreground
output_after_run = ""
@ -271,18 +376,18 @@ def core(args, log_message, cmd, working_dir=None, output="log",
output_to_stdout = True
output_timeout = output in ["log", "stdout"] and not disable_timeout
stdin = subprocess.DEVNULL if output in ["log", "stdout"] else None
(code, output_after_run) = foreground_pipe(args, cmd, working_dir,
output_to_stdout,
output_return,
output_timeout,
kill_as_root)
sudo, stdin)
# Check the return code
if code and check is not False:
logging.debug("^" * 70)
logging.info("NOTE: The failed command's output is above the ^^^ line"
" in the log file: " + args.log)
raise RuntimeError("Command failed: " + log_message)
if check is not False:
check_return_code(args, code, log_message)
# Return (code or output string)
return output_after_run if output_return else code

View File

@ -1,4 +1,4 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import logging
@ -92,7 +92,7 @@ def print_checks_git_repo(args, repo, details=True):
log_ok("up to date with remote branch")
# Outdated remote information
if pmb.helpers.git.is_outdated(args, path):
if pmb.helpers.git.is_outdated(path):
return log_nok_ret(-5, "outdated remote information",
"update with 'pmbootstrap pull'")
log_ok("remote information updated recently (via git fetch/pull)")
@ -121,7 +121,7 @@ def print_checks_chroots_outdated(args, details):
:returns: list of unresolved checklist items """
if pmb.config.workdir.chroots_outdated(args):
logging.info("[NOK] Chroots not zapped recently")
return ["Run 'pmbootststrap zap' to delete possibly outdated chroots"]
return ["Run 'pmbootstrap zap' to delete possibly outdated chroots"]
elif details:
logging.info("[OK ] Chroots zapped recently (or non-existing)")
return []

View File

@ -1,4 +1,4 @@
# Copyright 2020 Clayton Craft
# Copyright 2023 Clayton Craft
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import glob
@ -12,9 +12,11 @@ def list(args, arch):
:param arch: device architecture, for which the UIs must be available
:returns: [("none", "No graphical..."), ("weston", "Wayland reference...")]
"""
ret = [("none", "No graphical environment")]
ret = [("none", "Bare minimum OS image for testing and manual"
" customization. The \"console\" UI should be selected if"
" a graphical UI is not desired.")]
for path in sorted(glob.glob(args.aports + "/main/postmarketos-ui-*")):
apkbuild = pmb.parse.apkbuild(args, path + "/APKBUILD")
apkbuild = pmb.parse.apkbuild(f"{path}/APKBUILD")
ui = os.path.basename(path).split("-", 2)[2]
if pmb.helpers.package.check_arch(args, apkbuild["pkgname"], arch):
ret.append((ui, apkbuild["pkgdesc"]))

View File

@ -1,7 +1,9 @@
# Copyright 2020 Oliver Smith
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb.install._install import install
from pmb.install._install import get_kernel_package
from pmb.install.partition import partition
from pmb.install.partition import partition_cgpt
from pmb.install.format import format
from pmb.install.format import get_root_filesystem
from pmb.install.partition import partitions_mount

Some files were not shown because too many files have changed in this diff Show More