Commit Graph

157 Commits

Author SHA1 Message Date
Martchus b981c6afe8 Add builduser to same groups as on host
This prevents permission errors when relying on a user's group
for accessing certain files (made available within the container
via bind mounts).
2021-07-20 18:33:39 +02:00
Martchus 83958da9c3 Set TERM within the systemd-nspawn container in makechrootpkg
This is required by WINE to prevent
```
unknown: I need something more specific
```
2021-02-20 18:37:38 +01:00
Kevin Mihelich d5407ee173 makechrootpkg: don't delete MAKEFLAGS and PACKAGER 2021-02-20 18:37:38 +01:00
Kevin Mihelich b538ea0d49 makechrootpkg: no default logging 2021-02-20 18:37:38 +01:00
Kevin Mihelich d508ffe8a4 arch-nspawn: arm fix 2021-02-20 18:37:38 +01:00
Kevin Mihelich 5fc2939bb1 makechrootpkg: distcc 2021-02-20 18:37:38 +01:00
Kevin Mihelich 319343770a makechrootpkg: cache dir 2021-02-20 18:37:38 +01:00
Levente Polyak 8c26438df8
makechrootpkg: only expose failed build logs instead of products
After further followups always moving all products isn't actually
desired as they can theoretically be broken in various ways if
arch-nspawn exists non successful.

However, as we would like to always preserve the produced log files we
instead split out the logfiles into an own function and call that for
unsuccessful buils.

Fixes 4f305aa3
2021-01-31 23:44:11 +01:00
bartoszek 4f305aa316
makechrootpkg: Expose failed build logs/products
Since move_products() function is fairly robust we can make it run for
failed build also to expose logs for packages that fails in build(),
prepare() or package(). It also exposes partially packaged split
packages if they fail in latter package_xxx().
2021-01-26 20:43:29 +01:00
Eli Schwartz e963b6da9e
makechrootpkg: use the chroot database to find checkpkg packages
We don't want to check against the current version known to the host
system, because that will be incorrect in a wide variety of situations,
including:
- the build host hasn't done a full system upgrade yet
- we're building against staging, and want to see the delta between
  different staging versions
- we're building against extra, but the host runs testing which carries
  changes we don't want to visualize right now
- the chroot has a configured database not available to the host, and
  the package is only available there

Essentially, it's rarely 100% correct to run checkpkg on the host, but
we already have a database we *know* is correct, and that is the one we
just built the package against. So let's use that.

This also fixes a bug in the current logic, where in order to try
downloading fresh databases, we work in a non-cached temporary working
database to download the package files, but then let checkpkg default to
comparing packages in the system database. Since we are explicitly
trying to compare against packages that differ from the host's pacman
database, we need to pass the package files as options to checkpkg,
using the additional modes added in commit c14338c0fe

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2020-02-27 14:50:19 +01:00
Levente Polyak f20435643f
makechrootpkg: sync databases for checkpkg off-site
Use pacman's --dbpath feature to sync fresh databases inside an isolated
location and split up the database sync and package location calls to
remove the need of weird grep calls.

It isn't nice of makechrootpkg to modify the host database state just by
building packages. No foreign program shall automatically modify
the host database other than by the explicit will of a system
maintainer, which is the major reason this changes get incorporated.

However, there is certain indoctrinated believe that using -Sy is
the prime evil. In fact it has been declared as a social rule to a
technical problem of not getting into potential partial upgrade states.
This is not a proper loophole less solution as there are multiple ways
and use cases that lead to such a state, like aborting a -Syu on the
prompt for whatever reason, what really matters is that it is not a
technically bullet proof solution to solve the problem.

Databases shall have the freedom to be as up to date as databases or
their owner wishes, allowing querying on latest database state without
fear. The only loophole-less contract that _really_ is from importance
is always using -Su instead of plain -S to install packages. Installing
packages is what actually brings one into a potential partial upgrade
state and by using -Su an outstanding upgrade is forced when installing
a new package. This properly solves all edge cases in a technical
manner instead of declaring people who abort the prompt of -Syu to be
the problem. In fact, using this simple contract allows whatever system
maintenance workflow a host owner wants to follow, which may still be to
always use -Syu and deal with system upgrades explicitly instead of the
time when installing new packages, but the -Su contract is the real safe
guard to guarantee no edge case can ever slip in. This magically also
opens up the freedom to people who wish to use -Sy to simply query on up
to date data as the currently indoctrinated "never do -Sy" stone plates
not only are not rock solid in technical terms but also make certain use
cases simply impossible and hence cripple the functionality without at
the very least being fully loophole free.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-12-05 22:50:11 +01:00
Levente Polyak 8d99df602d
makechrootpkg: double quote array expansions for checkpkg locations
Avoid re-splitting remotepkg elements used for checkpkg conditions.
2019-11-30 13:44:02 +01:00
Levente Polyak 104c5bc90e
makechrootpkg: sync database for checkpkg to avoid nonexistent targets
For build servers or similar infrastructure its relatively common to not
sync/update the database regularly. This leads to problems properly
running checkpkg duo to nonexistent target files that we try to
download. As building on build servers is a very common use case, lets
ensure we sync the local database before trying to resolve the package
locations.
2019-11-30 13:25:06 +01:00
Levente Polyak cee28a1b13
makechrootpkg: check local pkg versions before downloading for checkpkg
Avoid always trying to download and output the according message.
Add checks for packages either not being available in the repo or
all variants have up to date versions stored in the local cache.
2019-11-30 13:25:06 +01:00
Eli Schwartz 751093eff2
use libmakepkg to find and use variables in makepkg.conf
- drop homebrew function in makechrootpkg
- use better mock to find invoking user's $HOME
- make offload-build respect makepkg.conf to determine where to sync
  files, matching the behavior of makechrootpkg

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-11-07 21:28:21 +01:00
Levente Polyak 5dd90ef848
checkpkg: add option to print a warning in case of differences
Sometimes its desired to be explicitly made aware of differences
reporter by checkpkg via printing a warning instead of a regular
message.

Automatically use --warn for makechrootpkg builds so packagers are made
visibly aware of a soname bump by simply looking out for colors
indicating non success messages.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-09-28 00:15:51 +02:00
Levente Polyak 5246cb9aa5
checkpkg: add option to avoid keeping the tmp dir
In some cases, like default makechrootpkg execution, the temporary
directory used to assemble the differences is not required. Add an
option to checkpkg that allows to get rid of that directory after
run and call it automatically like that in makechrootpkg.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-09-28 00:15:48 +02:00
Levente Polyak 144f896660
makechrootpkg: run checkpkg automatically after build
Cache previous versions required for checkpkg via pacman to avoid
multiple downloads when running multiple times.

In case we can't download the packages, like while building out of repo
packages, print a warning instead of running checkpkg

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-09-28 00:15:33 +02:00
Eli Schwartz 6e466ca654
Revert "makechrootpkg: with -n, check if the package failed to install"
This reverts commit be44b9cde1.

This was a nice idea in theory, because it means that we can catch
conflicting files before releasing them into the repos. In practice,
there were unanticipated side effects: single-package installs which
conflict against their own makedepends cannot be installed either.
Examples include:
- kernel modules which makedepend on their dkms equivalent
- jack2, which makedepends/optdepends on portaudio, which requires
  jack... but jack2 is a drop-in provides/conflicts jack.

We cannot reliably detect when makepkg --install will error out because
of dependency conflicts vs. packages which are simply broken. So, back
out this change for now.

Revisit this once pacutils has a new release, because it will add the
option --resolve-conflicts=all, allowing for much better scripted
responses to "foo conflicts with bar, remove bar? [y/N]" than simply
"--noconfirm and fail".

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-09-12 21:29:42 +02:00
Eli Schwartz be44b9cde1
makechrootpkg: with -n, check if the package failed to install
We previously whitelisted this return code because split packages can
frequently conflict each other, so makepkg -i is *expected* to fail in
such a case. However, there is no good reason to let this succeed if the
pkgbase only builds one pkgname -- that will always be a severe issue.

Add a check for how many split

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:54 +02:00
Eli Schwartz 7b0a11677a
makechrootpkg: make the -U option work for the first time ever
The -U option was initially introduced in commit
cda9cf436b in order to enable running
makechrootpkg as root, delegating to another, manually selected, user to
perform various non-root tasks (given that makepkg was modified to throw
fatal errors when run as root without the option of --asroot to disable
that). However, it was only ever implemented for the --verifysource
option outside of the chroot, and the builduser inside the chroot is
created with the same uid as the makechrootpkg invoker. It needs to run
as the same uid, because it needs rw access to $startdir and $SRCDEST!
Additionally this lets the invoking user more easily inspect the build
directory in case of problems...

The correct solution for this is to properly implement the initial
intention of the -U option, and make it override the autodetection of
the "invoking user" which is normally done by inspecting $SUDO_USER.
This is then used as the single source of truth for "who am I pretending
to be".

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:53 +02:00
Eli Schwartz 8e4293034b
makechrootpkg: also downgrade packages when updating chroots
Packages should never be getting downgraded... unless a package is
pulled from testing, e.g. for example if gcc9 totally breaks the linux
kernel. In such cases, the master repo says there is a downgrade, so
we'd better go with that. Basically, ensure that packages match the repo
they are being built against. Consistency at all costs!

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:53 +02:00
Eli Schwartz b7893a2ca8
makechrootpkg: when installing with -I, ensure package is installed
noconfirm is wrong here, as we don't want to accept the default answer
-- we want to install the new package, even if it conflicts and provides
an existing one. After all, we explicitly asked for it.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:53 +02:00
Eli Schwartz 5fcd90a212
makechrootpkg: accept arguments useful to verifysource
And pass them on to download_sources outside the chroot.

Fixes FS#35652

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:52 +02:00
Eli Schwartz f6f4da26cb
makechrootpkg: fix breakage in makepkg option parsing
In commit bd826752c9, support for short
options was added to the heuristic for --noextract, but in the process,
we changed to loop over the set of user options plus the builtin
defaults for inside the chroot. This was wrong, as we only care about
the user options -- moreover, it prevents us from adding verifysource
support *outside* the chroot, for options that are also chroot options,
like --holdver.

Also remove uselessly duplicated line.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:52 +02:00
Eli Schwartz 74a6641946
Escape paths with ":" that are passed to systemd-nspawn --bind
When parsing paths to automatically make available to the container, the
":" is used internally by systemd-nspawn to signify destinations in the
container. Replace automatically with "\:" for the mounts that we set
up, in order to safely handle a working directory etc. that contains
this character.

For bind options exposed to the user, it is assumed the user takes care
of passing systemd-nspawn compatible paths themselves.

Fixes FS#60845

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:52 +02:00
Eli Schwartz 8dbf95cdd4
makechrootpkg: check truthiness using shell arithmetic
Using the literal strings "true" and "false" is inaccurate and may
result in uncertainty of whether it is set when doing string comparison,
or simply rely on the shell implementation of treating the string as a
command builtin, then executing the value as a shell command. Emulate
makepkg, which makes heavy use of shell arithmetic for this purpose.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:52 +02:00
Eli Schwartz 46d614d91a
Revert "makechrootpkg: Have functions be more function-y."
This reverts (the bulk of) commit 2fd5931a8c.

Reducing globals makes little sense in in a oneshot bash script, but
reduces code clarity and in fact resulted in bugs because even the
commit author couldn't keep track of the script state.

An exit was changed to a return, even though that made no sense outside
of a function, and has been duly returned to being an exit. This was
never tested and later papered over by wrapping the entire script in a
main() function and then calling the function for hysterical raisins.

The functiony nature of sync_chroot/delete_chroot is preserved, as those
functions demonstrate meaningfully standalone functionality -- who
knows? we may want to reuse this. Everything else is tightly bound to
the internal logic of makechrootpkg.

Completely separate functionality that was silently implemented in the
original commit is also preserved:
- declare a couple of variables as locals
- move the abort-on-no-PKGBUILD outside the install_packages function

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:51 +02:00
Eli Schwartz df0d6b867b
Revert "makechrootpkg: Avoid having code floating around outside of a function."
This reverts commit 49088b0860.

The fundamental intention was flawed and broken, it caused annoying
issues and regressions, and the self-avowed sole purpose of the change
was so that a downstream project could *post-modify the script and
source it as a library*.

That is not okay. You don't wrap non-factorable code in a function
called main() and call it a library. The only possible use for this is
to treat makechrootpkg *internals* as a library, which is not supported.

Downstream projects that wish to use the functionality of makechrootpkg
should treat makepkg as a command with a public API in the form of
command line options. That is kind of how commands of all kinds work,
since forever. That is how all users of makechrootpkg *except for
parabola* use it.

Arguments that "it saves us the cost of fork+exec to bash" are simply
invalid.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:41:51 +02:00
Eli Schwartz b7ce90fefc
makechrootpkg: load makepkg.conf variables correctly
Since makepkg.conf is a bash-compatible configuration file, it must be
sourced.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:40:05 +02:00
Eli Schwartz via arch-projects ad4b66830a
Revert "makechrootpkg: sync_chroot: Make more general."
This reverts commit 6d1992909c.

It has never worked. In commit c86823a2d4
it was noted that it compared the device numbers for [[ $1 = $1 ]] which
was a useless check and always returned true, for *any* btrfs
filesystem. Now that the function is corrected to compare [[ $1 = $2 ]]
the check is still useless, but this time because it always returns
false -- btrfs subvolumes on the same filesystem do *not* share device
numbers.

So let's go back to the original working implementation that only
matters in terms of makechrootpkg, and just checks if makechrootpkg's
root working directory is btrfs (in which case we know it will be a
subvolume because mkarchroot will create it that way).

This restores our special support for the btrfs filesystem.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
2019-06-12 23:42:05 +02:00
Matt Robinson 155798b8b1
makechrootpkg: keep *DEST, MAKEFLAGS & PACKAGER
If makechrootpkg is called as non-root, the {SRC,SRCPKG,PKG,LOG}DEST,
MAKEFLAGS and PACKAGER environment variables are lost in the call to
check_root().

Add these to the passed keepenv list so that they are preserved instead.
2019-03-25 23:32:13 +01:00
Erich Eckner 8310abb348
remove empty tree if "--verifysource" failed
makechrootpkg's download_sources() leaves a stray directory if
"makepkg --verifysource" failed. We use "setup_workdir" instead
of "mktemp -d", because this ensures the correct garbage collection.

Signed-off-by: Erich Eckner <git@eckner.net>
2019-01-22 01:44:40 +01:00
Eli Schwartz via arch-projects 98ff92f467
makechrootpkg: whitelist return code 14 from makepkg
makepkg 5.1 implements error codes, and 14 means that installing the
packages after they were built has failed. We don't care about this
error and would like makechrootpkg to succeed regardless, e.g. for split
packages that are mutually exclusive.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
2018-05-31 16:03:13 +02:00
Eli Schwartz 7fcf847bc3 Do not assume the makechrootpkg user's groupname is the same as the username
chown support "$user:$group" but also "$user:" which infers $group
rather than leaving it as root. This looks up the group name in cases
where the default group is e.g. "users" and users do not get their own
unique groups.
2018-05-16 10:37:55 -04:00
Eli Schwartz 509c00ea23 makechrootpkg: Do not copy the user keyring into the chroot.
Since commit 75fdff1811 we no longer run
integrity checks inside the chroot anyway, so this is no longer needed
and will never be used.
2018-05-13 09:16:20 -04:00
Evangelos Foutras 5713cd629c makechrootpkg: add /etc/shadow entry for builduser
Without it, sudo 1.8.23 will return an error:

    sudo: PAM account management error: Authentication
    service cannot retrieve authentication info
2018-05-12 11:52:18 +03:00
Eli Schwartz 40f0179a5e makechrootpkg: fix verifysource with pacman-git
In pacman-git commit d8717a6a9666ec80c8645d190d6f9c7ab73084ac makepkg
started checking that the setuid/setgid bit could be removed on the
$BUILDDIR in order to prevent this propagating to the packages
themselves.  Unfortunately, this requires the temporary builddir used
during the --verifysource stage of makepkg, to be owned by $makepkg_user
which was not the case as it is created as root using mktemp (and given
world rwx in addition to the restricted deletion bit.)

Obviously makepkg cannot chmod a directory that it does not own. Fix
this by making $makepkg_user the owner of that directory, as should have
been the case all along.

(Giving world rwx is illogical on general principle. The fact that this
is a workaround for makepkg demanding these directories be writable even
when they are not going to be used for the makepkg options in question,
is not justification for being careless.)

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
2018-03-24 20:54:24 +01:00
Emiel Wiedijk ffb5003fda makechrootpkg: respect GNUPGHOME
Previously, makechrootpkg hardcoded ~/.gnupg. Therefore, if a user
uses a custom GPG home directory, the siganture checking would fail.
Now makechrootpkg uses $GNUPGHOME, with a fallback to ~/.gnupg.

Signed-off-by: Emiel Wiedijk <me@aimileus.nl>
2018-03-24 20:54:17 +01:00
Bartłomiej Piotrowski 38c7a391b0 makechrootpkg: make sure that makepkg.conf is always parsed as text 2018-01-21 14:18:43 +01:00
Luke Shumaker 75ad2aca57 makechrootpkg: Adjust to work properly with `set -e`
This worked properly until eab5aba.
2018-01-21 14:16:10 +01:00
Eli Schwartz 48b2f8dcc4 makechrootpkg: Fix anti-pattern when checking for enabled features
Don't use error-prone logic e.g.
foo=true; if $foo ...

This completely fails to act as expected when the variable is unset
because of unrelated bugs.

While this merely causes the default behavior to be "false" rather than
"true" in such cases, it is better to fail to enable explicitly
requested behavior (which will be noticed by the user) than to simply
upgrade to this behavior for free (which may not seem to have any
obvious cause).

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
2018-01-21 14:16:10 +01:00
Eli Schwartz 3b725b5843 makechrootpkg: Fix unconditionally running namcap
Fixes regression in 2fd5931a8c

$run_namcap will always be set to ""
`if $not_a_var; then ...; fi` is always truthful when $not_a_var is
unset or equal to "" and the `then` clause will always be run.

I'm not sure why global state variables need to be cloned locally for
their sole explicit purpose.

But for now this patch implements the minimum necessary work to properly
pass the "do I want namcap" variable into prepare_chroot() according to
the current logic flow.
Note that I have still not thorougly tested makechrootpkg.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
2018-01-21 14:16:10 +01:00
Evangelos Foutras 7a3c508501 Revert "makechrootpkg: Reopen console to assign the CTTY"
This reverts commit ddd508efc0.

The underlying bug (FS#56529) was fixed in glibc 2.26-9.
2017-12-27 23:33:45 +02:00
Eli Schwartz eab5aba9b0 Support reproducible builds
Recent development versions of makepkg support reproducible builds
through the environment variable SOURCE_DATE_EPOCH. Pass this variable
through makechrootpkg to makepkg when available.

Also initialize SOURCE_DATE_EPOCH whenever running archbuild to enforce
reproducible builds for repository packages.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2017-11-22 16:35:25 +01:00
Luke Shumaker 095e5305e4
makechrootpkg: Fix function usage comments
A couple of the comments noting which globals are used by functions are
outdated/wrong.

 - download_sources() : Remove USER from the list.  It was always wrong.
   Originally, it should have been SUDO_USER (not USER), but I should have
   removed it entirely in 4f23609.

 - move_products() : Add SRCPKGDEST to the list.  Though the commit adding
   the comment was only recently upstreamed (as 2fd5931), it originated in
   2013 in a commit that has since  been rebased many times.  Anyway, in
   this rebasing, it missed move_products() starting to pay attention to
   SRCPKGDEST in fd1be1b (since nothing made git think there was a
   "conflict").
2017-10-30 15:59:38 +01:00
Luke Shumaker e4db687d10
makechrootpkg: move init_variables() to be part of main()
The reason it wasn't moved before was just to keep the diffs
(with --ignore-all-space) smaller, to make merging and rebasing work
easier.  Moving code around in a file tends to make that difficult.

But, readability wise, it belongs in main().
2017-10-30 15:59:05 +01:00
Jan Alexander Steffens (heftig) ddd508efc0
makechrootpkg: Reopen console to assign the CTTY
nspawn does not give us a controlling terminal, hence we ignore
interrupts. Apparently this was lost in systemd at some point.

Hack around this by reopening the console to make it the controlling
terminal.
2017-09-14 23:33:47 +02:00
Jan Alexander Steffens (heftig) 0f3778c3d3
makechrootpkg: Prevent collecting coredumps
Coredumps from build chroots are not generally useful. Prevent
them from being generated.

Avoids a lot of annoyance from the GCC testsuite spawning lots of
systemd-coredump processes.

Just set the soft limit so the user can still raise it in the PKGBUILD
if they insist.
2017-09-14 23:31:36 +02:00
Jan Alexander Steffens (heftig) bd826752c9
makechrootpkg: Also look for -e as --noextract 2017-08-24 17:20:59 +02:00