summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--makechrootpkg.in88
1 files changed, 75 insertions, 13 deletions
diff --git a/makechrootpkg.in b/makechrootpkg.in
index 0650f2d..e18e68f 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -76,6 +76,14 @@ usage() {
}
# {{{ functions
+# Usage: load_vars $makepkg_conf
+# Globals:
+# - SRCDEST
+# - SRCPKGDEST
+# - PKGDEST
+# - LOGDEST
+# - MAKEFLAGS
+# - PACKAGER
load_vars() {
local makepkg_conf="$1" var
@@ -88,11 +96,23 @@ load_vars() {
return 0
}
-create_chroot() {
- # Lock the chroot we want to use. We'll keep this lock until we exit.
- lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy"
+# Usage: sync_chroot $CHROOTDIR/$CHROOT <$CHROOTCOPY|$copydir>
+sync_chroot() {
+ local chrootdir=$1
+ local copy=$2
+ local copydir=''
+ if [[ ${copy:0:1} = / ]]; then
+ copydir=$copy
+ else
+ copydir="$chrootdir/$copy"
+ fi
+
+ if [[ "$chrootdir/root" -ef "$copydir" ]]; then
+ error 'Cannot sync copy with itself: %s' "$copydir"
+ return 1
+ fi
- if [[ ! -d $copydir ]] || $clean_first; then
+ if true; then # indent for rebasing/merging purposes
# Get a read lock on the root chroot to make
# sure we don't clone a half-updated chroot
slock 8 "$chrootdir/root.lock" "Locking clean chroot"
@@ -117,7 +137,11 @@ create_chroot() {
touch "$copydir"
}
-clean_temporary() {
+# Usage: delete_chroot $copydir [$copy]
+delete_chroot() {
+ local copydir=$1
+ local copy=${1:-$2}
+
stat_busy "Removing temporary copy [%s]" "$copy"
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
btrfs subvolume delete "$copydir" >/dev/null ||
@@ -133,7 +157,11 @@ clean_temporary() {
stat_done
}
+# Usage: install_packages $copydir $pkgs...
install_packages() {
+ local copydir=$1
+ local install_pkgs=("${@:2}")
+
local -a pkgnames
local ret
@@ -145,11 +173,19 @@ install_packages() {
ret=$?
rm -- "${pkgnames[@]/#/$copydir/root/}"
- # If there is no PKGBUILD we are done
- [[ -f PKGBUILD ]] || exit $ret
+ return $ret
}
+# Usage: prepare_chroot $copydir $HOME $repack $run_namcap
+# Globals:
+# - MAKEFLAGS
+# - PACKAGER
prepare_chroot() {
+ local copydir=$1
+ local USER_HOME=$2
+ local repack=$3
+ local run_namcap=$4
+
$repack || rm -rf "$copydir/build"
local builduser_uid="${SUDO_UID:-$UID}"
@@ -214,7 +250,14 @@ _chrootnamcap() {
done
}
+# Usage: download_sources $copydir $src_owner
+# Globals:
+# - SRCDEST
+# - USER
download_sources() {
+ local copydir=$1
+ local src_owner=$2
+
local builddir="$(mktemp -d)"
chmod 1777 "$builddir"
@@ -233,7 +276,15 @@ download_sources() {
rm -rf "$builddir"
}
+# Usage: move_products $copydir $owner
+# Globals:
+# - PKGDEST
+# - LOGDEST
move_products() {
+ local copydir=$1
+ local src_owner=$2
+
+ local pkgfile
for pkgfile in "$copydir"/pkgdest/*; do
chown "$src_owner" "$pkgfile"
mv "$pkgfile" "$PKGDEST"
@@ -244,6 +295,7 @@ move_products() {
fi
done
+ local l
for l in "$copydir"/logdest/*; do
[[ $l == */logpipe.* ]] && continue
chown "$src_owner" "$l"
@@ -319,17 +371,27 @@ load_vars /etc/makepkg.conf
[[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD
[[ -d $LOGDEST ]] || LOGDEST=$PWD
-create_chroot
+# Lock the chroot we want to use. We'll keep this lock until we exit.
+lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy"
+
+if [[ ! -d $copydir ]] || $clean_first; then
+ sync_chroot "$chrootdir" "$copy"
+fi
$update_first && arch-nspawn "$copydir" \
"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
pacman -Syu --noconfirm
-[[ -n ${install_pkgs[*]} ]] && install_packages
+if [[ -n ${install_pkgs[*]} ]]; then
+ install_packages "$copydir" "${install_pkgs[@]}"
+ ret=$?
+ # If there is no PKGBUILD we have done
+ [[ -f PKGBUILD ]] || return $ret
+fi
-download_sources
+download_sources "$copydir" "$src_owner"
-prepare_chroot
+prepare_chroot "$copydir" "$USER_HOME" "$repack"
if arch-nspawn "$copydir" \
--bind="$PWD:/startdir" \
@@ -337,12 +399,12 @@ if arch-nspawn "$copydir" \
"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
/chrootbuild "${makepkg_args[@]}"
then
- move_products
+ move_products "$copydir" "$src_owner"
else
(( ret += 1 ))
fi
-$temp_chroot && clean_temporary
+$temp_chroot && delete_chroot "$copydir" "$copy"
if (( ret != 0 )); then
if $temp_chroot; then