summaryrefslogtreecommitdiff
path: root/sbuild-stuff
blob: 8ffbd93436901a78b11a6c68f821a146f1cad508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash

set -e
set -u

if [ "${1:-}" == "--binary-only" ]; then
	BINARY_ARCH="--binary-arch"
	BINARCH=1
	shift
else
	BINARCH=0
fi

if ! which grep-dctrl > /dev/null; then
	echo "grep-dctrl not found.  Maybe install dctrl-tools?"
	exit 1
fi
if ! which changestool > /dev/null; then
	echo "changestool not found.  Maybe install reprepro?"
	exit 1
fi

gpgcat() {
	local f="$1"
	if egrep -q "^-----BEGIN PGP SIGNED MESSAGE-----" "$f"; then
		gpg < "$f"
	else
		cat "$f"
	fi
}

get_metadata() {
	local dsc="$1"; shift

	dsc="$(readlink -f "$dsc")"
	local origtar="$(dcmd --orig $dsc)"
	if ! [ -e "$origtar" ]; then
		echo >&2 "File $origtar not found"
		exit 1
	fi
	local dirname="$(tar tzf $origtar | head -n1)"
	dirname="${dirname%%/}"

	local tmpdir="`mktemp -d`"
	pushd . >/dev/null
	cd "$tmpdir"

	dpkg-source -x "$dsc" > /dev/null
	cd "$dirname"

	local dist=$(dpkg-parsechangelog | grep-dctrl -n -s Distribution '')
	local ver=$(dpkg-parsechangelog | grep-dctrl -n -s Version '')

	popd >/dev/null
	rm -rf "$tmpdir"
	echo "$dist $ver"
}

DSC="${1:-}"; shift
if [ -z "$DSC" ] || [ -z "$BINARCH" ]; then
	echo "Usage: $0 [--binary-arch] <foo.dsc>" >&2
	exit 1;
fi

metadata="$(get_metadata "$DSC")"
read dscdist debian_version <<< "$metadata"
sourcepkg="$(gpgcat "$DSC" | grep-dctrl -n -s Source '')"

if [ -z "${ARCH:-}" ]; then
	if [ "`uname -m`" = "x86_64" ]; then
		ARCH="amd64"
	elif [ "`uname -m`" = "i386" ] || [ "`uname -m`" = "i686" ]; then
		ARCH="i386"
	else
		echo >&2 "Do not know arch"
		exit 1
	fi
fi

if [ -z "${DIST:-}" ]; then
	DIST=sid
	for d in lenny squeeze wheezy    dapper hardy karmic lucid maverick natty oneiric; do
		if echo $debian_version | grep -q "$d" ; then
			DIST="$d"
			break
		fi
	done
	if command -v "sbuild-override-dist-$sourcepkg" >/dev/null 2>&1; then
		NEWDIST=$("sbuild-override-dist-$sourcepkg" "$DIST" "$DSC" "$ARCH")
		[ -z "$NEWDIST" ] || DIST="$NEWDIST"
	fi
fi

if [ "$DIST" = "SKIP" ] ;then
	echo "skipping build for $DSC because DIST is $DIST."
	exit 0
fi

if [ "$BINARCH" = 1 ]; then
	extra="${EXTRA_ARGS:-}"
else
	extra="${EXTRA_ARGS:-} -s --arch-all"
fi

sbuild --arch="$ARCH" --dist="$DIST" --apt-update $extra "$DSC"

changesfile="${DSC%.dsc}_$ARCH.changes"
if ! [ -e "$changesfile" ]; then
	echo >&2 "Expected file $changesfile does not exist"
	exit 1
fi
changestool "$changesfile" setdistribution "$dscdist"