From 3491ea5d799479c9ae0da2c2864084146d61a10a Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Sat, 12 Mar 2011 15:16:31 +0100 Subject: Syntax cleanup No functional change. --- archbuild | 4 ++-- mkarchroot | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/archbuild b/archbuild index fc2ec34..3435be5 100755 --- a/archbuild +++ b/archbuild @@ -4,8 +4,8 @@ base_packages='base base-devel sudo' cmd="$(basename "${0%-build}")" if [ "${cmd%-*}" == 'multilib' ]; then - repo="${cmd}" - arch='x86_64' + repo="${cmd}" + arch='x86_64' base_packages+=' gcc-multilib libtool-multilib' else repo=${cmd%-*} diff --git a/mkarchroot b/mkarchroot index ac05a6b..254841e 100755 --- a/mkarchroot +++ b/mkarchroot @@ -26,7 +26,7 @@ usage() { echo ' -C Location of a pacman config file' echo ' -M Location of a makepkg config file' echo ' -n Do not copy config files into the chroot' - echo " -c Set pacman cache. Default: /var/cache/pacman/pkg" + echo ' -c Set pacman cache. Default: /var/cache/pacman/pkg' echo ' -h This message' exit $1 } @@ -68,7 +68,7 @@ shift 1 if [ -z "$cache_dir" ]; then cache_conf=${working_dir}/etc/pacman.conf [ ! -f $cache_conf ] && cache_conf=${pac_conf:-/etc/pacman.conf} - cache_dir=$((grep -m 1 '^CacheDir' $cache_conf || echo 'CacheDir = /var/cache/pacman/pkg') | sed 's/CacheDir\s*=\s*//') + cache_dir=$( (grep -m 1 '^CacheDir' $cache_conf || echo 'CacheDir = /var/cache/pacman/pkg') | sed 's/CacheDir\s*=\s*//') unset cache_conf fi @@ -82,8 +82,7 @@ if echo "${host_mirror}" | grep -q 'file://'; then host_mirror_path=$(echo "${host_mirror}" | sed -E 's#file://(/.*)/\$repo/os/\$arch#\1#g') fi -# {{{ functions - +# {{{ functions chroot_mount() { [ -e "${working_dir}/sys" ] || mkdir "${working_dir}/sys" mount -t sysfs sysfs "${working_dir}/sys" @@ -160,7 +159,7 @@ if [ "$RUN" != "" ]; then eval chroot "${working_dir}" ${RUN} # }}} - else +else # {{{ build chroot if [ -e "${working_dir}" -a "${FORCE}" = "n" ]; then echo "error: working dir '${working_dir}' already exists - try using -f" -- cgit v1.2.3-24-g4f1b From ba7cc139c40d77d4f9c60802313d0b5018ca44bd Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Sun, 13 Mar 2011 18:01:20 +0100 Subject: Fix spelling --- finddeps | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/finddeps b/finddeps index c47518a..5f1a808 100755 --- a/finddeps +++ b/finddeps @@ -21,14 +21,14 @@ for d in $(find . -type d); do unset pkgname depends makedepends . PKGBUILD for dep in "${depends[@]}"; do - # lose the version comaparator, if any + # lose the version comparator, if any depname=${dep%%[<>=]*} if [ "$depname" = "$match" ]; then echo "$d (depends)" fi done for dep in "${makedepends[@]}"; do - # lose the version comaparator, if any + # lose the version comparator, if any depname=${dep%%[<>=]*} if [ "$depname" = "$match" ]; then echo "$d (makedepends)" -- cgit v1.2.3-24-g4f1b 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(-) 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-24-g4f1b From 80168e7e1c55f16cabcccc23450f64a55c338ede Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 11 Mar 2011 21:18:24 +0100 Subject: Abort properly if source files are not under version control (FS#23122). Remove superfluous subshell code from version control checks in commitpkg, making it exit properly if source files are not under version control. Also, improve correctness of sed(1) commands and use fgrep(1) instead of grep(1) where appropriate. Signed-off-by: Lukas Fleischer --- commitpkg | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/commitpkg b/commitpkg index ab57a61..f50c607 100755 --- a/commitpkg +++ b/commitpkg @@ -72,23 +72,23 @@ else fi # check if all local source files are under version control -(for s in ${source[@]}; do - echo $s | grep -vq '://' && \ - svn status $s | grep -q '?' && \ +for s in ${source[@]}; do + echo $s | grep -Fvq '://' && \ + svn status $s | grep -q '^\?' && \ abort "$s is not under version control" -done) || true +done # check if changelog and install files are under version control -(for i in 'changelog' 'install'; do +for i in 'changelog' 'install'; do filelist=$(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD) for file in $filelist; do # evaluate any bash variables used eval file=${file} - if svn status ${file} | grep -q '?'; then + if svn status ${file} | grep -q '^\?'; then abort "${file} is not under version control" fi done -done) || true +done # see if any limit options were passed, we'll send them to rsync unset rsyncopts -- cgit v1.2.3-24-g4f1b 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(-) 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-24-g4f1b From dbdb237519635bc5ef349b434582ccbd9bbfe1e5 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sat, 12 Mar 2011 21:53:52 +0100 Subject: Add ".PHONY" target to Makefile. Signed-off-by: Lukas Fleischer --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index bedd23f..859cddf 100644 --- a/Makefile +++ b/Makefile @@ -88,3 +88,5 @@ uninstall: dist: git archive --format=tar --prefix=devtools-$(V)/ $(V) | gzip -9 > devtools-$(V).tar.gz + +.PHONY: all install uninstall dist -- cgit v1.2.3-24-g4f1b From 8b9733661d698290c732b5aea863d09fe4704e92 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sat, 12 Mar 2011 22:25:09 +0100 Subject: Use variables in Makefile instead of hardcoding stuff in every target. Signed-off-by: Lukas Fleischer --- Makefile | 139 +++++++++++++++++++++++++++------------------------------------ 1 file changed, 59 insertions(+), 80 deletions(-) diff --git a/Makefile b/Makefile index 859cddf..6cccdc6 100644 --- a/Makefile +++ b/Makefile @@ -1,90 +1,69 @@ V=0.9.17 +BINPROGS = \ + checkpkg \ + commitpkg \ + archco \ + communityco \ + archrelease \ + archrm \ + archbuild \ + lddd \ + finddeps \ + rebuildpkgs + +SBINPROGS = \ + mkarchroot \ + makechrootpkg + +CONFIGFILES = \ + makepkg-i686.conf \ + makepkg-x86_64.conf \ + pacman-extra.conf \ + pacman-testing.conf \ + pacman-staging.conf \ + pacman-multilib.conf \ + pacman-multilib-testing.conf + +COMMITPKG_LINKS = \ + extrapkg \ + corepkg \ + testingpkg \ + stagingpkg \ + communitypkg \ + community-testingpkg \ + community-stagingpkg \ + multilibpkg \ + multilib-testingpkg + +ARCHBUILD_LINKS = \ + extra-i686-build \ + extra-x86_64-build \ + testing-i686-build \ + testing-x86_64-build \ + staging-i686-build \ + staging-x86_64-build \ + multilib-build \ + multilib-testing-build + all: install: - # commitpkg/checkpkg and friends - install -d -m755 $(DESTDIR)/usr/bin - install -m 755 checkpkg $(DESTDIR)/usr/bin - install -m 755 commitpkg $(DESTDIR)/usr/bin - ln -sf commitpkg $(DESTDIR)/usr/bin/extrapkg - ln -sf commitpkg $(DESTDIR)/usr/bin/corepkg - ln -sf commitpkg $(DESTDIR)/usr/bin/testingpkg - ln -sf commitpkg $(DESTDIR)/usr/bin/stagingpkg - ln -sf commitpkg $(DESTDIR)/usr/bin/communitypkg - ln -sf commitpkg $(DESTDIR)/usr/bin/community-testingpkg - ln -sf commitpkg $(DESTDIR)/usr/bin/community-stagingpkg - ln -sf commitpkg $(DESTDIR)/usr/bin/multilibpkg - ln -sf commitpkg $(DESTDIR)/usr/bin/multilib-testingpkg - # arch{co,release,rm} - install -m 755 archco $(DESTDIR)/usr/bin - install -m 755 communityco $(DESTDIR)/usr/bin - install -m 755 archrelease $(DESTDIR)/usr/bin - install -m 755 archrm $(DESTDIR)/usr/bin - # new chroot tools, only usable by root - install -d -m 755 $(DESTDIR)/usr/sbin - install -m 755 mkarchroot $(DESTDIR)/usr/sbin - install -m 755 makechrootpkg $(DESTDIR)/usr/sbin - install -m 755 archbuild $(DESTDIR)/usr/bin - ln -sf archbuild $(DESTDIR)/usr/bin/extra-i686-build - ln -sf archbuild $(DESTDIR)/usr/bin/extra-x86_64-build - ln -sf archbuild $(DESTDIR)/usr/bin/testing-i686-build - ln -sf archbuild $(DESTDIR)/usr/bin/testing-x86_64-build - ln -sf archbuild $(DESTDIR)/usr/bin/staging-i686-build - ln -sf archbuild $(DESTDIR)/usr/bin/staging-x86_64-build - ln -sf archbuild $(DESTDIR)/usr/bin/multilib-build - ln -sf archbuild $(DESTDIR)/usr/bin/multilib-testing-build - # Additional packaging helper scripts - install -m 755 lddd $(DESTDIR)/usr/bin - install -m 755 finddeps $(DESTDIR)/usr/bin - install -m 755 rebuildpkgs $(DESTDIR)/usr/bin - # install default config - install -d -m755 $(DESTDIR)/usr/share/devtools - install -m 644 makepkg-i686.conf $(DESTDIR)/usr/share/devtools - install -m 644 makepkg-x86_64.conf $(DESTDIR)/usr/share/devtools - install -m 644 pacman-extra.conf $(DESTDIR)/usr/share/devtools - install -m 644 pacman-testing.conf $(DESTDIR)/usr/share/devtools - install -m 644 pacman-staging.conf $(DESTDIR)/usr/share/devtools - install -m 644 pacman-multilib.conf $(DESTDIR)/usr/share/devtools - install -m 644 pacman-multilib-testing.conf $(DESTDIR)/usr/share/devtools + install -dm0755 $(DESTDIR)/usr/bin + install -dm0755 $(DESTDIR)/usr/sbin + install -dm0755 $(DESTDIR)/usr/share/devtools + install -m0755 ${BINPROGS} $(DESTDIR)/usr/bin + install -m0755 ${SBINPROGS} $(DESTDIR)/usr/sbin + install -m0644 ${CONFIGFILES} $(DESTDIR)/usr/share/devtools + for l in ${COMMITPKG_LINKS}; do ln -sf commitpkg $(DESTDIR)/usr/bin/$$l; done + for l in ${ARCHBUILD_LINKS}; do ln -sf archbuild $(DESTDIR)/usr/bin/$$l; done uninstall: - # remove all files we installed - rm $(DESTDIR)/usr/bin/checkpkg - rm $(DESTDIR)/usr/bin/commitpkg - rm $(DESTDIR)/usr/bin/extrapkg - rm $(DESTDIR)/usr/bin/corepkg - rm $(DESTDIR)/usr/bin/testingpkg - rm $(DESTDIR)/usr/bin/stagingpkg - rm $(DESTDIR)/usr/bin/communitypkg - rm $(DESTDIR)/usr/bin/community-testingpkg - rm $(DESTDIR)/usr/bin/community-stagingpkg - rm $(DESTDIR)/usr/bin/multilibpkg - rm $(DESTDIR)/usr/bin/multilib-testingpkg - rm $(DESTDIR)/usr/sbin/mkarchroot - rm $(DESTDIR)/usr/sbin/makechrootpkg - rm $(DESTDIR)/usr/bin/extra-i686-build - rm $(DESTDIR)/usr/bin/extra-x86_64-build - rm $(DESTDIR)/usr/bin/testing-i686-build - rm $(DESTDIR)/usr/bin/testing-x86_64-build - rm $(DESTDIR)/usr/bin/staging-i686-build - rm $(DESTDIR)/usr/bin/staging-x86_64-build - rm $(DESTDIR)/usr/bin/multilib-build - rm $(DESTDIR)/usr/bin/multilib-testing-build - rm $(DESTDIR)/usr/bin/lddd - rm $(DESTDIR)/usr/bin/finddeps - rm $(DESTDIR)/usr/bin/archco - rm $(DESTDIR)/usr/bin/archrelease - rm $(DESTDIR)/usr/bin/archrm - rm $(DESTDIR)/usr/bin/communityco - rm $(DESTDIR)/usr/bin/rebuildpkgs - rm $(DESTDIR)/usr/share/devtools/makepkg-i686.conf - rm $(DESTDIR)/usr/share/devtools/makepkg-x86_64.conf - rm $(DESTDIR)/usr/share/devtools/pacman-extra.conf - rm $(DESTDIR)/usr/share/devtools/pacman-testing.conf - rm $(DESTDIR)/usr/share/devtools/pacman-staging.conf - rm $(DESTDIR)/usr/share/devtools/pacman-multilib.conf - rm $(DESTDIR)/usr/share/devtools/pacman-multilib-testing.conf + for f in ${BINPROGS}; do rm -f $(DESTDIR)/usr/bin/$$f; done + for f in ${SBINPROGS}; do rm -f $(DESTDIR)/usr/sbin/$$f; done + for f in ${CONFIGFILES}; do rm -f $(DESTDIR)/usr/share/devtools/$$f; done + for l in ${COMMITPKG_LINKS}; do rm -f $(DESTDIR)/usr/bin/$$l; done + for l in ${ARCHBUILD_LINKS}; do rm -f $(DESTDIR)/usr/bin/$$l; done dist: git archive --format=tar --prefix=devtools-$(V)/ $(V) | gzip -9 > devtools-$(V).tar.gz -- cgit v1.2.3-24-g4f1b From 96f22cfededae216e127e6fb1d616d003cd8d978 Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Sun, 13 Mar 2011 20:29:13 +0100 Subject: Use the multilib-devel group --- archbuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archbuild b/archbuild index 3435be5..8d75e77 100755 --- a/archbuild +++ b/archbuild @@ -6,7 +6,7 @@ cmd="$(basename "${0%-build}")" if [ "${cmd%-*}" == 'multilib' ]; then repo="${cmd}" arch='x86_64' - base_packages+=' gcc-multilib libtool-multilib' + base_packages+=' multilib-devel' else repo=${cmd%-*} arch=${cmd##*-} -- cgit v1.2.3-24-g4f1b 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(-) 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-24-g4f1b From 5434d3991cd51873f987bde49d55948341c09f3e Mon Sep 17 00:00:00 2001 From: Jan Steffens Date: Sun, 13 Mar 2011 18:09:52 +0100 Subject: Remove sudo from archbuild Archbuild should be called via sudo. --- archbuild | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/archbuild b/archbuild index 8d75e77..7e8c456 100755 --- a/archbuild +++ b/archbuild @@ -29,20 +29,25 @@ while getopts 'cr:' arg; do esac done +if [ "$EUID" != '0' ]; then + echo 'This script must be run as root.' + exit 1 +fi + if ${clean_first} || [ ! -d "${chroots}/${repo}-${arch}" ]; then echo "Creating chroot for [${repo}] (${arch})..." - sudo rm -rf ${chroots}/${repo}-${arch} - sudo mkdir -p ${chroots}/${repo}-${arch} - setarch ${arch} sudo mkarchroot \ + rm -rf ${chroots}/${repo}-${arch} + mkdir -p ${chroots}/${repo}-${arch} + setarch ${arch} mkarchroot \ -C /usr/share/devtools/pacman-${repo}.conf \ -M /usr/share/devtools/makepkg-${arch}.conf \ ${chroots}/${repo}-${arch}/root \ ${base_packages} else - setarch ${arch} sudo mkarchroot \ + setarch ${arch} mkarchroot \ -u \ ${chroots}/${repo}-${arch}/root fi echo "Building in chroot for [${repo}] (${arch})..." -setarch ${arch} sudo makechrootpkg -c -r ${chroots}/${repo}-${arch} +setarch ${arch} makechrootpkg -c -r ${chroots}/${repo}-${arch} -- cgit v1.2.3-24-g4f1b 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. --- archbuild | 13 +++++++++++++ makechrootpkg | 23 +++++++++++++++++++++++ mkarchroot | 16 ++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/archbuild b/archbuild index 7e8c456..9dd4888 100755 --- a/archbuild +++ b/archbuild @@ -36,6 +36,19 @@ fi if ${clean_first} || [ ! -d "${chroots}/${repo}-${arch}" ]; then echo "Creating chroot for [${repo}] (${arch})..." + + for copy in ${chroots}/${repo}-${arch}/*; do + [[ -d $copy ]] || continue + echo "Deleting chroot copy '$(basename "${copy}")'..." + + # Lock the copy + exec 9>${copy}.lock + flock 9 + + rm -rf ${copy} + done + exec 9>&- + rm -rf ${chroots}/${repo}-${arch} mkdir -p ${chroots}/${repo}-${arch} setarch ${arch} mkarchroot \ 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 diff --git a/mkarchroot b/mkarchroot index 254841e..5c6548e 100755 --- a/mkarchroot +++ b/mkarchroot @@ -141,6 +141,20 @@ chroot_umount () { umount "${working_dir}/${cache_dir}" [ -n "${host_mirror_path}" ] && umount "${working_dir}/${host_mirror_path}" } + +chroot_lock () { + # Only reopen the FD if it wasn't handed to us + if [ "$(readlink -f /dev/fd/9)" != "${working_dir}.lock" ]; then + exec 9>"${working_dir}.lock" + fi + + # Lock the chroot. Take note of the FD number. + if ! flock -n 9; then + echo -n "locking chroot..." + flock 9 + echo "done" + fi +} # }}} umask 0022 @@ -153,6 +167,7 @@ if [ "$RUN" != "" ]; then exit 1 fi + chroot_lock chroot_mount copy_hostconf @@ -169,6 +184,7 @@ else mkdir -p "${working_dir}/var/lib/pacman/sync" mkdir -p "${working_dir}/etc/" + chroot_lock chroot_mount pacargs="--noconfirm --root=${working_dir} --cachedir=${cache_dir}" -- cgit v1.2.3-24-g4f1b 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. --- archbuild | 1 + makechrootpkg | 14 ++++++++++++-- mkarchroot | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/archbuild b/archbuild index 9dd4888..19b734b 100755 --- a/archbuild +++ b/archbuild @@ -45,6 +45,7 @@ if ${clean_first} || [ ! -d "${chroots}/${repo}-${arch}" ]; then exec 9>${copy}.lock flock 9 + { type -P btrfs && btrfs subvolume delete ${copy}; } &>/dev/null rm -rf ${copy} done exec 9>&- 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 diff --git a/mkarchroot b/mkarchroot index 5c6548e..f385731 100755 --- a/mkarchroot +++ b/mkarchroot @@ -181,6 +181,10 @@ else exit 1 fi + if { type -P btrfs && btrfs subvolume create "${working_dir}"; } &>/dev/null; then + chmod 0755 "${working_dir}" + fi + mkdir -p "${working_dir}/var/lib/pacman/sync" mkdir -p "${working_dir}/etc/" -- cgit v1.2.3-24-g4f1b 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(-) 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-24-g4f1b