aboutsummaryrefslogtreecommitdiff
path: root/pbuilder-buildpackage
blob: a412c70477ab6df5f1f9371ff8d32dba59085f44 (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
#! /bin/bash
export LANG=C
export LC_ALL=C

function copydsc () {
    local DSCFILE="$1"
    local TARGET="$2"
    for FILE in \
      "$DSCFILE" \
      $(echo "$DSCFILE" | sed 's/^\(.*\)\.dsc$/\1/' ).diff.gz \
      $(echo "$DSCFILE" | sed 's/^\(.*\)\.dsc$/\1/').tar.gz \
      $(echo "$DSCFILE" | sed 's/\(.*\)-[^-.]*\.dsc$/\1/').orig.tar.gz ; do
        cp "$FILE" "$TARGET" ;
    done

}

function checkbuilddep () {
    for INSTALLPKG in $($CHROOTEXEC bin/sh -c "(cd tmp/buildd/*/; dpkg-checkbuilddeps)" 2>&1 |grep "^dpkg-checkbuilddeps: Unmet build dependencies: " | sed 's/^[^:]*:[^:]*: \(.*\)$/\1/' | awk 'BEGIN{RS=", "} /^([^([]*)/{print $1}'); do
	echo " -> Installing $INSTALLPKG"
	$CHROOTEXEC usr/bin/apt-get -y install "$INSTALLPKG"
    done;
    for REMOVEPKG in $($CHROOTEXEC bin/sh -c "(cd tmp/buildd/*/; dpkg-checkbuilddeps)" 2>&1 |grep "^dpkg-checkbuilddeps: Build conflicts: " | sed 's/^[^:]*:[^:]*: \(.*\)$/\1/' | awk 'BEGIN{RS=", "} /^([^([]*)/{print $1}'); do
	echo " -> Removing $REMOVEPKG"
	$CHROOTEXEC usr/bin/apt-get -y remove "$REMOVEPKG"
    done;
}

. /usr/lib/pbuilder/pbuilder-checkparams
. /usr/lib/pbuilder/pbuilder-modules
PACKAGENAME="$1"
CHROOTEXEC="chroot $BUILDPLACE "



if [ ! -f "$PACKAGENAME" ]; then
  echo "Command line parameter [$PACKAGENAME] is not a valid .dsc file name" >&2
  exit 1;
fi;

cleanbuildplace
echo "building the build env"
mkdir -p "$BUILDPLACE"
(
 cd "$BUILDPLACE"
 tar xfzp "$BASETGZ"
 mkdir -p "$BUILDPLACE/tmp/buildd"
 )
mountproc

echo Copying source file
copydsc "$PACKAGENAME" "$BUILDPLACE/tmp/buildd"
echo Extracting source
$CHROOTEXEC /bin/bash -c "( cd tmp/buildd; /usr/bin/dpkg-source -x $(basename $PACKAGENAME) )"
echo Installing the build-deps
checkbuilddep
echo Building the package
$CHROOTEXEC /bin/sh -c "(cd tmp/buildd/*/; dpkg-buildpackage)"
umountproc

test -n "$BUILDRESULT" && (
  mkdir -p "$BUILDRESULT"
  if [ -d "$BUILDRESULT" ]; then
    cp "$BUILDPLACE"/tmp/buildd/* "$BUILDRESULT"
  else
    echo "Error: BUILDRESULT=[$BUILDRESULT] and is not a directory." >&2
  fi
)
cleanbuildplace