Debian Codegraph @

debian/tests/build-procenv

raw symbols SCIP
1 #!/bin/sh
2 set -eu
3
4 #---------------------------------------------------------------------
5 # Creates a pbuilder chroot, builds a package, installs the resulting
6 # .deb, then runs the command provided by the .deb.
7 #---------------------------------------------------------------------
8
9 die()
10 {
11 msg="$*"
12 echo "ERROR: $msg" >&2
13 exit 1
14 }
15
16 # The package we'll ask pbuilder to build (we know its buildable since
17 # it's already in the archive :-))
18 #
19 # The advantage of choosing this particular package being that it runs
20 # *itself* at the end of its build.
21 pkg=procenv
22
23 resultdir=/var/cache/pbuilder/result
24
25 # Avoid conflict with ADT
26 unset TMPDIR
27 cd "$AUTOPKGTEST_TMP"
28
29 distro=$(lsb_release --id --short|tr '[:upper:]' '[:lower:]' || :)
30 [ -z "$distro" ] && die "cannot establish distribution"
31 arch=$(dpkg --print-architecture 2>/dev/null)
32 [ -z "$arch" ] && die "cannot establish architecture"
33 host_release=$(lsb_release --codename --short || :)
34 [ -z "$host_release" ] && die "cannot establish release running on host"
35
36 if [ "$distro" = debian ] ; then
37 release=$(distro-info --testing)
38 components="main"
39 mirror="http://cloudfront.debian.net/debian"
40 elif [ "$distro" = ubuntu ] ; then
41 case "$arch" in
42 amd64|i386) mirror="http://archive.ubuntu.com/ubuntu" ;;
43 *) mirror="http://ports.ubuntu.com" ;;
44 esac
45 release=$(distro-info --devel)
46 components="main universe"
47 else
48 die "need to know where archive is for distro '$distro' on arch '$arch'"
49 fi
50
51 # Have to redirect stderr to avoid ADT thinking the test has failed
52 # (the return code is still being checked, so this seems reasonable).
53 echo "INFO: Creating pbuilder chroot for release '$release'"
54 echo "+ pbuilder create --debug --distribution '$release' --components '$components' --debootstrapopts --mirror '$mirror'"
55 pbuilder create --debug \
56 --distribution "$release" \
57 --components "$components" \
58 --mirror "$mirror" 2>&1
59
60 if [ ! -d "$resultdir" ] ; then
61 die "cannot find directory $resultdir"
62 fi
63
64 # Use '--download-only' to avoid unpack which generates a
65 # signature warning to stderr, causing this test to fail.
66 echo "INFO: Adding deb-src line in /etc/apt/sources.list for the '$release' release"
67 echo "deb-src $mirror $release $components" > /etc/apt/sources.list
68 apt-get -o APT::Sandbox::User=root -q update
69 echo "INFO: Downloading source for package '$pkg' release '$release'"
70 apt-get -o APT::Sandbox::User=root -q source --download-only "$pkg/$release"
71
72 dsc=$(ls ${pkg}*.dsc)
73
74 echo "INFO: Building package '$pkg' for release '$release' from '$dsc'"
75 pbuilder build --debug "$dsc" 2>&1
76
77 pkg_and_version=$(echo "$dsc"|sed 's/\.dsc$//g')
78 deb=${resultdir}/${pkg_and_version}_${arch}.deb
79
80 # Do what we can to check if the .deb looks usable (since we may not
81 # be able to install it to test it properly)
82 echo "INFO: Listing information on '$deb'"
83 dpkg --info "$deb"
84
85 echo "INFO: Listing contents of '$deb'"
86 dpkg --contents "$deb"
87
88 extract="$AUTOPKGTEST_TMP/extract"
89 echo "INFO: Extracting '$deb' to '$extract'"
90 dpkg --extract "$deb" "$extract"
91
92 echo "INFO: Trying to install package '$pkg' from '$deb'"
93 echo "INFO: (this might not succeed, that's not a bug)"
94 if dpkg -i "$deb" 2>&1 ; then
95 # run the command to prove the build worked but also to expose the
96 # auto-package-test environment used for this test.
97 cmd=$pkg
98 echo "INFO: Showing AutoPkgTest environment by running '$cmd' from package '$pkg'"
99 "$cmd"
100 else
101 echo "INFO: The install step failed. This can be expected if the host release is different than our target."
102 echo "host release: $host_release"
103 echo "target release: $release"
104 fi
105
106 echo "INFO: SUCCESS"