diff options
Diffstat (limited to 'src/chroot-tools/makechrootpkg.sh.patch')
-rw-r--r-- | src/chroot-tools/makechrootpkg.sh.patch | 450 |
1 files changed, 239 insertions, 211 deletions
diff --git a/src/chroot-tools/makechrootpkg.sh.patch b/src/chroot-tools/makechrootpkg.sh.patch index 505b96a..f5b8ed7 100644 --- a/src/chroot-tools/makechrootpkg.sh.patch +++ b/src/chroot-tools/makechrootpkg.sh.patch @@ -1,52 +1,81 @@ ---- makechrootpkg.sh.in -+++ makechrootpkg.sh.ugly -@@ -12,12 +12,7 @@ +--- makechrootpkg.sh.in 2013-09-08 23:01:20.000000000 -0400 ++++ makechrootpkg.sh.ugly 2013-09-09 15:43:06.000000000 -0400 +@@ -12,6 +12,7 @@ shopt -s nullglob --# So that usage conflicts between upstream and -par mkarchroot don't get hidden --# silently in a merge. --archroot() { -- mkarchroot "$@" --} -- +init_variables() { - makepkg_args='-s --noconfirm -L' + _makepkg_args=(-s --noconfirm -L --holdver) + makepkg_args=("${_makepkg_args[@]}") repack=false - update_first=false -@@ -28,13 +23,14 @@ - temp_chroot=false - chrootdir= - passeddir= --declare -a install_pkgs --declare -i ret=0 -+declare -ag install_pkgs -+declare -ig ret=0 +@@ -26,9 +27,10 @@ + declare -i ret=0 copy=$USER - [[ -n $SUDO_USER ]] && copy=$SUDO_USER +-[[ -n $SUDO_USER ]] && copy=$SUDO_USER ++[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER [[ -z "$copy" || $copy = root ]] && copy=copy src_owner=${SUDO_USER:-$USER} +} usage() { echo "Usage: ${0##*/} [options] -r <chrootdir> [--] [makepkg args]" -@@ -69,6 +65,7 @@ +@@ -62,6 +64,7 @@ exit 1 } +parse_options_init() { - while getopts 'hcudr:I:l:nT' arg; do + while getopts 'hcur:I:l:nT' arg; do case "$arg" in h) usage ;; -@@ -129,8 +126,20 @@ - # Note this is the same FD number as in mkarchroot - lock_open_write 9 "$copydir" \ - "Waiting for existing lock on chroot copy to be released: [$copy]" +@@ -86,9 +89,6 @@ + [[ ! -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" + +-# Detect chrootdir filesystem type +-chroottype=$(stat -f -c %T "$chrootdir") +- + if [[ ${copy:0:1} = / ]]; then + copydir=$copy + else +@@ -103,30 +103,47 @@ + repack=true + fi + +-if [[ -n $SUDO_USER ]]; then ++if [[ -n ${SUDO_USER:-} ]]; then + USER_HOME=$(eval echo ~$SUDO_USER) + else + USER_HOME=$HOME + fi +} -+ -+# Usage: chroot_sync $CHROOTDIR/$CHROOT [$CHROOTCOPY|$copydir] -+chroot_sync() { + + # {{{ functions ++# Usage: load_vars $makepkg_conf ++# Globals: ++# - SRCDEST ++# - LOGDEST ++# - PKGDEST ++# - MAKEFLAGS ++# - PACKAGER + load_vars() { + local makepkg_conf="$1" var + + [[ -f $makepkg_conf ]] || return 1 + + for var in {SRC,PKG,LOG}DEST MAKEFLAGS PACKAGER; do +- [[ -z ${!var} ]] && eval $(grep "^${var}=" "$makepkg_conf") ++ [[ -z ${!var:-} ]] && eval $(grep "^${var}=" "$makepkg_conf") + done + + 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='' @@ -55,221 +84,220 @@ + else + copydir="$chrootdir/$copy" + fi ++ ++ # Detect chrootdir filesystem type + local chroottype=$(stat -f -c %T "$chrootdir") --if [[ ! -d $copydir ]] || $clean_first; then - # Get a read lock on the root chroot to make - # sure we don't clone a half-updated chroot - lock_open_read 8 "$chrootdir/root" \ -@@ -152,9 +161,16 @@ +- if [[ ! -d $copydir ]] || $clean_first; then + # 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" +@@ -147,10 +164,15 @@ - # Drop the read lock again - lock_close 8 --fi -+} + # Drop the read lock again + lock_close 8 +- fi + } + +-clean_temporary() { ++# Usage: delete_chroot $copydir [$copy] ++delete_chroot() { ++ local copydir=$1 ++ local copy=${2:-$copydir} ++ # Detect chrootdir filesystem type ++ local chroottype=$(stat -f -c %T "$copydir") + -+# Usage: chroot_install_pkgs $copydir $pkgs... -+chroot_install_pkgs() { + stat_busy "Removing temporary copy [%s]" "$copy" + if [[ "$chroottype" == btrfs ]]; then + btrfs subvolume delete "$copydir" >/dev/null || +@@ -166,9 +188,14 @@ + stat_done + } + ++# Usage: install_packages $copydir $pkgs... + install_packages() { + local copydir=$1 -+ shift ++ local install_pkgs=("${@:2}") + declare -i ret=0 -+ declare -a install_pkgs=("$@") -+ local pkgname + local pkgname --if [[ -n "${install_pkgs[*]}" ]]; then ++ local install_pkg for install_pkg in "${install_pkgs[@]}"; do pkgname="${install_pkg##*/}" cp "$install_pkg" "$copydir/$pkgname" -@@ -165,10 +181,10 @@ +@@ -179,11 +206,19 @@ rm "$copydir/$pkgname" done -- # If there is no PKGBUILD we have done +- # If there is no PKGBUILD we are done - [[ -f PKGBUILD ]] || exit $ret --fi + return $ret -+} + } -+func1() { - $update_first && archroot -u "$copydir" ++# 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" - mkdir -p "$copydir/build" -@@ -230,14 +246,24 @@ - # Set target CARCH as it might be used within the PKGBUILD to select correct sources - eval $(grep '^CARCH=' "$copydir/etc/makepkg.conf") - export CARCH -+} + mkdir -p "$copydir/build" +@@ -217,12 +252,12 @@ -+# Usage: chroot_copy_in $copydir -+# Environment: -+# - In the dirctory of a PKGBUILD -+# - $SRCDEST is set -+chroot_copy_in() { -+local copydir=$1 - # Copy PKGBUILD and sources --cp PKGBUILD "$copydir/build/" -+for recipe in PKGBUILD SRCBUILD; do -+if [[ -f $recipe ]]; then -+cp $recipe "$copydir/build/" - ( -- source PKGBUILD -- for file in "${source[@]}"; do -+ source $recipe -+ for file in "${source[@]}" "${mksource[@]}"; do - file="${file%%::*}" - file="${file##*://*/}" -+ file="${file##*://}" - if [[ -f $file ]]; then - cp "$file" "$copydir/srcdest/" - elif [[ -f $SRCDEST/$file ]]; then -@@ -251,18 +277,30 @@ - # evaluate any bash variables used - eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\" - [[ -f $file ]] && cp "$file" "$copydir/build/" -- done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD) -+ done < <(sed -n "s/^[[:space:]]*$i=//p" $recipe) - done - ) -+fi -+done + chown -R nobody "$copydir"/{build,pkgdest,logdest,srcdest,startdir} - chown -R nobody "$copydir"/{build,pkgdest,srcdest} -+} +- if [[ -n $MAKEFLAGS ]]; then ++ if [[ -n ${MAKEFLAGS:-} ]]; then + sed -i '/^MAKEFLAGS=/d' "$copydir/etc/makepkg.conf" + echo "MAKEFLAGS='${MAKEFLAGS}'" >> "$copydir/etc/makepkg.conf" + fi -+# Usage: chroot_let_nobody_use_pacman $copydir -+chroot_let_nobody_use_pacman() { -+local copydir=$1 - cat > "$copydir/etc/sudoers.d/nobody-pacman" <<EOF - Defaults env_keep += "HOME" - nobody ALL = NOPASSWD: /usr/bin/pacman - EOF - chmod 440 "$copydir/etc/sudoers.d/nobody-pacman" -+} +- if [[ -n $PACKAGER ]]; then ++ if [[ -n ${PACKAGER:-} ]]; then + sed -i '/^PACKAGER=/d' "$copydir/etc/makepkg.conf" + echo "PACKAGER='${PACKAGER}'" >> "$copydir/etc/makepkg.conf" + fi +@@ -235,6 +270,14 @@ + chmod 440 "$copydir/etc/sudoers.d/nobody-pacman" + fi -+# Usage: chroot_build $copydir $makepkg_args $run_namcap -+chroot_build() { -+local copydir=$1 -+local makepkg_args=$2 -+local run_namcap=$3 - # This is a little gross, but this way the script is recreated every time in the - # working copy - cat >"$copydir/chrootbuild" <<EOF -@@ -284,37 +322,62 @@ - exit 0 - EOF - chmod +x "$copydir/chrootbuild" -+archroot -r "$copydir" "/chrootbuild" -+} ++ if ! grep -q '^\[repo\]' "$copydir/etc/pacman.conf"; then ++ cat >> "$copydir/etc/pacman.conf" <<EOF ++[repo] ++SigLevel = Optional TrustAll ++Server = file:///repo ++EOF ++ fi ++ + # 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 @@ + chmod +x "$copydir/chrootbuild" + } --if archroot -r "$copydir" "/chrootbuild"; then -+# Usage: chroot_add_to_local_repo $copydir $pkgfiles... -+chroot_add_to_local_repo() { -+ local copydir=$1; shift - mkdir -p "$copydir/repo" -- for pkgfile in "$copydir"/pkgdest/*.pkg.tar.?z; do -- if $add_to_db; then -+ for pkgfile in "$@"; do - cp "$pkgfile" "$copydir/repo" - pushd "$copydir/repo" >/dev/null - repo-add repo.db.tar.gz "${pkgfile##*/}" - popd >/dev/null -- fi -+ done -+} ++# Usage: download_sources $copydir $src_owner ++# Globals: ++# - SRCDEST + download_sources() { ++ local copydir=$1 ++ local src_owner=$2 ++ + local builddir="$(mktemp -d)" + chmod 1777 "$builddir" + + # Ensure sources are downloaded +- if [[ -n $SUDO_USER ]]; then +- sudo -u $SUDO_USER env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ ++ if [[ $USER != $src_owner ]]; then ++ sudo -u $src_owner env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ + makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o + else + ( export SRCDEST BUILDDIR="$builddir" +@@ -258,7 +307,7 @@ + (( $? != 0 )) && die "Could not download sources." + + # Clean up garbage from verifysource +- rm -rf $builddir ++ rm -rf "$builddir" + } + + _chrootbuild() { +@@ -295,6 +344,7 @@ -+# Usage: chroot_copy_out_pkgs $copydir $user -+# Environment: -+# - $PKGDEST is set -+chroot_copy_out_pkgs() { + # Safety check + if [[ ! -w PKGBUILD ]]; then ++ # XXX: internationalize this message + echo "Can't write to PKGBUILD!" + exit 1 + fi +@@ -312,12 +362,24 @@ + exit 0 + } + ++# Usage: move_products $copydir $owner ++# Globals: ++# - PKGDEST ++# - LOGDEST + move_products() { + local copydir=$1 + local src_owner=$2 -+ for pkgfile in "$copydir"/pkgdest/*.pkg.tar*; do ++ ++ local pkgfile + for pkgfile in "$copydir"/pkgdest/*; do chown "$src_owner" "$pkgfile" mv "$pkgfile" "$PKGDEST" -+ if [[ $PKGDEST != . ]]; then ++ if [[ $PKGDEST != $PWD ]]; then + ln -sf "$PKGDEST/${pkgfile##*/}" . + fi done -+} -- for l in "$copydir"/build/*-{build,check,namcap,package,package_*}.log; do -+# Usage: chroot_copy_out_pkgs $copydir $user -+chroot_copy_out_logs() { -+ local copydir=$1 -+ local src_owner=$2 -+ for l in "$copydir"/build/*.log; do ++ local l + for l in "$copydir"/logdest/*; do chown "$src_owner" "$l" - [[ -f $l ]] && mv "$l" . - done --else -- # Just in case. We returned 1, make sure we fail -- ret=1 --fi -+} + mv "$l" "$LOGDEST" +@@ -325,6 +387,10 @@ + } + # }}} -+# Usage: chroot_copy_out_srcs $copydir $user -+# Environment: -+# - $SRCDEST is set -+chroot_copy_out_srcs() { -+local copydir=$1 -+local src_owner=$2 - for f in "$copydir"/srcdest/*; do - chown "$src_owner" "$f" - mv "$f" "$SRCDEST" - done -+} ++main() { ++init_variables ++parse_options_init ++ + umask 0022 --if $temp_chroot; then -- stat_busy "Removing temporary directoy [$copy]" -+# Usage: chroot_delete $copydir -+chroot_delete() { -+ local chroottype=$(stat -f -c %T "$copydir") -+ stat_busy "Removing chroot copy [$copydir]" - if [[ "$chroottype" == btrfs ]]; then - btrfs subvolume delete "$copydir" >/dev/null || - die "Unable to delete subvolume $copydir" -@@ -326,8 +389,39 @@ - # remove lock file - rm --force "$copydir.lock" - stat_done --elif (( ret != 0 )); then -- die "Build failed, check $copydir/build" --else -- true --fi -+} + load_vars /etc/makepkg.conf +@@ -335,27 +401,37 @@ + [[ -d $SRCDEST ]] || SRCDEST=$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" + -+main() { -+ init_variables -+ parse_options_init "$@" -+ if [[ ! -d $copydir ]] || $clean_first; then -+ chroot_sync "$chrootdir" "$copy" -+ fi -+ if [[ -n "${install_pkgs[*]}" ]]; then -+ chroot_install_pkgs "$copydir" "${install_pkgs[@]}" -+ ret=$? -+ # If there is no PKGBUILD we have done -+ [[ -f PKGBUILD ]] || exit $ret -+ fi -+ func1 -+ chroot_copy_in "$copydir" -+ chroot_let_nobody_use_pacman "$copydir" -+ chroot_build "$copydir" "$makepkg_args" "$run_namcap" -+ func2 -+ if chroot_build; then -+ chroot_add_to_local_repo "$copydir" "$copydir"/pkgdest/*.pkg.tar* -+ chroot_copy_out_pkgs "$copydir" "$src_owner" -+ chroot_copy_out_logs "$copydir" "$src_owner" -+ else -+ # Just in case. We returned 1, make sure we fail -+ ret=1 -+ fi -+ chroot_copy_out_srcs "$copydir" "$src_owner" -+ if $temp_chroot; then -+ chroot_delete "$copydir" -+ elif (( ret != 0 )); then -+ die "Build failed, check $copydir/build" -+ else -+ true -+ fi ++if [[ ! -d $copydir ]] || $clean_first; then ++ sync_chroot "$chrootdir" "$copy" ++fi + + $update_first && arch-nspawn "$copydir" 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 ]] || exit $ret ++fi + +-prepare_chroot ++prepare_chroot "$copydir" "$USER_HOME" "$repack" + +-download_sources ++download_sources "$copydir" "$src_owner" + + if arch-nspawn "$copydir" \ + --bind-ro="$PWD:/startdir_host" \ + --bind-ro="$SRCDEST:/srcdest_host" \ + /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 +@@ -366,3 +442,4 @@ + else + true + fi +} |