Try both git repos in turn befor failing
[strace-test.git] / strace-build-test
1 #!/bin/bash
2
3 POINT=HEAD
4 ARCH=$(dpkg-architecture -q DEB_BUILD_ARCH)
5 HOSTNAME=$(hostname)
6 PKG_TEST="https://www.einval.com/debian/strace/package-test"
7
8 while getopts ":p:a:" opt; do
9   case $opt in
10     p)
11       POINT=$OPTARG
12       ;;
13     a)
14       ARCH=$OPTARG
15       set +e
16       chk=`dpkg-architecture -a$ARCH > /dev/null 2>&1 ; echo $?`
17       set -e
18       if [ $chk != 0 ]; then
19           echo "Did not recognise ${ARCH} as a Debian architecture name. Exit."
20           exit 1
21       fi
22       ARCH=${ARCH}
23       ;;
24     \?)
25       echo "Invalid option: -$OPTARG" >&2
26       ;;
27   esac
28 done
29
30 PATH=/usr/local/sbin:/usr/local/bin:$PATH
31 export PATH
32
33 NUMCPUS=$(grep processor /proc/cpuinfo | wc -l)
34 if [ $NUMCPUS -gt 1 ]; then
35     PARALLEL="-j $NUMCPUS"
36 else
37     PARALLEL=""
38 fi
39
40 set -e
41 set -x
42
43 mysid=sid-93sam-strace-$RANDOM
44
45 cleanup () {
46     schroot -e -c $mysid
47 }
48
49 trap cleanup 0
50
51 BASE_CHROOT="sid_$ARCH-dchroot"
52
53 schroot -e -c $mysid || true
54 schroot -b -c $BASE_CHROOT -n $mysid
55 dd-schroot-cmd -y -c $mysid apt-get update
56 dd-schroot-cmd -y -c $mysid apt-get build-dep strace
57 dd-schroot-cmd -y -c $mysid apt-get install git autotools-dev gawk dh-autoreconf wget
58 dd-schroot-cmd -y -c $mysid apt-get install gcc-multilib || true
59
60 DATETIME=$(date -u '+%Y-%m-%d-%H%M%S')
61 BDIR=~/build/strace/build-test-${DATETIME}
62
63 mkdir -p ${BDIR}
64 cd ${BDIR} 
65
66 cat > ~/build/strace/inside-schroot-test.sh << EOF
67 #!/bin/sh
68 set -e
69 cd ${BDIR}
70 git clone -q http://git.code.sf.net/p/strace/code strace.git || rm -rf strace.git && git clone -q https://github.com/strace/strace strace.git
71 echo "BUILD ENVIRONMENT INFORMATION"
72 echo "============================="
73 echo "Debian architecture"
74 echo "-------------------"
75 dpkg-architecture -q DEB_BUILD_ARCH
76 echo "Hostname"
77 echo "--------"
78 hostname
79 echo "uname -rm"
80 echo "---------"
81 uname -rm
82 echo "Version of kernel headers (linux-libc-dev)"
83 echo "------------------------------------------"
84 dpkg -s linux-libc-dev
85 echo "Version of libc"
86 echo "---------------"
87 dpkg -s libc6-dev
88 echo "Version of gcc"
89 echo "--------------"
90 dpkg -s gcc
91 cd strace.git
92 git checkout $POINT
93 git log | head -1
94 ./bootstrap
95 ./configure
96 make $PARALLEL && make check VERBOSE=1 && echo SUCCESS > ${BDIR}/RESULT
97 EOF
98
99 chmod +x ~/build/strace/inside-schroot-test.sh
100
101 cd ~
102
103 # Run the command, outout to typescript
104 script -c "schroot -r -c $mysid ~/build/strace/inside-schroot-test.sh"
105
106 if [ ! -f ${BDIR}/RESULT ] ; then
107     echo "BUILD FAILED - not doing cleanup"
108     echo "Results in ${BDIR}"
109 fi
110
111 rm -rf ${BDIR}
112 rm -f ~/build/strace/inside-schroot-test.sh
113 mv typescript typescript-$ARCH-$HOSTNAME-${DATETIME}.txt
114 gzip -9 typescript-$ARCH-$HOSTNAME-${DATETIME}.txt
115 FILE="typescript-$ARCH-$HOSTNAME-${DATETIME}.txt.gz"
116 (echo "START $FILE" ; \
117  base64 < $FILE ; \
118  echo "END $FILE") | \
119     mailx -s "strace-build-test $ARCH-$HOSTNAME-${DATETIME} log" \
120           steve-strace@einval.com
121 rm -f $FILE
122
123 # Check to see if we have a package build to test too, run it in a
124 # separate log file but using the same chroot for speed
125 rm -rf ~/build/strace/package-test
126 set +e
127 WGET="wget --ca-certificate=/home/93sam/.CA/ca-certificates.crt"
128 $WGET -O /dev/null $PKG_TEST/MANIFEST
129 if [ $? -eq 0 ]; then
130     # Time to grab sources
131     mkdir ~/build/strace/package-test
132     cd ~/build/strace/package-test
133     $WGET $PKG_TEST/MANIFEST
134     for file in $(cat MANIFEST); do
135         $WGET $PKG_TEST/$file
136     done
137     DSC=$(ls *.dsc)
138
139     cat > ~/build/strace/inside-schroot-test.sh << EOF
140 #!/bin/sh
141 cd ~/build/strace/package-test
142 dpkg-source -x *.dsc
143 cd strace-*
144 debuild -i -us -uc -b
145 EOF
146     chmod +x ~/build/strace/inside-schroot-test.sh
147     set -e
148     cd ~
149     # Run the command, outout to typescript
150     script -c "schroot -r -c $mysid ~/build/strace/inside-schroot-test.sh"
151
152     rm -rf ~/build/strace/package-test
153     rm -f ~/build/strace/inside-schroot-test.sh
154     gzip -9 typescript
155     FILE=typescript.gz
156     (echo "START $FILE" ; \
157      base64 < $FILE ; \
158      echo "END $FILE") | \
159         mailx -s "$DSC package build log: $ARCH on $HOSTNAME " \
160               steve@einval.com
161     rm -f $FILE
162 fi