[Reproducible-builds] [misc] 02/02: Add a script to rebuild twice at the same path

Stéphane Glondu glondu at moszumanska.debian.org
Sat Feb 22 13:03:07 UTC 2014


This is an automated email from the git hooks/post-receive script.

glondu pushed a commit to branch master
in repository misc.

commit a14e6df482e05e3497f2f9fcf2ce672d16ad70b8
Author: Stephane Glondu <steph at glondu.net>
Date:   Wed Feb 19 11:49:05 2014 +0100

    Add a script to rebuild twice at the same path
---
 rebuild-twice-in-same-path/Makefile.pbuilder |  3 ++
 rebuild-twice-in-same-path/README            | 32 +++++++++++
 rebuild-twice-in-same-path/pbuilder-execute  | 79 ++++++++++++++++++++++++++++
 rebuild-twice-in-same-path/run               | 26 +++++++++
 4 files changed, 140 insertions(+)

diff --git a/rebuild-twice-in-same-path/Makefile.pbuilder b/rebuild-twice-in-same-path/Makefile.pbuilder
new file mode 100644
index 0000000..9b6c9f0
--- /dev/null
+++ b/rebuild-twice-in-same-path/Makefile.pbuilder
@@ -0,0 +1,3 @@
+# -*- makefile -*-
+%:
+	cowbuilder --execute --basepath $(BASEPATH) --bindmounts $(BUILD_RESULT) -- $(CURDIR)/pbuilder-execute $(BUILD_RESULT) $@
diff --git a/rebuild-twice-in-same-path/README b/rebuild-twice-in-same-path/README
new file mode 100644
index 0000000..381ccd2
--- /dev/null
+++ b/rebuild-twice-in-same-path/README
@@ -0,0 +1,32 @@
+This directory contains a set of scripts to rebuild packages twice at
+the same location using bind mounts. They are based on cowbuilder.
+
+Disclaimer: some commands are run as root. Depending on your trust
+model, you might want to first start with a fresh virtual
+environment. But you should really read and understand all the scripts
+in this directory first.
+
+A cowbuilder chroot can be created with:
+
+    sudo cowbuilder --create --distribution sid --mirror http://http.debian.net/debian --basepath /var/cache/pbuilder/reproducible.cow
+
+You can log into this chroot to make permanent changes with:
+
+    sudo cowbuilder --login --basepath /var/cache/pbuilder/reproducible.cow --save-after-login
+
+To play with a disposable chroot, just drop the --save-after-login option.
+
+We suppose you made the following permanent changes:
+- useradd pbuilder
+- apt-get install fakeroot time devscripts
+- enable deb-src in /etc/apt/sources.list
+- patched toolchain (e.g. as in https://wiki.debian.org/ReproducibleBuilds/Rebuild20140126)
+
+The entry point of the system is the `run` script. Usage:
+
+    sudo ./run /var/cache/pbuilder/reproducible.cow <result-path> <make-arguments> <packages>
+
+It will run the `pbuilder-execute` script through pbuilder, which is
+itself run through make. With make, you can rebuild several packages
+in parallel using the -j option (beware, the interactive output might
+not make any sense then).
diff --git a/rebuild-twice-in-same-path/pbuilder-execute b/rebuild-twice-in-same-path/pbuilder-execute
new file mode 100755
index 0000000..07fad26
--- /dev/null
+++ b/rebuild-twice-in-same-path/pbuilder-execute
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# Copyright © 2014 Stéphane Glondu <glondu at debian.org>
+# Licensed under GPL-3+ — https://www.gnu.org/licenses/gpl.txt
+
+# $UID is a bashism
+if [ "$0" != "/runscript" ] || [ "$UID" -ne 0 ]; then
+    echo "This script must be run by pbuilder or one of its variant"
+    exit 1
+fi
+
+result=$1
+pkg=$2
+
+if [ -z "$result" ] || [ -z "$pkg" ]; then
+    echo "One argument is missing"
+    exit 1
+fi
+
+# The following must be clean, so fail if they already exist
+mkdir /tmp/src || exit 3
+chown pbuilder /tmp/src
+mkdir /usr/src/debian || exit 3
+mkdir $result/$pkg || exit 3
+
+echo "Installing build-dependencies of $pkg..."
+
+apt-get build-dep -y $pkg > $result/$pkg/build-dep 2>&1
+aptitude search --disable-columns -F '%p %V' '~i' > $result/$pkg/installed-packages
+
+su -c "mkdir -p /tmp/src/a && cd /tmp/src/a && apt-get source $pkg && cd .. && cp -a a b" pbuilder
+
+# Find the base name of build dir
+for u in /tmp/src/a/*; do
+    if [ -d "$u" ]; then build_dir="${u##*/}"; fi
+done
+if [ -z "$build_dir" ]; then
+    echo "Could not find find dir for package $pkg"
+    exit 2
+fi
+
+echo "First build of $pkg..."
+
+mkdir $result/$pkg/a
+mount --bind /tmp/src/a /usr/src/debian
+/usr/bin/time -o $result/$pkg/a/stats su -c "cd /usr/src/debian/$build_dir && DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -us -uc" pbuilder > $result/$pkg/a/log 2>&1
+du -sh /usr/src/debian >> $result/$pkg/a/stats
+umount /usr/src/debian
+
+changes=/tmp/src/a/*.changes
+if [ ! -f $changes ]; then
+    echo "First build failed"
+    exit 4
+fi
+
+timestamp=$(date +%s -d "$(sed -n -e 's/^Date: //p' $changes)")
+dcmd cp $changes $result/$pkg/a
+rm -rf /tmp/src/a
+
+echo "Second build of $pkg..."
+
+mkdir $result/$pkg/b
+mount --bind /tmp/src/b /usr/src/debian
+/usr/bin/time -o $result/$pkg/b/stats su -c "cd /usr/src/debian/$build_dir && DEB_BUILD_OPTIONS=nocheck DEB_BUILD_TIMESTAMP=$timestamp dpkg-buildpackage -us -uc" pbuilder > $result/$pkg/b/log 2>&1
+du -sh /usr/src/debian >> $result/$pkg/b/stats
+umount /usr/src/debian
+
+changes=/tmp/src/b/*.changes
+if [ ! -f $changes ]; then
+    echo "Second build failed"
+    exit 4
+fi
+
+if diff -u $result/$pkg/a/*.changes $changes; then
+    touch $result/$pkg/b/reproducible
+else
+    dcmd cp $changes $result/$pkg/b
+fi
+rm -rf /tmp/src/b
diff --git a/rebuild-twice-in-same-path/run b/rebuild-twice-in-same-path/run
new file mode 100755
index 0000000..7884e95
--- /dev/null
+++ b/rebuild-twice-in-same-path/run
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# Copyright © 2014 Stéphane Glondu <glondu at debian.org>
+# Licensed under GPL-3+ — https://www.gnu.org/licenses/gpl.txt
+
+# $UID is a bashism
+if [ "$UID" -ne 0 ]; then
+    echo "This script must be run as root (at your own risk!)"
+    exit 1
+fi
+
+basepath=$1; shift
+result=$1; shift
+
+# Make sure $basepath is a path to a chroot
+if [ ! -d $basepath/etc ]; then
+    echo "$basepath/etc does not exist"
+    exit 2
+fi
+
+if [ ! -d $result ]; then
+    echo "$result does not exist"
+    exit 2
+fi
+
+make -f Makefile.pbuilder BASEPATH=$basepath BUILD_RESULT=$result "$@"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/misc.git



More information about the Reproducible-builds mailing list