Commit Graph

53 Commits

Author SHA1 Message Date
Eli Schwartz bcba566405
mkarchroot: support wrapping pacstrap -U
Needed to support reproducible builds.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
2019-11-30 13:21:23 +01:00
Eli Schwartz 40a90e2cab
ensure that sane umask is used where needed
If a user umask is restrictive, a chroot may be created as root without the
ability for the user to read it, which then causes makepkg
--verifysource to fail.

Do not set this in lib/common.sh, where it would apply to all scripts,
as we do not want to override the user's policy for things like $SRCDEST
files, svn checkouts, etc.

Fixes FS#47625

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 e76d560477
Revert "mkarchroot: Don't let the environment affect pacstrap (sans proxy settings)."
This reverts commit 578a62f1e0.

mkarchroot is run as root (via check_root if needed) so the environment
should already be clean. If not, the user has broken their root
environment, and we cannot support this. It's unclear what environment
settings may or may not be messing with anything, ever, but the original
bug report happened on Parabola who perform extensive patching to
"libretools" such that the code no longer resembles devtools at all.
It's therefore likely any such bug is parabola specific, but we will
never know since the original commit message states that they don't know
why they do it either.

Parsing the user's entire exported environment via both sed and grep is
overkill for a non-bug, especially when it doesn't work for variables
declared -rx and doesn't work for things like:

export fooled_you=$'wow such hax\ndeclare -x http_proxy=lol'

Also if done properly this would rely on compgen -e to print all
exported shell variables. Or even better, loop through /proc/$$/environ
which is both null-delimited and easily parsed with the read builtin and
[[ ]]

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 c2bbcbed64
mkarchroot: don't create a broken chroot by default
It's incorrect to make pacman completely useless inside the chroot by
starting off with no pacman keyring. Assuming that the only consumers of
a new chroot will be arch-nspawn (which copies over the hostconf) is
bad design, and furthermore makes it impossible to fix other issues in
arch-nspawn itself.

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 58374246c4
Migrate pacman.conf CacheDir parsing to pacman-conf
And while we're at it, make this more consistent. Currently we
unnecessarily support only one -c /path/to/cachedir option.

This requires slightly more thorough handling in mkarchroot to ensure
all custom cachedirs are passed on to arch-nspawn. Rework
to simply forward all arguments to arch-nspawn (minus final arguments
used for pacman -Sy packagelist).

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-08-09 19:39:45 +02:00
Erich Eckner 321e998020
fix whitespace/indentation errors
Some lines are indented by spaces, while adjacent lines are indentet by tabs.
We should use tabs on both.

Signed-off-by: Erich Eckner <git@eckner.net>
2019-04-20 17:58:55 +02:00
Luke Shumaker 78fabcfa06
Quote strings that shellcheck warns about.
These changes are all strictly "slap some double-quotes in there".
Anything more than that is not included in this commit.
2017-07-05 18:21:56 +02:00
Luke Shumaker 3f72579b28
Make purely stylistic changes to make shellcheck happier.
These are purely stylistic changes that make shellcheck complain less.

This does NOT include things like quoting currently unquoted variables.
2017-07-05 18:21:55 +02:00
Luke Shumaker 578a62f1e0
mkarchroot: Don't let the environment affect pacstrap (sans proxy settings).
A previous iteration of this change (libretools commit d7dcce53396d)
simply inserted `env -i` to clear the environment.

However, that lead to it ignoring proxy settings, which some users had
problems with:

    https://labs.parabola.nu/issues/487:
    > To fix other bugs, the pacstrap environment is blank, which also
    > means that the proxy settings are blank.

So (in libretools commit d17d1d82349f), I changed it to use `declare
-x` to inspect the environment, and create a version of it only
consisting of variables ending with "_proxy" (case-insensitive).

I honestly don't remember what "other bugs" prompted me to clear the
environment in the first place.
2017-04-05 22:17:51 +02:00
Luke Shumaker 5b9c06d275
mkarchroot, arch-nspawn: Add an `-s` flag to inhibit `setarch`.
This allows us to run an ARM chroot on an x86 box; as the binfmt
runner will set the architecture for us, and the x86
`/usr/bin/setarch` program won't know about the ARM architecture
string.
2017-04-05 22:17:51 +02:00
Luke Shumaker 82e6bfcd7a
mkarchroot, arch-nspawn: Add an `-f` flag to add files to copy.
This allows us to copy in files like `qemu-arm-static`, which is
necessary for running an ARM chroot on an x86 box.
2017-04-05 22:17:51 +02:00
Luke Shumaker cb35d74f8c
Avoid using string interpolation; use printf format strings instead.
This involves extending the signature of lib/common.sh's `stat_busy()`,
`lock()`, and `slock()`. The `mesg=$1; shift` in stat_busy even suggests
that this is what was originally intended from it.
2017-04-05 22:11:16 +02:00
Luke Shumaker 14d5e1c21b
Add a "License:" tag to all code files.
In cases where there is no license specified, the file is tagged as
"License: Unspecified".  Obviously, that is not ideal, but it
highlights the fact, and I hope that it encourages whoever has the
authority to specify the license to do so.

On that note, to anyone who may have the authority to specify the
license of files in devtools: the current licence of many files is
GPLv2 with no option for later versions; I impore you to re-license
them to have the "or any later version" option.
2017-04-05 22:10:03 +02:00
Jan Alexander Steffens (heftig) c53a3e8017
lib/archroot.sh: Add is_btrfs helper 2017-03-07 20:37:54 +01:00
Jan Alexander Steffens (heftig) 45f87aa9d5
lib/archroot.sh: Simplify check_root
Move the function and save the orig_argv right along it.
2017-03-07 19:35:09 +01:00
Jan Alexander Steffens (heftig) 66553e7e07
lib/archroot.sh: Move CHROOT_VERSION to a common file 2017-03-07 19:35:09 +01:00
Jan Alexander Steffens (heftig) c8147a3512
mkarchroot: Set LANG=en_US.UTF-8
In order to have an UTF-8 locale in the build root. This is something
normally set on real machines but is not set from our chroots. Meson,
for example, loudly complains when the locale charset is not UTF-8.

I'd like to have C.UTF-8, as most other distributions do. Unfortunately,
it's not part of vanilla glibc; en_US.UTF-8 will have to do.

mkarchroot already creates roots with both en_US.UTF-8 and de_DE.UTF-8,
the latter because builds of gcc (perhaps used to) require it.

Bump the CHROOT_VERSION due to the setting change.
2017-02-17 19:51:56 +01:00
Sven-Hendrik Haase 882f5d0451 mkarchroot: Manually generate machine-id because nspawn expects it 2016-05-27 22:16:09 +02:00
Dave Reisner bf7dc83bab save and reuse original argv when auto-elevating
Fixes FS#42277.
2014-10-19 16:48:03 -04:00
Luke Shumaker 625e6bd412 mkarchroot: Correct "Usage:" text.
The "app" hasn't been an option since arch-nspawn was created.
2014-09-22 08:25:43 -04:00
Sébastien Luttringer 03611dc63e Switch to root when started as regular user
In collaborative builder machine, these scripts are often allowed to become root
via sudo. This patch avoid to prefix them by sudo each time or call su.

Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2014-05-10 08:05:08 +02:00
Dave Reisner be3c71fa81 avoid injecting code into the format string
Now that die() properly forwards arguments to error(), we can expect
that the first arg is a format string and not the entirety of the
output.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2013-08-08 21:28:10 +02:00
Jan Alexander Steffens (heftig) a7a05deb37 lib/common.sh: Introduce locking helper functions
Reduces code duplication.

With makechrootpkg not calling mkarchroot anymore,
the lock handover protocol is unneeded.

arch-nspawn does not do any locking, so add protection to archbuild.
2013-05-03 04:34:29 +02:00
Jan Alexander Steffens (heftig) 453558c4bb mkarchroot: Refactor chroot running into a new script
Separates the two features of mkarchroot. Provides users of the new
arch-nspawn with the full feature set of systemd-nspawn.

For example, this can be used to bind custom directories into the chroot.
2013-05-02 10:33:24 +02:00
Pierre Schmitz 97a2d2414a mkarchroot: Fix creation of btrfs snapshot and remove force option 2013-04-07 16:05:21 +02:00
Pierre Schmitz 5085cfcdf9 Bump the chroot version as we changed the default package set 2013-04-06 19:55:58 +02:00
Pierre Schmitz 6caad191c1 Only try to use btrfs snapshots if chroots are on a btrfs partition 2013-04-06 19:50:17 +02:00
Pierre Schmitz 71b15aafb6 Simplify update call as pacman does no longer support SyncFirst 2013-04-06 18:43:01 +02:00
Pierre Schmitz 4bcafd9768 mkarchroot: code cleanup 2013-04-06 18:38:10 +02:00
Pierre Schmitz 1f0374d8a6 mkarchroot: Create working directory if needed 2013-04-06 18:32:10 +02:00
Dave Reisner f03086a0e1 use nspawn to bind mount needed directories
systemd-nspawn is capable of doing this as of systemd-198. Doing this
means we can remove all of our home grown chroot mount/umount logic, as
it's all performed by pacstrap or systemd-nspawn.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2013-04-06 18:15:14 +02:00
Pierre Schmitz 828143751b Drop initscripts support 2013-01-20 10:08:24 +01:00
Eric Bélanger 890baf6891 Make sure the usage functions are consistent
The usage messages now begins with a "Usage:", i.e. capitalized and with a colon. Fixes FS#26956.

Signed-off-by: Eric Bélanger <snowmaniscool@gmail.com>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-11-15 15:25:07 +01:00
Eric Bélanger 41b54bdde5 mkarchroot: Remove unnecessary parameter for usage function
Fixes FS#28973

Signed-off-by: Eric Bélanger <snowmaniscool@gmail.com>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-11-15 14:28:50 +01:00
Jan Alexander Steffens (heftig) fbb2bd2b8e Fix return code handling
Stop trap_exit from forcing a 0 exit code. This fixes makechrootpkg,
which used to always return success, even if the build failed.

Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-10-27 20:27:39 +02:00
Pierre Schmitz 1703b92e1a mkarchroot: do not try to bind /etc/timezone from host
/etc/timezone is no longer used. We only need /etc/localtime.

This fixes FS#31929
2012-10-13 20:33:53 +02:00
Pierre Schmitz ac1ee41e4d mkarchroot: use a helper function to simplify bind mounts 2012-10-04 19:57:19 +02:00
Pierre Schmitz c617c67ff8 mkarchroot: Use systemd's nspawn if available
* If we are running systemd use nspawn instead of our own chroot setup
* Use pacstrap to setup our chroot environment
* Make sure the common trap is still called
* Bind resolve.conf, timezone and lcoaltime from the host if nspawn is not used
* Run ldconfig within the chroot
2012-10-03 12:38:33 +02:00
Pierre Schmitz 246b8ead60 mkarchroot: reset trap so it wont be called twice 2012-06-16 16:21:55 +02:00
Allan McRae 3734c80bf7 Fix /run permissions in chroot
Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-06-15 09:27:27 +02:00
Pierre Schmitz ed9d5a16e3 Support multiple package cache directories
* We use the host package cache configuration
* As only the first cache will be written to, we mount the others readonly
2012-06-12 08:17:58 +02:00
Pierre Schmitz c5cd72c085 Remove no longer used option 2012-06-11 23:44:30 +02:00
Pierre Schmitz 8bedb89fd6 Add a version number to each chroot so we can tell the user when a rebuild is needed 2012-06-11 17:04:17 +02:00
Pierre Schmitz c7cda47342 Enable signature checking within build environment
* bind /sys and /dev/pts from host
* drop support for devtmpfs as it is no longer needed
* add /run and /dev/rtc0
* clone own ipc, uts and mount namespaces for chroot
* set localtime, timezone and locale within chroot environment
* copy /etc/pacman.d/gnupg from host
2012-06-11 16:44:23 +02:00
Gerardo Exequiel Pozzi 231496c82a mkarchroot: use bind mount instead of symlink for /dev/ptmx
We need /dev/ptmx -> /dev/pts/ptmx (for devpts -o newinstance)
Other way to do this thing is via bind mount (as said kernel doc[devpts.txt]).

This should be done in this way at least for /dev as devtmpfs in the chroot.
Since we can not touch /dev (devtmpfs), because devtmpfs is "singleton",
just use bind method and avoid interference.

Do it the same for both modes of /dev (tmpfs) and (devtmpfs) to keep it simple.

Currently devpts in chroot is not working without this when using /dev as devtmpfs,
this fixes this issue (opening /dev/ptmx, creates devices nodes on outside /dev/pts)

Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-06-10 12:57:14 +02:00
Gerardo Exequiel Pozzi 2d9a99ee15 Add -d param to optionally support devtmpfs
The main intention of this patch is to take advantage of
/dev/loop-control and loop devices.

Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-03-05 14:30:26 +01:00
Tom Gundersen 130227546a mkarchroot: do not create /etc/mtab
As of filesystem-2011.12 this is not needed anylonger, and indeed blocks the
chroot from being upgraded. As a workaround, recreating the chroot fixes the
problem.

Fixes FS#27640.

Reported-by: Andrea Scarpino <andrea@archlinux.org>
Signed-off-by: Tom Gundersen <teg@jklm.no>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2011-12-20 23:05:44 +01:00
Lukas Fleischer 56d4dec19f Use double brackets everywhere
We already fixed a couple of these in previous patches - this one should
replace all remaining uses of single brackets ("[") by double brackets.
Also, use arithmetic evaluation instead of conditional expressions where
appropriate and make use of "-z" and "-n" instead of comparing variables
to empty strings.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2011-12-04 18:00:57 +01:00
Pierre Schmitz a030cdc532 mkarchroot: Respect makepkg.conf and pacman.conf when running a command 2011-11-06 10:27:55 +01:00
Eric Bélanger 42d821ef7b Capitalize output messages
Some of the output/error messages were capitalized, some were
not. This patch capitalize everything for consistency sake. Other
minor changes were done to the messages like removing the superfluous
"error:" from die messages and adding a final period to messages that
were complete sentences as appropriate.

Signed-off-by: Eric Bélanger <snowmaniscool@gmail.com>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2011-11-04 19:33:29 +01:00