2007-11-28 16:10:41 +01:00
|
|
|
#!/bin/bash
|
2017-03-28 22:13:18 +02:00
|
|
|
# License: GNU GPLv2
|
|
|
|
#
|
2007-10-22 04:08:55 +02:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2007-10-04 06:24:29 +02:00
|
|
|
|
2011-11-01 15:33:08 +01:00
|
|
|
m4_include(lib/common.sh)
|
2017-03-07 19:27:36 +01:00
|
|
|
m4_include(lib/archroot.sh)
|
2011-11-01 15:33:08 +01:00
|
|
|
|
2019-08-09 20:31:53 +02:00
|
|
|
source /usr/share/makepkg/util/config.sh
|
|
|
|
|
2011-09-17 15:14:08 +02:00
|
|
|
shopt -s nullglob
|
|
|
|
|
2014-12-29 06:33:41 +01:00
|
|
|
default_makepkg_args=(--syncdeps --noconfirm --holdver --skipinteg)
|
2019-02-13 08:02:40 +01:00
|
|
|
makepkg_args=("${default_makepkg_args[@]}")
|
2019-03-28 23:04:32 +01:00
|
|
|
verifysource_args=()
|
2019-02-13 08:02:40 +01:00
|
|
|
chrootdir=
|
|
|
|
passeddir=
|
|
|
|
makepkg_user=
|
|
|
|
declare -a install_pkgs
|
|
|
|
declare -i ret=0
|
|
|
|
|
2019-02-13 08:45:36 +01:00
|
|
|
keepbuilddir=0
|
|
|
|
update_first=0
|
|
|
|
clean_first=0
|
|
|
|
run_namcap=0
|
2019-09-11 23:10:04 +02:00
|
|
|
run_checkpkg=0
|
2019-02-13 08:45:36 +01:00
|
|
|
temp_chroot=0
|
|
|
|
|
2019-02-13 08:02:40 +01:00
|
|
|
bindmounts_ro=()
|
|
|
|
bindmounts_rw=()
|
|
|
|
|
|
|
|
copy=$USER
|
|
|
|
[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER
|
|
|
|
[[ -z "$copy" || $copy = root ]] && copy=copy
|
|
|
|
src_owner=${SUDO_USER:-$USER}
|
|
|
|
|
2010-02-13 19:47:16 +01:00
|
|
|
usage() {
|
2012-11-15 15:22:50 +01:00
|
|
|
echo "Usage: ${0##*/} [options] -r <chrootdir> [--] [makepkg args]"
|
2010-02-13 19:47:16 +01:00
|
|
|
echo ' Run this script in a PKGBUILD dir to build a package inside a'
|
2014-05-04 18:31:53 +02:00
|
|
|
echo ' clean chroot. Arguments passed to this script after the'
|
|
|
|
echo ' end-of-options marker (--) will be passed to makepkg.'
|
2010-02-13 19:47:16 +01:00
|
|
|
echo ''
|
|
|
|
echo ' The chroot dir consists of the following directories:'
|
|
|
|
echo ' <chrootdir>/{root, copy} but only "root" is required'
|
|
|
|
echo ' by default. The working copy will be created as needed'
|
|
|
|
echo ''
|
|
|
|
echo 'The chroot "root" directory must be created via the following'
|
|
|
|
echo 'command:'
|
2013-03-14 03:55:39 +01:00
|
|
|
echo ' mkarchroot <chrootdir>/root base-devel'
|
2010-02-13 19:47:16 +01:00
|
|
|
echo ''
|
2016-07-22 15:37:24 +02:00
|
|
|
echo 'This script reads {SRC,SRCPKG,PKG,LOG}DEST, MAKEFLAGS and PACKAGER'
|
|
|
|
echo 'from makepkg.conf(5), if those variables are not part of the'
|
|
|
|
echo 'environment.'
|
|
|
|
echo ''
|
2017-04-02 10:09:56 +02:00
|
|
|
echo "Default makepkg args: ${default_makepkg_args[*]}"
|
2010-02-13 19:47:16 +01:00
|
|
|
echo ''
|
|
|
|
echo 'Flags:'
|
|
|
|
echo '-h This help'
|
|
|
|
echo '-c Clean the chroot before building'
|
2014-12-29 06:25:58 +01:00
|
|
|
echo '-C <dir> Set pacman cache to pass to arch-nspawn'
|
2013-08-19 02:40:59 +02:00
|
|
|
echo '-d <dir> Bind directory into build chroot as read-write'
|
|
|
|
echo '-D <dir> Bind directory into build chroot as read-only'
|
2010-02-13 19:47:16 +01:00
|
|
|
echo '-u Update the working copy of the chroot before building'
|
|
|
|
echo ' This is useful for rebuilds without dirtying the pristine'
|
|
|
|
echo ' chroot'
|
|
|
|
echo '-r <dir> The chroot dir to use'
|
|
|
|
echo '-I <pkg> Install a package into the working copy of the chroot'
|
|
|
|
echo '-l <copy> The directory to use as the working copy of the chroot'
|
2013-03-14 03:55:40 +01:00
|
|
|
echo ' Useful for maintaining multiple copies'
|
|
|
|
echo " Default: $copy"
|
2011-12-30 16:26:08 +01:00
|
|
|
echo '-n Run namcap on the package'
|
2019-09-11 23:10:04 +02:00
|
|
|
echo '-C Run checkpkg on the package'
|
2013-03-14 03:55:40 +01:00
|
|
|
echo '-T Build in a temporary directory'
|
2016-07-22 15:37:25 +02:00
|
|
|
echo '-U Run makepkg as a specified user'
|
2010-02-13 19:47:16 +01:00
|
|
|
exit 1
|
2007-10-04 06:24:29 +02:00
|
|
|
}
|
|
|
|
|
2013-05-02 08:29:21 +02:00
|
|
|
# {{{ functions
|
2019-05-10 04:58:26 +02:00
|
|
|
# Usage: sync_chroot $chrootdir $copydir [$copy]
|
2017-04-05 21:35:58 +02:00
|
|
|
sync_chroot() {
|
2019-05-10 04:58:26 +02:00
|
|
|
local chrootdir=$1
|
2017-05-06 00:40:59 +02:00
|
|
|
local copydir=$2
|
|
|
|
local copy=${3:-$2}
|
2017-04-05 21:35:58 +02:00
|
|
|
|
2019-05-10 04:58:26 +02:00
|
|
|
if [[ "$chrootdir/root" -ef "$copydir" ]]; then
|
2017-04-05 21:35:58 +02:00
|
|
|
error 'Cannot sync copy with itself: %s' "$copydir"
|
|
|
|
return 1
|
|
|
|
fi
|
2013-05-02 08:29:21 +02:00
|
|
|
|
2017-04-05 22:20:01 +02:00
|
|
|
# Get a read lock on the root chroot to make
|
|
|
|
# sure we don't clone a half-updated chroot
|
2019-05-10 04:58:26 +02:00
|
|
|
slock 8 "$chrootdir/root.lock" \
|
|
|
|
"Locking clean chroot [%s]" "$chrootdir/root"
|
|
|
|
|
|
|
|
stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copy"
|
|
|
|
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
|
|
|
|
subvolume_delete_recursive "$copydir" ||
|
|
|
|
die "Unable to delete subvolume %s" "$copydir"
|
|
|
|
btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null ||
|
2017-04-05 22:20:01 +02:00
|
|
|
die "Unable to create subvolume %s" "$copydir"
|
|
|
|
else
|
|
|
|
mkdir -p "$copydir"
|
2019-05-10 04:58:26 +02:00
|
|
|
rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir"
|
2013-05-02 08:29:21 +02:00
|
|
|
fi
|
2017-04-05 22:20:01 +02:00
|
|
|
stat_done
|
|
|
|
|
|
|
|
# Drop the read lock again
|
|
|
|
lock_close 8
|
2014-05-04 05:07:46 +02:00
|
|
|
|
|
|
|
# Update mtime
|
|
|
|
touch "$copydir"
|
2013-05-02 08:29:21 +02:00
|
|
|
}
|
2011-03-13 19:06:27 +01:00
|
|
|
|
2017-04-05 21:35:58 +02:00
|
|
|
# Usage: delete_chroot $copydir [$copy]
|
|
|
|
delete_chroot() {
|
|
|
|
local copydir=$1
|
|
|
|
local copy=${1:-$2}
|
|
|
|
|
2017-04-05 21:36:02 +02:00
|
|
|
stat_busy "Removing chroot copy [%s]" "$copy"
|
2017-05-06 00:40:58 +02:00
|
|
|
if is_subvolume "$copydir" && ! mountpoint -q "$copydir"; then
|
2017-04-09 02:36:01 +02:00
|
|
|
subvolume_delete_recursive "$copydir" ||
|
2013-07-30 21:24:48 +02:00
|
|
|
die "Unable to delete subvolume %s" "$copydir"
|
2011-03-13 15:19:20 +01:00
|
|
|
else
|
2013-05-02 08:29:21 +02:00
|
|
|
# avoid change of filesystem in case of an umount failure
|
|
|
|
rm --recursive --force --one-file-system "$copydir" ||
|
2013-07-30 21:24:48 +02:00
|
|
|
die "Unable to delete %s" "$copydir"
|
2011-03-13 15:19:20 +01:00
|
|
|
fi
|
2013-05-02 08:29:21 +02:00
|
|
|
|
|
|
|
# remove lock file
|
|
|
|
rm -f "$copydir.lock"
|
2011-11-01 15:33:08 +01:00
|
|
|
stat_done
|
2013-05-02 08:29:21 +02:00
|
|
|
}
|
2011-03-13 19:06:27 +01:00
|
|
|
|
2013-05-02 08:29:21 +02:00
|
|
|
install_packages() {
|
2016-04-30 21:49:38 +02:00
|
|
|
local -a pkgnames
|
|
|
|
local ret
|
2007-10-04 06:24:29 +02:00
|
|
|
|
2016-04-30 21:49:38 +02:00
|
|
|
pkgnames=("${install_pkgs[@]##*/}")
|
2011-09-17 14:46:10 +02:00
|
|
|
|
2016-04-30 21:49:38 +02:00
|
|
|
cp -- "${install_pkgs[@]}" "$copydir/root/"
|
|
|
|
arch-nspawn "$copydir" "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
|
2019-05-26 22:41:21 +02:00
|
|
|
bash -c 'yes y | pacman -U -- "$@"' -bash "${pkgnames[@]/#//root/}"
|
2016-04-30 21:49:38 +02:00
|
|
|
ret=$?
|
|
|
|
rm -- "${pkgnames[@]/#/$copydir/root/}"
|
2011-09-17 14:46:10 +02:00
|
|
|
|
2017-04-05 21:35:58 +02:00
|
|
|
return $ret
|
2013-05-02 08:29:21 +02:00
|
|
|
}
|
2007-12-16 02:57:39 +01:00
|
|
|
|
2013-05-02 08:29:21 +02:00
|
|
|
prepare_chroot() {
|
2019-02-13 08:45:36 +01:00
|
|
|
(( keepbuilddir )) || rm -rf "$copydir/build"
|
2008-01-16 14:12:38 +01:00
|
|
|
|
2017-05-06 00:41:07 +02:00
|
|
|
local builduser_uid builduser_gid
|
2019-08-04 05:05:17 +02:00
|
|
|
builduser_uid="$(id -u "$makepkg_user")"
|
|
|
|
builduser_gid="$(id -g "$makepkg_user")"
|
2016-04-20 19:36:54 +02:00
|
|
|
local install="install -o $builduser_uid -g $builduser_gid"
|
|
|
|
local x
|
2014-09-21 21:03:28 +02:00
|
|
|
|
|
|
|
# We can't use useradd without chrooting, otherwise it invokes PAM modules
|
|
|
|
# which we might not be able to load (i.e. when building i686 packages on
|
|
|
|
# an x86_64 host).
|
2018-05-12 10:52:18 +02:00
|
|
|
sed -e '/^builduser:/d' -i "$copydir"/etc/{passwd,shadow,group}
|
2017-05-06 00:41:08 +02:00
|
|
|
printf >>"$copydir/etc/group" 'builduser:x:%d:\n' "$builduser_gid"
|
|
|
|
printf >>"$copydir/etc/passwd" 'builduser:x:%d:%d:builduser:/build:/bin/bash\n' "$builduser_uid" "$builduser_gid"
|
2018-05-12 10:52:18 +02:00
|
|
|
printf >>"$copydir/etc/shadow" 'builduser:!!:%d::::::\n' "$(( $(date -u +%s) / 86400 ))"
|
2011-09-17 15:50:30 +02:00
|
|
|
|
2018-01-15 18:36:45 +01:00
|
|
|
$install -d "$copydir"/{build,startdir,{pkg,srcpkg,src,log}dest}
|
2016-04-20 19:36:54 +02:00
|
|
|
|
2016-07-04 05:32:15 +02:00
|
|
|
for x in BUILDDIR=/build PKGDEST=/pkgdest SRCPKGDEST=/srcpkgdest SRCDEST=/srcdest LOGDEST=/logdest
|
2016-04-20 19:36:54 +02:00
|
|
|
do
|
|
|
|
grep -q "^$x" "$copydir/etc/makepkg.conf" && continue
|
|
|
|
echo "$x" >>"$copydir/etc/makepkg.conf"
|
|
|
|
done
|
2009-12-27 11:42:11 +01:00
|
|
|
|
2016-04-20 19:36:54 +02:00
|
|
|
cat > "$copydir/etc/sudoers.d/builduser-pacman" <<EOF
|
2014-09-21 21:03:28 +02:00
|
|
|
builduser ALL = NOPASSWD: /usr/bin/pacman
|
2011-10-29 20:37:28 +02:00
|
|
|
EOF
|
2016-04-20 19:36:54 +02:00
|
|
|
chmod 440 "$copydir/etc/sudoers.d/builduser-pacman"
|
2007-10-07 19:31:22 +02:00
|
|
|
|
2013-05-02 08:29:21 +02:00
|
|
|
# This is a little gross, but this way the script is recreated every time in the
|
|
|
|
# working copy
|
2014-09-23 13:57:43 +02:00
|
|
|
{
|
2014-10-20 01:49:02 +02:00
|
|
|
printf '#!/bin/bash\n'
|
|
|
|
declare -f _chrootbuild
|
2018-01-15 17:57:00 +01:00
|
|
|
declare -p SOURCE_DATE_EPOCH 2>/dev/null || true
|
2017-04-02 10:09:58 +02:00
|
|
|
printf '_chrootbuild "$@" || exit\n'
|
2014-10-20 01:49:02 +02:00
|
|
|
|
2019-02-13 08:45:36 +01:00
|
|
|
if (( run_namcap )); then
|
2016-04-20 19:36:54 +02:00
|
|
|
declare -f _chrootnamcap
|
|
|
|
printf '_chrootnamcap || exit\n'
|
2014-09-23 13:57:43 +02:00
|
|
|
fi
|
|
|
|
} >"$copydir/chrootbuild"
|
2013-05-02 08:29:21 +02:00
|
|
|
chmod +x "$copydir/chrootbuild"
|
|
|
|
}
|
|
|
|
|
2016-04-20 19:36:54 +02:00
|
|
|
# These functions aren't run in makechrootpkg,
|
|
|
|
# so no global variables
|
|
|
|
_chrootbuild() {
|
2017-09-14 22:21:47 +02:00
|
|
|
# No coredumps
|
|
|
|
ulimit -c 0
|
|
|
|
|
2017-05-06 00:41:10 +02:00
|
|
|
# shellcheck source=/dev/null
|
2016-04-20 19:36:54 +02:00
|
|
|
. /etc/profile
|
2017-09-14 22:21:47 +02:00
|
|
|
|
2017-05-06 00:41:05 +02:00
|
|
|
# Beware, there are some stupid arbitrary rules on how you can
|
|
|
|
# use "$" in arguments to commands with "sudo -i". ${foo} or
|
|
|
|
# ${1} is OK, but $foo or $1 isn't.
|
|
|
|
# https://bugzilla.sudo.ws/show_bug.cgi?id=765
|
2014-12-29 06:32:15 +01:00
|
|
|
mkdir /build/.distcc
|
|
|
|
chown builduser /build/.distcc
|
|
|
|
sudo --preserve-env=SOURCE_DATE_EPOCH -iu builduser DISTCC_IO_TIMEOUT=1200 DISTCC_DIR='/build/.distcc' bash -c 'cd /startdir; makepkg "$@"' -bash "$@"
|
2018-05-29 23:23:10 +02:00
|
|
|
ret=$?
|
|
|
|
case $ret in
|
2019-09-12 16:20:19 +02:00
|
|
|
0|14)
|
2018-05-29 23:23:10 +02:00
|
|
|
return 0;;
|
|
|
|
*)
|
|
|
|
return $ret;;
|
|
|
|
esac
|
2016-04-20 19:36:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_chrootnamcap() {
|
|
|
|
pacman -S --needed --noconfirm namcap
|
|
|
|
for pkgfile in /startdir/PKGBUILD /pkgdest/*; do
|
|
|
|
echo "Checking ${pkgfile##*/}"
|
|
|
|
sudo -u builduser namcap "$pkgfile" 2>&1 | tee "/logdest/${pkgfile##*/}-namcap.log"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-05-02 08:29:21 +02:00
|
|
|
download_sources() {
|
2018-06-27 09:05:43 +02:00
|
|
|
setup_workdir
|
|
|
|
chown "$makepkg_user:" "$WORKDIR"
|
2013-05-02 08:29:21 +02:00
|
|
|
|
|
|
|
# Ensure sources are downloaded
|
2018-02-27 17:16:24 +01:00
|
|
|
sudo -u "$makepkg_user" --preserve-env=GNUPGHOME \
|
2018-06-27 09:05:43 +02:00
|
|
|
env SRCDEST="$SRCDEST" BUILDDIR="$WORKDIR" \
|
2014-12-29 06:33:00 +01:00
|
|
|
makepkg -A --config="$copydir/etc/makepkg.conf" --verifysource -o "${verifysource_args[@]}" ||
|
2017-07-13 19:37:15 +02:00
|
|
|
die "Could not download sources."
|
2013-05-02 08:29:21 +02:00
|
|
|
}
|
2007-10-04 06:24:29 +02:00
|
|
|
|
2013-05-02 08:29:21 +02:00
|
|
|
move_products() {
|
2017-04-05 21:35:58 +02:00
|
|
|
local pkgfile
|
2013-05-02 08:29:21 +02:00
|
|
|
for pkgfile in "$copydir"/pkgdest/*; do
|
2012-08-11 12:17:56 +02:00
|
|
|
chown "$src_owner" "$pkgfile"
|
2011-09-17 15:05:35 +02:00
|
|
|
mv "$pkgfile" "$PKGDEST"
|
2017-01-07 14:50:27 +01:00
|
|
|
|
|
|
|
# Fix broken symlink because of temporary chroot PKGDEST /pkgdest
|
|
|
|
if [[ "$PWD" != "$PKGDEST" && -L "$PWD/${pkgfile##*/}" ]]; then
|
2017-03-04 15:00:50 +01:00
|
|
|
ln -sf "$PKGDEST/${pkgfile##*/}"
|
2017-01-07 14:50:27 +01:00
|
|
|
fi
|
2010-02-13 19:47:16 +01:00
|
|
|
done
|
|
|
|
|
2017-04-05 21:35:58 +02:00
|
|
|
local l
|
2013-05-02 08:29:21 +02:00
|
|
|
for l in "$copydir"/logdest/*; do
|
2013-11-06 14:58:39 +01:00
|
|
|
[[ $l == */logpipe.* ]] && continue
|
2012-08-11 12:17:56 +02:00
|
|
|
chown "$src_owner" "$l"
|
2013-05-02 08:29:21 +02:00
|
|
|
mv "$l" "$LOGDEST"
|
2010-02-13 19:47:16 +01:00
|
|
|
done
|
2013-11-06 18:56:50 +01:00
|
|
|
|
|
|
|
for s in "$copydir"/srcpkgdest/*; do
|
|
|
|
chown "$src_owner" "$s"
|
|
|
|
mv "$s" "$SRCPKGDEST"
|
2017-05-13 01:57:05 +02:00
|
|
|
|
|
|
|
# Fix broken symlink because of temporary chroot SRCPKGDEST /srcpkgdest
|
|
|
|
if [[ "$PWD" != "$SRCPKGDEST" && -L "$PWD/${s##*/}" ]]; then
|
|
|
|
ln -sf "$SRCPKGDEST/${s##*/}"
|
|
|
|
fi
|
2013-11-06 18:56:50 +01:00
|
|
|
done
|
2013-05-02 08:29:21 +02:00
|
|
|
}
|
|
|
|
# }}}
|
|
|
|
|
2014-12-29 06:25:58 +01:00
|
|
|
while getopts 'hcuC:r:I:l:nCTD:d:U:' arg; do
|
2019-02-13 08:02:40 +01:00
|
|
|
case "$arg" in
|
2019-02-13 08:45:36 +01:00
|
|
|
c) clean_first=1 ;;
|
2019-02-13 08:02:40 +01:00
|
|
|
D) bindmounts_ro+=("--bind-ro=$OPTARG") ;;
|
|
|
|
d) bindmounts_rw+=("--bind=$OPTARG") ;;
|
2019-02-13 08:45:36 +01:00
|
|
|
u) update_first=1 ;;
|
2014-12-29 06:25:58 +01:00
|
|
|
C) cache_dir="-c $OPTARG" ;;
|
2019-02-13 08:02:40 +01:00
|
|
|
r) passeddir="$OPTARG" ;;
|
|
|
|
I) install_pkgs+=("$OPTARG") ;;
|
|
|
|
l) copy="$OPTARG" ;;
|
2019-02-13 08:45:36 +01:00
|
|
|
n) run_namcap=1; makepkg_args+=(--install) ;;
|
2019-09-11 23:10:04 +02:00
|
|
|
C) run_checkpkg=1 ;;
|
2019-02-13 08:45:36 +01:00
|
|
|
T) temp_chroot=1; copy+="-$$" ;;
|
2019-02-13 08:02:40 +01:00
|
|
|
U) makepkg_user="$OPTARG" ;;
|
|
|
|
h|*) usage ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
|
|
|
|
[[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.'
|
|
|
|
makepkg_user=${makepkg_user:-${SUDO_USER:-$USER}}
|
|
|
|
|
|
|
|
check_root SOURCE_DATE_EPOCH,GNUPGHOME,SRCDEST,SRCPKGDEST,PKGDEST,LOGDEST,MAKEFLAGS,PACKAGER
|
|
|
|
|
|
|
|
# Canonicalize chrootdir, getting rid of trailing /
|
|
|
|
chrootdir=$(readlink -e "$passeddir")
|
|
|
|
[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir"
|
|
|
|
[[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir"
|
|
|
|
|
|
|
|
if [[ ${copy:0:1} = / ]]; then
|
|
|
|
copydir=$copy
|
|
|
|
else
|
|
|
|
copydir="$chrootdir/$copy"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Pass all arguments after -- right to makepkg
|
|
|
|
makepkg_args+=("${@:$OPTIND}")
|
|
|
|
|
|
|
|
# See if -R or -e was passed to makepkg
|
2019-03-29 00:41:30 +01:00
|
|
|
for arg in "${@:$OPTIND}"; do
|
2019-02-13 08:02:40 +01:00
|
|
|
case ${arg%%=*} in
|
2019-03-28 23:04:32 +01:00
|
|
|
--skip*|--holdver) verifysource_args+=("$arg") ;;
|
|
|
|
--repackage|--noextract) keepbuilddir=1 ;;
|
2019-02-13 08:02:40 +01:00
|
|
|
--*) ;;
|
2019-03-28 23:04:32 +01:00
|
|
|
-*R*|-*e*) keepbuilddir=1 ;;
|
2019-02-13 08:02:40 +01:00
|
|
|
esac
|
|
|
|
done
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:02:40 +01:00
|
|
|
umask 0022
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-08-09 20:31:53 +02:00
|
|
|
ORIG_HOME=$HOME
|
|
|
|
IFS=: read -r _ _ _ _ _ HOME _ < <(getent passwd "${SUDO_USER:-$USER}")
|
|
|
|
load_makepkg_config
|
|
|
|
HOME=$ORIG_HOME
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:02:40 +01:00
|
|
|
# Use PKGBUILD directory if these don't exist
|
|
|
|
[[ -d $PKGDEST ]] || PKGDEST=$PWD
|
|
|
|
[[ -d $SRCDEST ]] || SRCDEST=$PWD
|
|
|
|
[[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD
|
|
|
|
[[ -d $LOGDEST ]] || LOGDEST=$PWD
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:02:40 +01:00
|
|
|
# Lock the chroot we want to use. We'll keep this lock until we exit.
|
|
|
|
lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy"
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:45:36 +01:00
|
|
|
if [[ ! -d $copydir ]] || (( clean_first )); then
|
2019-02-13 08:02:40 +01:00
|
|
|
sync_chroot "$chrootdir" "$copydir" "$copy"
|
|
|
|
fi
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:45:36 +01:00
|
|
|
(( update_first )) && arch-nspawn "$copydir" \
|
2019-02-13 08:02:40 +01:00
|
|
|
"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
|
2019-05-26 22:42:38 +02:00
|
|
|
pacman -Syuu --noconfirm
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:02:40 +01:00
|
|
|
if [[ -n ${install_pkgs[*]:-} ]]; then
|
2019-02-13 08:23:51 +01:00
|
|
|
install_packages
|
2019-02-13 08:02:40 +01:00
|
|
|
ret=$?
|
2019-02-13 08:23:51 +01:00
|
|
|
# If there is no PKGBUILD we are done
|
|
|
|
[[ -f PKGBUILD ]] || exit $ret
|
2019-02-13 08:02:40 +01:00
|
|
|
fi
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:02:40 +01:00
|
|
|
if [[ "$(id -u "$makepkg_user")" == 0 ]]; then
|
|
|
|
error "Running makepkg as root is not allowed."
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-07-13 19:37:15 +02:00
|
|
|
|
2019-02-13 08:23:51 +01:00
|
|
|
download_sources
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:23:51 +01:00
|
|
|
prepare_chroot
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2014-12-29 06:25:58 +01:00
|
|
|
if arch-nspawn $cache_dir "$copydir" \
|
2020-05-20 16:33:36 +02:00
|
|
|
--setenv=TERM=xterm \
|
2019-03-28 21:54:09 +01:00
|
|
|
--bind="${PWD//:/\\:}:/startdir" \
|
|
|
|
--bind="${SRCDEST//:/\\:}:/srcdest" \
|
2019-02-13 08:02:40 +01:00
|
|
|
"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
|
|
|
|
/chrootbuild "${makepkg_args[@]}"
|
|
|
|
then
|
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 c14338c0fe71a74f5e56b4f3af7c548fe0928e15
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-12-17 01:27:27 +01:00
|
|
|
mapfile -t pkgnames < <(sudo -u "$makepkg_user" bash -c 'source PKGBUILD; printf "%s\n" "${pkgname[@]}"')
|
2019-02-13 08:23:51 +01:00
|
|
|
move_products
|
2019-02-13 08:02:40 +01:00
|
|
|
else
|
|
|
|
(( ret += 1 ))
|
|
|
|
fi
|
2013-05-02 08:29:21 +02:00
|
|
|
|
2019-02-13 08:45:36 +01:00
|
|
|
(( temp_chroot )) && delete_chroot "$copydir" "$copy"
|
2017-04-06 01:06:10 +02:00
|
|
|
|
2019-02-13 08:02:40 +01:00
|
|
|
if (( ret != 0 )); then
|
2019-02-13 08:45:36 +01:00
|
|
|
if (( temp_chroot )); then
|
2019-02-13 08:02:40 +01:00
|
|
|
die "Build failed"
|
2013-03-14 03:55:40 +01:00
|
|
|
else
|
2019-02-13 08:02:40 +01:00
|
|
|
die "Build failed, check %s/build" "$copydir"
|
2013-03-14 03:55:40 +01:00
|
|
|
fi
|
2019-02-13 08:02:40 +01:00
|
|
|
else
|
2019-09-11 23:10:04 +02:00
|
|
|
if (( run_checkpkg )); then
|
|
|
|
msg "Running checkpkg"
|
2019-12-03 01:14:35 +01:00
|
|
|
|
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 c14338c0fe71a74f5e56b4f3af7c548fe0928e15
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-12-17 01:27:27 +01:00
|
|
|
mapfile -t remotepkgs < <(pacman --config "$copydir"/etc/pacman.conf \
|
|
|
|
--dbpath "$copydir"/var/lib/pacman \
|
|
|
|
-Sddp "${pkgnames[@]}")
|
2019-12-03 01:14:35 +01:00
|
|
|
|
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 c14338c0fe71a74f5e56b4f3af7c548fe0928e15
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-12-17 01:27:27 +01:00
|
|
|
if ! wait $!; then
|
2019-11-30 13:09:14 +01:00
|
|
|
warning "Skipped checkpkg due to missing repo packages"
|
|
|
|
exit 0
|
2019-09-11 23:10:04 +02:00
|
|
|
fi
|
2019-12-03 01:14:35 +01:00
|
|
|
|
|
|
|
# download package files if any non-local location exists
|
2019-11-30 13:44:02 +01:00
|
|
|
for remotepkg in "${remotepkgs[@]}"; do
|
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 c14338c0fe71a74f5e56b4f3af7c548fe0928e15
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-12-17 01:27:27 +01:00
|
|
|
if [[ $remotepkg != file://* ]]; then
|
|
|
|
msg2 "Downloading current versions"
|
|
|
|
arch-nspawn "$copydir" pacman --noconfirm -Swdd "${pkgnames[@]}"
|
|
|
|
mapfile -t remotepkgs < <(pacman --config "$copydir"/etc/pacman.conf \
|
|
|
|
--dbpath "$copydir"/var/lib/pacman \
|
|
|
|
-Sddp "${pkgnames[@]}")
|
|
|
|
break
|
|
|
|
fi
|
2019-11-30 13:09:14 +01:00
|
|
|
done
|
2019-12-03 01:14:35 +01:00
|
|
|
|
2019-11-30 13:09:14 +01:00
|
|
|
msg2 "Checking packages"
|
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 c14338c0fe71a74f5e56b4f3af7c548fe0928e15
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
2019-12-17 01:27:27 +01:00
|
|
|
sudo -u "$makepkg_user" checkpkg --rmdir --warn "${remotepkgs[@]/#file:\/\//}"
|
2019-09-11 23:10:04 +02:00
|
|
|
fi
|
2019-02-13 08:02:40 +01:00
|
|
|
true
|
|
|
|
fi
|