]> git.donarmstrong.com Git - neurodebian.git/blob - tools/nd_build
Also for stats report which repo and which job number use our setup
[neurodebian.git] / tools / nd_build
1 #!/bin/bash
2
3 if [ -z "$1" ]; then
4 cat << EOT
5 Script to build a source package in one of the available cowbuilders.
6
7 Synopsis
8 --------
9
10   nd_build <family> <codename> [arch] <dsc file> [cowbuilder options]
11
12
13 Examples
14 --------
15
16 Build for a single specific arch:
17
18   nd_build nd+debian lenny i386 someting.dsc
19
20
21 Build for all archs (will just build once for arch 'all'):
22
23   nd_build ubuntu jaunty something.dsc
24
25
26 Build the same way but don't put results in current dir:
27
28   nd_build debian sid something.dsc --buildresult to-upload/
29
30 EOT
31 exit 1
32 fi
33
34 family=$1
35 dist=$2
36
37 set -e
38
39 if [ -z "$family" ]; then
40   echo "You need to provide a distribution family ('debian', 'ubuntu'); prefix with 'nd+' to enable the NeuroDebian repository."
41   exit 1
42 fi
43
44 if [ -z "$dist" ]; then
45   echo "You need to provide a distribution codename (e.g. 'lenny', 'squeeze')."
46   exit 1
47 fi
48
49 . /etc/neurodebian/cmdsettings.sh
50
51 # common options
52 opts="--distribution $dist --aptcache $aptcache --buildplace $buildplace"
53
54 if [ -z "$3" ]; then
55   echo "You need to provide a .dsc file"
56   exit 1
57 fi
58
59 if [ ! "$3" = "${3%*.dsc}" ]; then
60   dscfile=$3
61   # must already be the dsc file, hence no arch info given
62   if [ "$(grep '^Architecture' $dscfile | awk '{ print $2 }')" = "all" ]; then
63     echo "Arch 'all' package detected -- using amd64 system to build it"
64     arch="amd64"
65   else
66     arch="i386 amd64"
67   fi
68   shift; shift; shift
69 else
70   # must be arch given and dsc as 4th
71   arch=$3
72   dscfile=$4
73   if [ -z "$dscfile" ]; then
74     echo "You need to provide a .dsc file"
75     exit 1
76   fi
77   shift; shift; shift; shift
78 fi
79
80 # failed will be set to 1 if any build fails
81 failed=
82 for a in $arch; do
83   # default
84   options="$opts"
85   if [ "$a" = "amd64" ]; then
86     # only force source into the upload for NeuroDebian
87     if [ ! "$family" = "${family#nd+*}" ]; then
88       options="$opts --debbuildopts -sa"
89     fi
90   else
91     options="$opts --debbuildopts -B"
92   fi
93
94   echo "Building for $family $dist $a ..."
95   buildfile="${dscfile%.dsc}_${a}.build"
96   tsfile="${buildfile}.timestamp.`date +%s`" # "unique" timestamp file
97   /usr/bin/time -f "%E real, %U user, %S sys, %O out" -o "${tsfile}" \
98   cowbuilder --build $dscfile \
99              --basepath ${cowbuilderroot}/cow/${family}-${dist}-${a}.cow \
100              --buildresult . \
101              --logfile "${buildfile}" \
102              $options \
103              "$@" && status='OK' || { status='FAILED'; failed=1; }
104   timeinfo=$(tail -n 1 "${tsfile}")
105   # Update the summary of builds
106   touch summary.build                               # Assure existence
107   sed -i -e "s/\(${buildfile}.*out$\)/\1 OLD/g" summary.build  # Mark previous entry as OLD
108   echo -e "${buildfile}\t$status\t$timeinfo" >> summary.build  # Add current one
109   rm -f "${tsfile}"
110 done
111 # Exit with failure status if any built failed
112 [ -z $failed ] || exit 1