summaryrefslogtreecommitdiff
path: root/src/chroot-tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/chroot-tools')
-rw-r--r--src/chroot-tools/hooks-chcleanup.sh3
-rwxr-xr-xsrc/chroot-tools/librechroot2
-rwxr-xr-xsrc/chroot-tools/libremakepkg73
-rw-r--r--src/chroot-tools/makechrootpkg.sh.patch68
4 files changed, 105 insertions, 41 deletions
diff --git a/src/chroot-tools/hooks-chcleanup.sh b/src/chroot-tools/hooks-chcleanup.sh
index 09e6dd9..198bc36 100644
--- a/src/chroot-tools/hooks-chcleanup.sh
+++ b/src/chroot-tools/hooks-chcleanup.sh
@@ -10,7 +10,6 @@ clean_chroot() (
cd /build
sudo -u nobody "$(librelib chroot/chcleanup)"
else
- librechroot -l "$copydir" clean-pkgs
+ librechroot "${librechroot_flags[@]}" clean-pkgs
fi
- r=$?; echo clean_chroot returning $r; return $r
)
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index 0b3ad43..cb7fe1b 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -88,7 +88,7 @@ usage() {
unless the copy name is manually specified as an absolute path,
in which case, that path is used.'
echo
- prose 'The current settings for the above varibles are:'
+ prose 'The current settings for the above variables are:'
printf ' CHROOTDIR : %s\n' "${CHROOTDIR:-$(_ 'ERROR: NO SETTING')}"
printf ' CHROOT : %s\n' "${CHROOT:-$(_ 'ERROR: NO SETTING')}"
printf ' COPY : %s\n' "$COPY"
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index a59315b..df4cd07 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -25,6 +25,7 @@ set -euE
. $(librelib messages)
. $(librelib chroot/makechrootpkg.sh)
+set -o pipefail
shopt -s nullglob
umask 0022
@@ -34,6 +35,7 @@ NONET=true # can be changed with the -N flag
# {SRC,LOG,PKG}DEST set at runtime by makepkg.conf
# MAKEFLAGS, PACKAGER set at runtime by makepkg.conf
# LIBREUSER, LIBREHOME are set by conf.sh
+librechroot_flags=()
# Hooks ########################################################################
@@ -47,6 +49,10 @@ hook_check_pkg=(:)
# Boring/mundane functions #####################################################
+indent() {
+ sed 's/^/ | /'
+}
+
# Usage: exit_copy $copydir $src_owner
# End immediately, but copy log files out
exit_copy() {
@@ -62,17 +68,18 @@ exit_copy() {
run_hook() {
local hookname=$1; shift
local hookvar="hook_${hookname}[@]"
+
local fails=()
- msg "Running hook: %s" "$hookname"
for hook in "${!hookvar}"; do
- msg2 'hook: %s' "$hook"
- "$hook" "$@" || { error "result: %s" $?; fails+=("$hook"); }
- done
+ "$hook" "$@" || fails+=("$hook")
+ done |& indent
+
if [[ ${#fails[@]} -gt 0 ]]; then
error "Failure(s) in %s: %s" "$hookname" "${fails[*]}"
return 1
+ else
+ return 0
fi
- return 0
}
# Usage: add_to_local_repo $copydir $pkgfiles...
@@ -88,25 +95,31 @@ add_to_local_repo() {
done
}
+hook_post_build+=('cleanup')
+cleanup() {
+ local copydir=$1
+ rm -f -- "$copydir"/chroot{prepare,build}
+}
+
build() (
local copydir=$1; shift
- local cmd=(/chrootbuild "$@")
-
- run_hook pre_build "$copydir"
- trap "run_hook post_build '$copydir'" EXIT
+ local repack=$1; shift
local netflag=''
+ local run=()
if $INCHROOT; then
- ! $NONET || netflag='-n'
- unshare $netflag -- "${cmd[@]}"
- else
! $NONET || netflag='-N'
- librechroot $netflag \
- -r "$PWD:/startdir_host" \
- -r "$SRCDEST:/srcdest_host" \
- -l "$copydir" \
- run "${cmd[@]}"
+ run=(unshare)
+ else
+ ! $NONET || netflag='-n'
+ run=(librechroot "${librechroot_flags[@]}" run)
fi
+
+ prepare_chroot "$copydir" "$LIBREHOME" "$repack" false
+ "${run[@]}" /chrootprepare "$@" |& indent
+ run_hook pre_build "$copydir"
+ trap "run_hook post_build '$copydir'" EXIT
+ "${run[@]}" /chrootbuild "$@" |& indent
)
# The main program #############################################################
@@ -212,6 +225,13 @@ main() {
MAKEFLAGS="$(get_conf_makepkg MAKEFLAGS '')"
PACKAGER="$(get_conf_makepkg PACKAGER '')"
+ librechroot_flags=(
+ -r "$PWD:/startdir_host"
+ -r "$SRCDEST:/srcdest_host"
+ -n "$CHROOT"
+ -l "$copy"
+ )
+
# OK, we are starting now ##############################################
if $INCHROOT; then
@@ -222,7 +242,8 @@ main() {
lock 9 "$copydir.lock" \
"Waiting for existing lock on chroot copy to be released: [%s]" "$copy"
# Create the chroot if it does not exist
- librechroot -n "$CHROOT" -l "$copy" make
+ msg 'Initializing the chroot...'
+ librechroot "${librechroot_flags[@]}" make |& indent
fi
# Set target CARCH
@@ -230,20 +251,20 @@ main() {
export CARCH="$(MAKEPKG_CONF=$copydir/etc/makepkg.conf get_conf_makepkg CARCH)"
# Pre-build
+ msg 'Starting pre-build activities...'
run_hook check_pkgbuild
- download_sources "$copydir" "$LIBREUSER"
- prepare_chroot "$copydir" "$LIBREHOME" "$repack" false
- clean_chroot "$copydir"
+ msg 'Downloading sources...'
+ download_sources "$copydir" "$LIBREUSER" |& indent
# Build
+ msg 'Starting to build the package...'
trap "exit_copy '$copydir' '$LIBREUSER'" EXIT
- warning 'Entering build...'
- build "$copydir" "${makepkg_args[@]}"
+ build "$copydir" "$repack" "${makepkg_args[@]}"
+
# Post-build
- warning 'Entering hook check_pkg...'
+ msg 'Starting post-build activities...'
run_hook check_pkg
- warning 'Entering add_to_local_repo ...'
- add_to_local_repo "$copydir" "$copydir"/pkgdest/*.pkg.tar*
+ add_to_local_repo "$copydir" "$copydir"/pkgdest/*.pkg.tar* |& indent
}
main "$@"
diff --git a/src/chroot-tools/makechrootpkg.sh.patch b/src/chroot-tools/makechrootpkg.sh.patch
index f5b8ed7..275b88a 100644
--- a/src/chroot-tools/makechrootpkg.sh.patch
+++ b/src/chroot-tools/makechrootpkg.sh.patch
@@ -1,5 +1,5 @@
---- makechrootpkg.sh.in 2013-09-08 23:01:20.000000000 -0400
-+++ makechrootpkg.sh.ugly 2013-09-09 15:43:06.000000000 -0400
+--- makechrootpkg.sh.in 2013-09-12 10:02:36.000000000 -0400
++++ makechrootpkg.sh.ugly 2013-09-14 13:51:51.000000000 -0400
@@ -12,6 +12,7 @@
shopt -s nullglob
@@ -162,7 +162,7 @@
sed -i '/^PACKAGER=/d' "$copydir/etc/makepkg.conf"
echo "PACKAGER='${PACKAGER}'" >> "$copydir/etc/makepkg.conf"
fi
-@@ -235,6 +270,14 @@
+@@ -235,20 +270,37 @@
chmod 440 "$copydir/etc/sudoers.d/nobody-pacman"
fi
@@ -176,8 +176,12 @@
+
# This is a little gross, but this way the script is recreated every time in the
# working copy
- printf $'#!/bin/bash\n%s\n_chrootbuild %q "$@"' "$(declare -f _chrootbuild)" \
-@@ -242,13 +285,19 @@
+- printf $'#!/bin/bash\n%s\n_chrootbuild %q "$@"' "$(declare -f _chrootbuild)" \
++ printf '#!/bin/bash\n%s\n_chrootprepare "$@"' "$(declare -f _chrootprepare)" \
++ > "$copydir/chrootprepare"
++ chmod +x "$copydir/chrootprepare"
++ printf '#!/bin/bash\n%s\n_chrootbuild %q "$@"' "$(declare -f _chrootbuild)" \
+ "$run_namcap" >"$copydir/chrootbuild"
chmod +x "$copydir/chrootbuild"
}
@@ -199,7 +203,7 @@
makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o
else
( export SRCDEST BUILDDIR="$builddir"
-@@ -258,7 +307,7 @@
+@@ -258,20 +310,15 @@
(( $? != 0 )) && die "Could not download sources."
# Clean up garbage from verifysource
@@ -207,8 +211,48 @@
+ rm -rf "$builddir"
}
- _chrootbuild() {
-@@ -295,6 +344,7 @@
+-_chrootbuild() {
++_chrootprepare() {
+ # This function isn't run in makechrootpkg,
+ # so no global variables
+- local run_namcap="$1"; shift
+- local makepkg_args=("$@")
+-
+- . /etc/profile
+- export HOME=/build
+- shopt -s nullglob
+
+ # XXX: Workaround makepkg disliking read-only dirs
++ rm -rf -- /srcdest/* /startdir/*
+ ln -sft /srcdest /srcdest_host/*
+ ln -sft /startdir /startdir_host/*
+
+@@ -286,15 +333,27 @@
+ done
+ done
+
+- cd /startdir
+-
+ # XXX: Keep PKGBUILD writable for pkgver()
+- rm PKGBUILD*
+- cp /startdir_host/PKGBUILD* .
+- chown nobody PKGBUILD*
++ rm /startdir/PKGBUILD*
++ cp /startdir_host/PKGBUILD* /startdir
++ chown nobody /startdir/PKGBUILD*
++}
++
++_chrootbuild() {
++ # This function isn't run in makechrootpkg,
++ # so no global variables
++ local run_namcap="$1"; shift
++ local makepkg_args=("$@")
++
++ . /etc/profile
++ export HOME=/build
++ shopt -s nullglob
++
++ cd /startdir
# Safety check
if [[ ! -w PKGBUILD ]]; then
@@ -216,7 +260,7 @@
echo "Can't write to PKGBUILD!"
exit 1
fi
-@@ -312,12 +362,24 @@
+@@ -312,12 +371,24 @@
exit 0
}
@@ -241,7 +285,7 @@
for l in "$copydir"/logdest/*; do
chown "$src_owner" "$l"
mv "$l" "$LOGDEST"
-@@ -325,6 +387,10 @@
+@@ -325,6 +396,10 @@
}
# }}}
@@ -252,7 +296,7 @@
umask 0022
load_vars /etc/makepkg.conf
-@@ -335,27 +401,37 @@
+@@ -335,27 +410,37 @@
[[ -d $SRCDEST ]] || SRCDEST=$PWD
[[ -d $LOGDEST ]] || LOGDEST=$PWD
@@ -296,7 +340,7 @@
if (( ret != 0 )); then
if $temp_chroot; then
-@@ -366,3 +442,4 @@
+@@ -366,3 +451,4 @@
else
true
fi