From f72297a639cda567107f83c1da4eafa2de604d9f Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Sun, 13 Mar 2011 17:57:28 +0100 Subject: Use readlink -e to canonicalize chrootdir --- makechrootpkg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'makechrootpkg') diff --git a/makechrootpkg b/makechrootpkg index e3e2baf..726f828 100755 --- a/makechrootpkg +++ b/makechrootpkg @@ -67,8 +67,9 @@ while getopts 'hcudr:I:l:' arg; do esac done -#Get rid of trailing / in chrootdir -[ "$chrootdir" != "/" ] && chrootdir=$(echo $chrootdir | sed 's#/$##') +# Canonicalize chrootdir, getting rid of trailing / +chrootdir=$(readlink -e "$chrootdir") + copydir="$chrootdir/$COPY" # Pass all arguments after -- right to makepkg -- cgit v1.2.3-2-g168b From 2ff5c45d148ae137f0cdacf0677a53b06d272c6d Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 11 Mar 2011 23:15:53 +0100 Subject: makechrootpkg: Copy package logs with split packages (fixes FS#23239). Signed-off-by: Lukas Fleischer --- makechrootpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'makechrootpkg') diff --git a/makechrootpkg b/makechrootpkg index 726f828..9facac6 100755 --- a/makechrootpkg +++ b/makechrootpkg @@ -233,7 +233,7 @@ if mkarchroot -r "/chrootbuild" "$copydir"; then fi done - for l in "${copydir}"/build/{namcap,*-{build,package}}.log; do + for l in "${copydir}"/build/{namcap,*-{build,package,package_*}}.log; do [ -f "$l" ] && mv "$l" "${WORKDIR}" done else -- cgit v1.2.3-2-g168b From 36dc5d8792599c547889fcaa30052b7c09e7add0 Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Fri, 18 Mar 2011 08:49:37 +0100 Subject: Stop the PACKAGER= and MAKEFLAGS= from piling on Repeatedly reusing the same chroot kept adding lines to makepkg.conf. --- makechrootpkg | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'makechrootpkg') diff --git a/makechrootpkg b/makechrootpkg index 9facac6..a38a740 100755 --- a/makechrootpkg +++ b/makechrootpkg @@ -161,9 +161,15 @@ if ! grep 'SRCDEST="/srcdest"' "$copydir/etc/makepkg.conf" >/dev/null 2>&1; then echo 'SRCDEST="/srcdest"' >> "$copydir/etc/makepkg.conf" fi [ -z "${MAKEFLAGS}" ] && eval $(grep '^MAKEFLAGS=' /etc/makepkg.conf) -[ -n "${MAKEFLAGS}" ] && echo "MAKEFLAGS='${MAKEFLAGS}'" >> "$copydir/etc/makepkg.conf" +if [ -n "${MAKEFLAGS}" ]; then + sed -i '/^MAKEFLAGS=/d' "$copydir/etc/makepkg.conf" + echo "MAKEFLAGS='${MAKEFLAGS}'" >> "$copydir/etc/makepkg.conf" +fi [ -z "${PACKAGER}" ] && eval $(grep '^PACKAGER=' /etc/makepkg.conf) -[ -n "${PACKAGER}" ] && echo "PACKAGER='${PACKAGER}'" >> "$copydir/etc/makepkg.conf" +if [ -n "${PACKAGER}" ]; then + sed -i '/^PACKAGER=/d' "$copydir/etc/makepkg.conf" + echo "PACKAGER='${PACKAGER}'" >> "$copydir/etc/makepkg.conf" +fi # Set target CARCH as it might be used within the PKGBUILD to select correct sources eval $(grep '^CARCH=' "$copydir/etc/makepkg.conf") -- cgit v1.2.3-2-g168b From 174ff59dba8c24f544e354cd43f3b68aea91d265 Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Sun, 13 Mar 2011 19:06:27 +0100 Subject: Add flock-based locking to chroots This prevents accidents when chroots are shared between multiple users. --- makechrootpkg | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'makechrootpkg') diff --git a/makechrootpkg b/makechrootpkg index a38a740..1f6f20a 100755 --- a/makechrootpkg +++ b/makechrootpkg @@ -105,11 +105,34 @@ if [ ! -d "$chrootdir/root" ]; then fi umask 0022 + +# Lock the chroot we want to use. We'll keep this lock until we exit. +# Note this is the same FD number as in mkarchroot +exec 9>"$copydir.lock" +if ! flock -n 9; then + echo -n "locking chroot copy '$copy'..." + flock 9 + echo "done" +fi + if [ ! -d "$copydir" -o "$clean_first" -eq "1" ]; then + # Get a read lock on the root chroot to make + # sure we don't clone a half-updated chroot + exec 8>"$chrootdir/root.lock" + + if ! flock -sn 8; then + echo -n "locking clean chroot..." + flock -s 8 + echo "done" + fi + echo -n 'creating clean working copy...' mkdir -p "$copydir" rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" echo 'done' + + # Drop the read lock again + exec 8>&- fi if [ -n "$install_pkg" ]; then -- cgit v1.2.3-2-g168b From 0af05a48abb1d35380f4f4259deb163eb3b7b174 Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Sun, 13 Mar 2011 15:19:20 +0100 Subject: Use Btrfs snapshots for chroot copies, when available This is much faster than using Rsync to clone. Rsync stays available when the chroots are not on a Btrfs. --- makechrootpkg | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'makechrootpkg') diff --git a/makechrootpkg b/makechrootpkg index 1f6f20a..5bf492f 100755 --- a/makechrootpkg +++ b/makechrootpkg @@ -127,8 +127,18 @@ if [ ! -d "$copydir" -o "$clean_first" -eq "1" ]; then fi echo -n 'creating clean working copy...' - mkdir -p "$copydir" - rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" + use_rsync=false + if type -P btrfs >/dev/null; then + [ -d $copydir ] && btrfs subvolume delete "$copydir" &>/dev/null + btrfs subvolume snapshot "$chrootdir/root" "$copydir" &>/dev/null || use_rsync=true + else + use_rsync=true + fi + + if $use_rsync; then + mkdir -p "$copydir" + rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" + fi echo 'done' # Drop the read lock again -- cgit v1.2.3-2-g168b From 2fa8fdec478529cd8649d38f9bfe2e50a3e28469 Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Sun, 13 Mar 2011 19:07:04 +0100 Subject: Make default copydir user-dependent Eases usage when chroots are shared between multiple users. --- makechrootpkg | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'makechrootpkg') diff --git a/makechrootpkg b/makechrootpkg index 5bf492f..2a9f56b 100755 --- a/makechrootpkg +++ b/makechrootpkg @@ -12,7 +12,6 @@ FORCE='n' RUN='' MAKEPKG_ARGS='-s --noconfirm' REPACK='' -COPY='copy' WORKDIR=$PWD update_first='0' @@ -24,6 +23,10 @@ chrootdir='' APPNAME=$(basename "${0}") +default_copy=$USER +[[ -n $SUDO_USER ]] && default_copy=$SUDO_USER +[[ -z $default_copy || $default_copy = root ]] && default_copy=copy + usage() { echo "usage ${APPNAME} [options] -r [--] [makepkg args]" echo ' Run this script in a PKGBUILD dir to build a package inside a' @@ -50,7 +53,8 @@ usage() { echo '-r The chroot dir to use' echo '-I Install a package into the working copy of the chroot' echo '-l The directory to use as the working copy of the chroot' - echo ' Useful for maintain multiple copies Default: copy' + echo ' Useful for maintaining multiple copies.' + echo " Default: $default_copy" exit 1 } @@ -62,7 +66,7 @@ while getopts 'hcudr:I:l:' arg; do d) add_to_db=1 ;; r) chrootdir="$OPTARG" ;; I) install_pkg="$OPTARG" ;; - l) COPY="$OPTARG" ;; + l) copy="$OPTARG" ;; *) MAKEPKG_ARGS="$MAKEPKG_ARGS -$arg $OPTARG" ;; esac done @@ -70,7 +74,8 @@ done # Canonicalize chrootdir, getting rid of trailing / chrootdir=$(readlink -e "$chrootdir") -copydir="$chrootdir/$COPY" +[[ -z $copy ]] && copy=$default_copy +copydir="$chrootdir/$copy" # Pass all arguments after -- right to makepkg MAKEPKG_ARGS="$MAKEPKG_ARGS ${*:$OPTIND}" -- cgit v1.2.3-2-g168b