Commit Graph

49 Commits

Author SHA1 Message Date
Levente Polyak d6866e0544
lib: support arbitrary compressed package files
We need to modify the matching of valid package files to support formats
like zstd. Let's try to use an eager approach instead of a simple
whitelist in order to be functional for arbitrary formats that may be
introduced in the future without the need to adjust any code.

Allow any single fragment word as compression type but filter out known
non-package content like signature files.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-12-08 20:59:11 +01:00
Ivy Foster 2c611d20bd
lib/common.sh: do not use colors when running on a dumb terminal 2019-11-30 13:25:05 +01:00
Levente Polyak 64b7d99504
zsh_completion: add sogrep completions
Transform sogrep into an in-prog so we can benefit from the m4 macro
to specify valid repos in a single place of truth.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-09-28 00:16:09 +02:00
Eli Schwartz 8f5a02b23d
Don't rely on $0 to determine script names.
Programs can freely define the value of argv0 and thus it means nothing.
Instead, use the bash-specific variable explicitly designed to safely
and accurately reference the name of the currently sourced file.

This also fixes the case where simple debugging mechanisms like using
"bash -x foo" tried to treat "foo" as the unqualified $0 and therefore
broke horribly due to lack of pathnames.

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 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
Erich Eckner c86823a2d4
is_same_fs() in lib/archroot.sh should use $1 and $2, not $1 and $1
The old behaviour would always evaluate to true - this is certainly not
what that function should do.

Signed-off-by: Erich Eckner <git@eckner.net>
2019-04-20 17:55:31 +02:00
Luke Shumaker aee72cae32 lib/common.sh: Adjust to work properly with `set -u`
Support for working with `set -u` was broken by 94160d6.  Egg on my
face; I'm the one who wants `set -u` support, and I'm the author of
that commit!

libmakepkg does not work with `set -u`; but mostly because of the include
guards!  So we just need to temporarily disable `set -u` (nounset) while
loading libmakepkg.  Instead of introducing a new variable, just store the
initial nounset status in _INCLUDE_COMMON_SH; rather than a useless
fixed-string "true".

While we're at it, disable POSIX-mode (just in case we're running as "sh"
instead of "bash"), since libmakepkg uses bash-isms that won't parse in
POSIX mode.
2018-01-21 14:16:10 +01: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
Bartłomiej Piotrowski 7259e7def0 Remove i686 support 2017-11-08 14:22:56 +01:00
Luke Shumaker 94160d62b8
use makepkg library instead of local function copies
This mirrors dbscripts commit
625fa02 by Pierre Schmitz <pierre@archlinux.de> at 2017-04-18 14:20:49
2017-10-30 16:03:15 +01:00
Luke Shumaker a9dab95334
Add `# shellcheck` directives to quiet shellcheck, add PKGBUILD.proto
The added PKGBUILD.proto file is so that shellcheck can know know what
to expect that a PKGBUILD sets.
2017-07-05 18:21:56 +02:00
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 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 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
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 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 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) 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
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
Dave Reisner 98841eb694 common: remove unreachable statement
We run from a non-interactive shell, so the exec which is inevitably
called will replace the current process and 'die' will never run under
any circumstances.

This also fixes a bug with the su fallback which would cause multiple
arguments to be concatenated without any whitespace between them.
2014-09-22 08:25:43 -04:00
Dave Reisner af6c0a0f6a common.sh: propagate error through trap_exit
Fixes a breakage introduced in 6db31cc16a which leads to errors
being masked from makechrootpkg.
2014-09-22 08:25:42 -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
BlackEagle 7aac293d76 get_full_version :: remove duplicated epoch check
Signed-off-by: BlackEagle <ike.devolder@gmail.com>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2014-05-10 08:04:51 +02:00
BlackEagle 6db31cc16a when cleanup is called without code exit with 0
Signed-off-by: BlackEagle <ike.devolder@gmail.com>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2014-05-10 08:04:24 +02:00
BlackEagle 4ee45fe6d4 abort and die are serious errors so throw 255 out
Signed-off-by: BlackEagle <ike.devolder@gmail.com>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2014-05-10 08:03:58 +02:00
Dave Reisner 1e043445d2 find_cached_package: avoid adding duplicates
If PKGDEST is set when makepkg was run, the package will be present in
find_cached_package's search path by default, causing an error.

This also fixes a display bug which causes no output to be shown when
multiple packages are found.

Fixes FS#37626.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2013-11-04 10:02:20 +01:00
Dave Reisner 27441f201c common: implement find_cached_package
This function (currently) searches through $PWD and $PKGDEST looking
for a tarball matching the requested package name, architecture, and
pkgver. If found, it writes the full path to the located package to
stdout and returns 0, else 1. If more than 1 match is found, it's
treated as an error and the user will need to figure out what to do.

Use this in checkpkg and commitpkg, which previously implemented their
own less complete logic, to locate the build artifacts they rely on.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2013-11-01 18:52:03 +01:00
Dave Reisner fb30cabe61 common: Properly forward arguments from die to error
Also allow this function to be called without arguments, in which case,
don't call error at all. Some uses of this function wrongly assumed
that this was already allowed.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2013-08-08 21:28:00 +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) 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 7228cc00e8 Use dedicated trap functions to avoid unsetting the trap when e.g. cleanup is called 2012-10-03 12:35:40 +02:00
Pierre Schmitz 246b8ead60 mkarchroot: reset trap so it wont be called twice 2012-06-16 16:21:55 +02:00
Lukas Fleischer 9ab0d94578 archrelease: Validate tags before releasing
Compare every single tag with a list of valid tags. This prevents broken
releases which occurred whenever someone made a typo on the command
line:

    $ ./archrelease community i686
    ==> ERROR: archrelease: Invalid tag: "community" (use -f to force release)

Since the list is used in the ZSH completion as well, break it out to a
separate file and move it to "lib/". Also, add a command line parameter
to allow for releasing to an unknown repository when necessary.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-02-12 12:35:14 +01:00
Lukas Fleischer fbbcc30e3d lib/common.sh: Revise setup_workdir()
* Honor TMPDIR variable (just like we did in commit a0c6bf45).
* Quote path properly.
* Avoid unnecessary use of basename(1).

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2011-11-04 19:34:00 +01:00
Lukas Fleischer c1752bd716 lib/common.sh: Use double brackets
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2011-11-04 19:33:51 +01:00
Pierre Schmitz aaa68e49e8 Move common functions to a shared file
* common.sh is included on build time
* most functions are copied from makepkg
2011-11-01 15:33:08 +01:00