Commit Graph

692 Commits

Author SHA1 Message Date
Luke Shumaker a396a69081
Make slightly more involved changes to make shellcheck happy.
- Use `read -r` instead of other forms of read or looping
 - Use arrays instead of strings with whitespaces.
 - In one instance, use ${var%%.*} instead of $(echo $var|cut -f. -d1)
2017-07-05 18:21:56 +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 430e1265fb
Makefile: Add a simple 'check' target that runs shellcheck 2017-07-05 18:21:55 +02:00
Luke Shumaker 56cace32b2
makechrootpkg: Add a comment warning about a bug in "sudo -i"
The bug isn't currently triggered, but I accidentally did trigger when I
was trying to modify the command a bit.  I figure a "caution" sign would be
helpful to any future developers.
2017-07-05 18:21:55 +02:00
Luke Shumaker 2fdd1654b5
Makefile: m4_changequote([[[, ]]]) to avoid accidental quoting.
The default m4 quote characters: `QUOTE' are troublesome, because ` is
fairly likely to pop up in a shell script (if not for a subshell, because
it is a useful character in comments and user-facing messages).

So, this changes it to [[[QUOTE]]], as it is unlikely to see three braces
together like that, let alone in unbalanced sets.
2017-07-05 18:21:55 +02:00
Luke Shumaker 007d6fc15f
Makefile: add .DELETE_ON_ERROR:
The absence of it was allowing an (m4-produced) syntax error in
in a change I had made to be masked.
2017-07-05 18:21:55 +02:00
Luke Shumaker 4f23609d4e
makechroot: download_sources: Accept makepkg_owner as an argument
What this is really doing is fixing a conflict that I had incorrectly
resolved when rebasing what became 2fd5931 onto cda9cf4.  Of course,
because of dynamic scoping, everything worked out, and everything worked as
intended.

Before cda9cf4, it was appropriate for download_sources to take src_owner
as an argument, but after cda9cf4, it is now appropriate to take
makepkg_user as an argument.  However, it still takes src_owner as an
argument, but pays 0 attention to it; instead looking at makepkg_user which
it happily inherited because of dynamic scoping.

So change it to take makepkg_user as the argument.
2017-07-05 18:21:55 +02:00
Luke Shumaker 31a800fd88
lib/archroot.sh: subvolume_delete_recursive: support arbitrary recursion
The `-xdev` flag to `find` makes it not recurse over subvolumes; so it only
supports recursion with depth=1.  Fix this by having the function
recursively call itself.
2017-07-05 18:21:55 +02:00
Luke Shumaker 6d1992909c
makechrootpkg: sync_chroot: Make more general.
This is inspired by the thought that went in to the delete_chroot
is_subvolume commit.

sync_chroot($chrootdir, $copydir) copies `$chrootdir/root` to `$copydir`.
That seems a little silly; why do we care about "$chrootdir"?  Have it just
be sync_chroot(source, destination) like every other sync/copy command.

Where this becomes tricky is check to decide if we are going to use btrfs
subvolumes or not.  We don't care if "$source/.." is on btrfs; the root
could be a directly-mounted subvolume, but and the destination could be
another subvolume of the same btrfs mounted somewhere else.

The things we do care about are:

 - The source is a btrfs subvolume (so that we can snapshot it)
 - The source is on the same filesystem as the directory that the copy will
   be created in.
 - If the destination exists:
   * that it is not a mountpoint (so that we can delete and recreate it)
   * that it is a btrfs subvolume (so that we can quickly delete it)

On the last point, it isn't necessary for creating the new snapshot, just
for quick deletion.  That can be a separate check, where we use regular
`rm` for deleting the existing copy, but use subvolume snapshots for
creating the new one.
2017-07-05 18:21:55 +02:00
Luke Shumaker 928744cbc4
makechrootpkg: sync_chroot: make usage easier to understand.
Also, shorten the "Synchronizing" message to only include the full path
to the copy if it was specified.

The capslocked variable names in the Usage comment were references to
things in Parabola's tools, that didn't make much sense here out of
context.
2017-07-05 18:21:54 +02:00
Luke Shumaker 2a9b30ed35
makechrootpkg: delete_chroot: Fix the is-btrfs-subvolume check.
First of all, it ran `is_btrfs "$chrootdir"` to decide if it was on
btrfs, but $chrootdir wasn't defined locally; it just happens to work
because $chrootdir was defined in main().  (I noticed this because in
Parabola, it is called differently, so $chrootdir was empty).

So I was tempted to just change it to `is_btrfs "$copydir"`, but if
$copydir is just a regular directory on a btrfs filesystem, then it
It would leave much of $copydir intact.  What we really care about is
if $copydir is a btrfs subvolume; which we can check by combining the
is_btrfs check with inspecting the inum of the directory.

I put this combined check in lib/archroot.sh:is_subvolume.

https://lists.archlinux.org/pipermail/arch-projects/2013-September/003901.html
2017-07-05 18:21:54 +02:00
Bartłomiej Piotrowski c9b1fc08b5 Sync makepkg.conf files with pacman 5.0.2-2 2017-07-04 12:04:51 +02:00
Luke Shumaker 49088b0860
makechrootpkg: Avoid having code floating around outside of a function.
This means wrapping variable initialization in init_variables(), and the
main program routine in main().

I did NOT put `shopt -s nullglob` in to a function.

It make make sense to move init_variables() down into the main()
function, instead of having it as a separate function up top (if this
done, then the `-g` flag passed to `declare` in init_variables() can
be dropped).  However, in interest of keeping the `diff -w` small, and
merges/rebases simpler, this isn't done here.
2017-04-17 03:11:34 +02:00
Jan Alexander Steffens (heftig) a1f8ac9c70
makechrootpkg: Delete chroot subvols recursively when using -T
I overlooked this one. Fixes FS#53513.
2017-04-09 02:37:24 +02:00
Jan Alexander Steffens (heftig) 2243a276e4
makechrootpkg: Unindent as suggested in 2fd5931 2017-04-05 22:20:01 +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 4228d79b63
makechrootpkg: Improve status messages.
In sync_chroot(), this makes the messages be a bit more precise with
exactly which thing they are syncing where.  This is based on my users
expressing confusion at what is going on (especially when something is
taking a long time, and they have to blame something for blocking).
With these changes, I haven't gotten such confusion in a long time
(but maybe my users just got used to it).

In delete_chroot(), this changes "temporary copy" to "chroot copy",
since in Parabola's version of the tools, the function can get called
from other places, and it isn't necessarily operating on a temporary
copy.
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 35da846dde
makechrootpkg: Adjust to have the functions work with `set -u`.
Even though main() doesn't call `set -u`; this way the functions will
continue to work if copied into an environment with `set -u`, or so
that we are ready if we ever want to start using `set -u`.
2017-04-05 22:17:51 +02:00
Luke Shumaker 2fd5931a8c
makechrootpkg: Have functions be more function-y.
Rather than them simply being named blocks of code with braces around
them.

That is: have them take things via arguments rather than global
variables.

Specific notes:

 - create_chroot->sync_chroot:

   I pulled out locking the destination chroot; getting that lock is
   now the caller's responsibility.  It still handles locking the
   source chroot though.

   I pulled the `if [[ ! -d $copydir ]] || $clean_first;` check out; it is
   now the caller's responsibility to use that check when deciding if to
   call sync_chroot.

   However, when pulling that check out, I left it as `if true;`, to
   keep an indentation level.  This patch has had to be rebased/merged
   many times, and changing the indentation is a sure way to make that
   go less smoothly; I'm not going to re-indent this block until I see
   the check removed in the git.archlinux.org/devtools.git repository.

 - install_packages:

    1. Receive the list of packages as arguments, rather than a global
       variable.
    2. Make the caller responsible for looking at PKGBUILD.  From the
       name and arguments, one would never expect it to look at PKGBUILD.
2017-04-05 22:17:51 +02:00
lukeshu@parabola.nu 6098253f6f
Handle makepkg.conf more consistently 2017-04-05 22:17:51 +02:00
Luke Shumaker c1a056c9a8
lib/common.sh: Make it safe to include multiple times.
This is similar to common C #ifdef guards.

I was tempted to wrap the entire thing in the if/fi, rather than use
'return' to bail early.  However, that means it won't execute anything
until after it reaches 'fi'.  And if `shopt -s extglob` isn't executed
before parsing, then it will syntax-error on the extended globs.  One
solution would have been to move `shopt -s extglob` up above the
include-guard.  But the committed solution is all-around simpler.
2017-04-05 22:14:20 +02:00
Luke Shumaker 747e8ffc8d
lib/common.sh: Adjust to work properly with `set -u`. 2017-04-05 22:14:20 +02:00
Luke Shumaker fb40b58772
makechrootpkg: install_pkg was an unused variable 2017-04-05 22:14:20 +02:00
Luke Shumaker f9d9db474a
makechrootpkg: Quote directory passed to `rm -rf`. 2017-04-05 22:14:20 +02:00
Luke Shumaker 253bb4c8d4
makechrootpkg: /chrootbuild: accept makepkg_args as arguments rather than embedding. 2017-04-05 22:14:19 +02:00
Luke Shumaker 189efd3bc0
makechrootpkg: usage(): Display the actual default makepkg flags.
It was displaing the value of the `makepkg_args` variable, which may
have already been changed by the argument parsing by the time it gets
to `-h`.  Now there is a separate `default_makepkg_args` variable.
2017-04-05 22:14:19 +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
Luke Shumaker ae82f88e51
commitpkg: Adjust fancy quoting/escaping to not confuse Emacs.
It was confusing Emacs and screwing up the syntax highlighting and
auto-indentation for the rest of the file.
2017-04-05 22:10:03 +02:00
Luke Shumaker f55786b7a8
Add '#!/hint/bash' headers to non-executable bash files.
This provides a cross-editor hint that the syntax of the file is Bash.
2017-04-05 22:10:03 +02:00
Luke Shumaker 8ff247de13
lib/common.sh: Make setup_workdir()/cleanup() safe for programs to not use 2017-04-05 22:03:00 +02:00
Luke Shumaker d4f09b2c7b
lib/common.sh: lock, slock: Create directories for locks if necessary. 2017-04-05 22:03:00 +02:00
Luke Shumaker d333440810
lib/common.sh: lock, slock: Allow locks to be inherited.
Allow for locks to be inherited.  Inheriting the lock is something that
mkarchroot could do previously, but has since lost the ability to do.  This
allows for the programs to be more compos-able.

Do this by instead of unconditionally opening $file on $fd, first check if
$file is already open on $fd; and go ahead use it if it is.

The naive way of doing this would be to `$(readlink /dev/fd/$fd)` and
compare that to `$file`.  However, if `$file` is itself a symlink; or there
is a symlink somewhere in the path to `$file`, then this could easily fail.
Instead, check `[[ "/dev/fd/$fd" -ef "$file" ]]`.  Even though the Bash
documentation (`help test`) says that `-ef` checks for if the two files are
hard links to eachother, because it uses stat(3) (which resolves symlinks)
to do this check, it also works with the /dev/fd/ soft links.
2017-04-05 22:03:00 +02:00
Luke Shumaker 997bc1dc0d
lib/common.sh: add 'lock_close'; use it as appropriate.
`lock_close FD` is easier to remember than 'exec FD>&-`; and is especially
easier if FD is a variable (though that isn't actually taken advantage of
here).

This uses Bash 4.1+ `exec {var}>&-`, rather than the clunkier
`eval exec "$var>&-"` that was necessary in older versions of Bash.
Thanks to Dave Reisner for pointing this new bit of syntax out to me
the last time I submitted this (back in 2014, 4.1 had just come out).
2017-04-05 22:03:00 +02:00
Jan Alexander Steffens (heftig) f73c1f172f
Version 20170320 2017-03-20 19:23:50 +01:00
Jan Alexander Steffens (heftig) eec7fcf965
archbuild/makechrootpkg: Delete subvolumes in roots
The systemd package creates a subvolume at /var/lib/machines (through
tmpfiles), if it can. We need to delete this subvolume before we can
delete the parent subvolume.

Look through the root for inodes with the number 256. These identify
subvolume roots.
2017-03-07 20:39:11 +01: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
Alad Wenter cda9cf436b
makechrootpkg: run makepkg as specified user
makepkg --asroot was removed with pacman 4.2. Allow to specify a
separate makepkg user from the command line instead.

Fixes FS#43432
2017-03-07 19:02:21 +01:00
Alad Wenter 06c98c1b54
makechrootpkg: explain load_vars
The way in which makechrootpkg reads variables from makepkg.conf(5) is
different from makepkg, in that it reads a subset of defined
variables, and only if the were not set in the environment before.

Mention this in the usage text.

Fixes FS#44827
2017-03-07 19:02:21 +01:00
Jan Alexander Steffens (heftig) e10ce7fc70
Version 20170304 2017-03-04 15:10:11 +01:00
Levente Polyak ff48401963
makechrootpkg: fix potential non-writable directories of builduser in /build
This removes the preservation of HOME being /build just for the pacman
sudo call. Former leads to unbuildable packages when an to be installed
dependency writes something into the HOME dir (f.e. .config). The
resulting directories won't be writable by the builduser as they are
owned by root:root and ultimately will fail to build anything that
requires so.
2017-03-04 15:05:09 +01:00
Jelle van der Waa 15f16162fb
lib: remove unused version, pkgparts 2017-03-04 15:03:37 +01:00
Jelle van der Waa fea14fa286
lib: remove unused left, right 2017-03-04 15:03:05 +01:00
Jan Alexander Steffens (heftig) 4bafd641ab
makechrootpkg: Simplify symlink replacement 2017-03-04 15:00:50 +01:00
NicoHood 58968cfaa2
makechrootpkg: Fix broken symlink because of temporary chroot PKGDEST /pkgdest 2017-03-04 15:00:12 +01:00