summaryrefslogtreecommitdiff
path: root/src/chroot-tools/libremakepkg
diff options
context:
space:
mode:
Diffstat (limited to 'src/chroot-tools/libremakepkg')
-rwxr-xr-xsrc/chroot-tools/libremakepkg60
1 files changed, 45 insertions, 15 deletions
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index f5f4855..c6faf31 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -110,24 +110,32 @@ chroot_cleanup() {
build() (
local copydir=$1
- local repack=$2
- local makepkg_args=("${@:3}")
+ local srcpkg=$2
+ local repack=$3
+ local makepkg_args=("${@:4}")
+
+ local startdir
+ startdir=$(mktemp -d)
+ chown "$LIBREUSER:" "$startdir"
+ trap "rm -rf -- ${startdir@Q}" EXIT
+ sudo -u "$LIBREUSER" bsdtar -xf "$srcpkg" -C "$startdir" --strip-components 1
local run_ynet=()
local run_nnet=()
if $INCHROOT; then
- run_ynet=(unshare)
- run_nnet=(unshare --net)
+ local _run=(sh -c "mount --bind -o ro -- ${startdir@Q} ${startdir@Q} && cd ${startdir@Q} && \$@" --)
+ run_ynet=(unshare --mount -- "${_run[@]}")
+ run_nnet=(unshare --mount --net -- "${_run[@]}")
else
+ librechroot_flags+=(-r "$startdir:/startdir")
run_ynet=(librechroot "${librechroot_flags[@]}" run)
run_nnet=(librechroot "${librechroot_flags[@]}" -N run)
fi
$NONET || run_nnet=("${run_ynet[@]}")
prepare_chroot "$copydir" "$LIBREHOME" "$repack" false
- "${run_ynet[@]}" /chrootprepare "${makepkg_args[@]}" |& indent
run_hook pre_build "$copydir"
- trap "run_hook post_build ${copydir@Q}" EXIT
+ trap "run_hook post_build ${copydir@Q}; rm -rf -- ${startdir@Q}" EXIT
"${run_nnet[@]}" /chrootbuild "${makepkg_args[@]}" |& indent
)
@@ -166,10 +174,10 @@ usage() {
flag "-w <$(_ 'PATH[:PATH]')>" 'Bind mount a file or directory, read/write'
flag "-r <$(_ 'PATH[:PATH]')>" 'Bind mount a file or directory, read-only'
print ' %s options:' libremakepkg
- flag '-N' "Don't disable networking during build() and
- package(). PLEASE don't use this unless you
- have a special reason, its use is a violation
- of Parabola policy."
+ flag '-N' "Don't disable networking during prepare(),
+ build(), and package(). PLEASE don't use this
+ unless you have a special reason, its use is a
+ violation of Parabola policy."
flag '-R' 'Repackage contents of the package without rebuilding'
flag '-h' 'Show this message'
}
@@ -248,7 +256,7 @@ main() {
fi
# Make sure that the various *DEST directories exist
- mkdir -p -- "$PKGDEST" "$SRCDEST" "$SRCPKGDEST" "$LOGDEST"
+ sudo -u "$LIBREUSER" mkdir -p -- "$PKGDEST" "$SRCDEST" "$SRCPKGDEST" "$LOGDEST"
# OK, we are starting now ##############################################
@@ -257,8 +265,6 @@ main() {
"Waiting for existing lock on build directory to be released"
else
librechroot_flags+=(
- -w "$PWD:/startdir"
- -w "$SRCDEST:/srcdest"
-n "$CHROOT"
-l "$copy"
)
@@ -279,13 +285,37 @@ main() {
# Pre-build
msg 'Starting pre-build activities...'
run_hook check_pkgbuild
+
msg 'Downloading sources...'
- download_sources "$copydir" "$LIBREUSER" |& indent
+ local srcpkgdest srcpkg
+ srcpkgdest="$(mktemp -d)"
+ chown "$LIBREUSER:" "$srcpkgdest"
+ trap "rm -rf -- ${srcpkgdest@Q}" EXIT
+ SRCPKGDEST="$srcpkgdest" download_sources "$copydir" "$LIBREUSER" |& indent
+ srcpkg=("$srcpkgdest"/*)
+ if (( ${#srcpkg[@]} != 1 )); then
+ error 'Something went funny with makepkg --allsource'
+ return $EXIT_FAILURE
+ fi
+ # We want to inject "-$pkgarch" in to srcpkg's filename, right before $SRCEXT
+ local srcext pkgarch srcpkg_filename
+ srcext="$(MAKEPKG_CONF=$copydir/etc/makepkg.conf get_var makepkg SRCEXT)"
+ if [[ "$(bsdtar xfO "$srcpkg" --include='*/.SRCINFO' | grep $'\tarch =')" = $'\tarch = any' ]]; then
+ pkgarch=any
+ else
+ pkgarch=$CARCH
+ fi
+ srcpkg_filename=${srcpkg##*/}
+ srcpkg_filename=${srcpkg_filename%"${srcext}"}-${pkgarch}${srcext}
+ mv -T -- "$srcpkg" "$SRCPKGDEST/${srcpkg_filename}"
+ srcpkg="$SRCPKGDEST/${srcpkg_filename}"
+ rmdir -- "${srcpkgdest}"
+ trap EXIT
# Build
msg 'Starting to build the package...'
trap "exit_copy '$copydir' '$LIBREUSER'" EXIT
- build "$copydir" "$repack" "${makepkg_args[@]}"
+ build "$copydir" "$srcpkg" "$repack" "${makepkg_args[@]}"
# Post-build
msg 'Starting post-build activities...'