reproducible_debstrap.sh 3.83 KB
Newer Older
1
2
3
4
5
6
#!/bin/bash
# vim: set noexpandtab:

# Copyright 2021-2022 Holger Levsen <holger@layer-acht.org>
# released under the GPLv2

7
DEBUG=false
8
9
10
11
12
13
14
15
16
17
18
. /srv/jenkins/bin/common-functions.sh
common_init "$@"

# common code for tests.reproducible-builds.org
. /srv/jenkins/bin/reproducible_common.sh
set -e
set -o pipefail # see eg http://petereisentraut.blogspot.com/2010/11/pipefail.html

cleanup() {
	local RESULT=$1
	output_echo "Cleanup ${RESULT}"
19
20
21
	# Cleanup the workspace and results directory
	for CLEANUP in ${BUILDDIR} ${RESULTSDIR} ; do
		if [ ! -z "$CLEANUP" ]; then
22
			output_echo "Removing ${CLEANUP}"
23
			sudo rm -rf --one-file-system ${CLEANUP}
24
25
		fi
	done
26
27
28
29
}


# Init some variables
30
31
export TOOL="$1"
export SUITE="$2"
32
output_echo "About to bootstrap $SUITE using $TOOL version $(dpkg-query  --showformat='${Version}' --show $TOOL)."
33
export SOURCE_DATE_EPOCH="$(date +%s)"
34
output_echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH"
35
36
export BUILDDIR=$(mktemp --tmpdir=/srv/workspace/ -d -t ${TOOL}-${SUITE}.XXXXXXXX)
export RESULTSDIR=$(mktemp --tmpdir=/srv/reproducible-results -d -t ${TOOL}-${SUITE}.XXXXXXXX) # accessible in schroots, used to compare results
37
38
39
40
41
42
43

# Cleanup if something goes wrong
trap cleanup INT TERM EXIT

# Randomize start time
delay_start

44
# Actual run ${TOOL} twice
45
46
47
48
49
for LOOP in "first" "second" ; do
	case $LOOP in
		first)	SUBDIR=b1
			ACTION="Verbosely running"
			REALTOOL=$TOOL
50
			;;
51
52
53
54
55
56
		second)	SUBDIR=b2
			ACTION="Running"
			case $TOOL in
				mmdebstrap)	REALTOOL="mmdebstrap -v" ;;
				debootstrap)	REALTOOL="debootstrap --verbose" ;;
			esac
57
			;;
58
59
	esac
	output_echo "$ACTION ${TOOL} $SUITE for the $LOOP run."
60
	mkdir -p $BUILDDIR/$SUBDIR/${TOOL}
61
62
63
64
	case ${TOOL} in
		mmdebstrap)	sudo $REALTOOL $SUITE > $BUILDDIR/$SUBDIR/${TOOL}/${SUITE}.tar
				;;
		debootstrap)	sudo $REALTOOL $SUITE $BUILDDIR/$SUBDIR/${TOOL}/${SUITE}
65
				for LOGFILE in /var/log/bootstrap.log /var/log/dpkg.log /var/log/alternatives.log ; do
66
					output_echo "Warning: modifying $TOOL result, deleting unreproducible logfile $LOGFILE"
67
					sudo rm -rf --one-file-system $BUILDDIR/$SUBDIR/${TOOL}/${SUITE}/$LOGFILE
68
				done
69
70
				for FILE in /etc/machine-id /var/cache/ldconfig/aux-cache ; do
					output_echo "Warning: modifying $TOOL result, deleting unreproducible file $FILE because it will be created as needed"
71
					sudo rm -rf --one-file-system $BUILDDIR/$SUBDIR/${TOOL}/${SUITE}/$FILE
72
				done
73
				sudo tar --mtime="@$SOURCE_DATE_EPOCH" --clamp-mtime -C $BUILDDIR/$SUBDIR/${TOOL}/ -cf $BUILDDIR/$SUBDIR/${TOOL}/${SUITE}.tar ${SUITE}
74
75
				sudo rm -rf --one-file-system $BUILDDIR/$SUBDIR/${TOOL}/${SUITE}
				;;
76
		*)		output_echo "Failure: ${TOOL} is unsupported."
77
78
79
				exit 1
				;;
	esac
80
	mv $BUILDDIR/$SUBDIR $RESULTSDIR/ 1>/dev/null
81
done
82

83
output_echo "Done running ${TOOL} twice."
84

85
# show sha256sum results
86
sha256sum $RESULTSDIR/b1/${TOOL}/${SUITE}.tar $RESULTSDIR/b2/${TOOL}/${SUITE}.tar
87

88
# show human readable results
89
90
if diff $RESULTSDIR/b1/${TOOL}/${SUITE}.tar $RESULTSDIR/b2/${TOOL}/${SUITE}.tar ; then
	output_echo "Success: ${TOOL} of $SUITE is reproducible today."
91
else
92
	output_echo "Warning: ${TOOL} of $SUITE is not reproducible."
93
94
95
96
97
	# Run diffoscope on the images
	output_echo "Calling diffoscope on the results."
	TIMEOUT="240m"
	DIFFOSCOPE="$(schroot --directory /tmp -c chroot:jenkins-reproducible-${DBDSUITE}-diffoscope diffoscope -- --version 2>&1)"
	TMPDIR=${RESULTSDIR}
98
99
	#call_diffoscope ${TOOL} ${SUITE}.tar
	# the previous, temporarily disabled line is only useful if we also make the .html file visible...
100
	schroot --directory /tmp -c chroot:jenkins-reproducible-${DBDSUITE}-diffoscope diffoscope -- --restructured-text $RESULTSDIR/${TOOL}_${SUITE}.txt $RESULTSDIR/b1/${TOOL}/${SUITE}.tar $RESULTSDIR/b2/${TOOL}/${SUITE}.tar || true # diffoscope will exi with error...
101
	cat $RESULTSDIR/${TOOL}_${SUITE}.txt
102
fi
103
104
105
106
107
108
109

cleanup success
# Turn off the trap
trap - INT TERM EXIT

# We reached the end, return with PASS
exit 0