summaryrefslogtreecommitdiffstats
path: root/makechrootpkg
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-03-26 09:58:28 +0100
committerPierre Schmitz <pierre@archlinux.de>2011-03-26 09:58:28 +0100
commitbdde6e5a35a697603e9637bbc0e153b1d2fa4320 (patch)
treec2f8d0e62288a3fa23295a83f241e5d0edb59dd7 /makechrootpkg
parent38f85d654aa93401fd90cbe44994ea894f73635f (diff)
parent2fa8fdec478529cd8649d38f9bfe2e50a3e28469 (diff)
downloaddevtools-bdde6e5a35a697603e9637bbc0e153b1d2fa4320.tar.gz
devtools-bdde6e5a35a697603e9637bbc0e153b1d2fa4320.tar.xz
Merge branch 'master', remote-tracking branch 'heftig/master'
Diffstat (limited to 'makechrootpkg')
-rwxr-xr-xmakechrootpkg65
1 files changed, 55 insertions, 10 deletions
diff --git a/makechrootpkg b/makechrootpkg
index 9cd2841..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 <chrootdir> [--] [makepkg args]"
echo ' Run this script in a PKGBUILD dir to build a package inside a'
@@ -50,7 +53,8 @@ usage() {
echo '-r <dir> The chroot dir to use'
echo '-I <pkg> Install a package into the working copy of the chroot'
echo '-l <copy> 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,14 +66,16 @@ 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
-#Get rid of trailing / in chrootdir
-[ "$chrootdir" != "/" ] && chrootdir=$(echo $chrootdir | sed 's#/$##')
-copydir="$chrootdir/$COPY"
+# Canonicalize chrootdir, getting rid of trailing /
+chrootdir=$(readlink -e "$chrootdir")
+
+[[ -z $copy ]] && copy=$default_copy
+copydir="$chrootdir/$copy"
# Pass all arguments after -- right to makepkg
MAKEPKG_ARGS="$MAKEPKG_ARGS ${*:$OPTIND}"
@@ -104,11 +110,44 @@ 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"
+ 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
+ exec 8>&-
fi
if [ -n "$install_pkg" ]; then
@@ -160,9 +199,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")