1 | #!/bin/bash |
---|
2 | |
---|
3 | quote() { |
---|
4 | echo "$1" | sed 's/[^[:alnum:]]/\\&/g' |
---|
5 | } |
---|
6 | |
---|
7 | fail() { |
---|
8 | echo "$@" >&2 |
---|
9 | exit 1 |
---|
10 | } |
---|
11 | |
---|
12 | dist_arch=$1; shift |
---|
13 | a= |
---|
14 | if [ "$1" = "-A" ]; then a=-A; shift; fi |
---|
15 | chroot=$dist_arch-sbuild |
---|
16 | dist=$(echo "$dist_arch" | sed 's/^\(.*\)-\([^-]*\)$/\1/') |
---|
17 | arch=$(echo "$dist_arch" | sed 's/^\(.*\)-\([^-]*\)$/\2/') |
---|
18 | . /mit/debathena/bin/debian-versions.sh |
---|
19 | if [ -e nobuild ] && fgrep -q "$dist" nobuild; then |
---|
20 | echo "Skipping $dist_$arch since $dist is listed in ./nobuild." |
---|
21 | exit |
---|
22 | fi |
---|
23 | tag=$(gettag $dist) |
---|
24 | : ${DEBATHENA_APT=/mit/debathena/apt} |
---|
25 | : ${DEBATHENA_RELEASE=production} |
---|
26 | export DEBATHENA_APT |
---|
27 | export DEBATHENA_RELEASE |
---|
28 | pkgfiles="$DEBATHENA_APT/dists/$dist/openafs/binary-$arch/Packages.gz $DEBATHENA_APT/dists/${dist}-proposed/openafs/binary-$arch/Packages.gz" |
---|
29 | |
---|
30 | if [ "$DEBATHENA_RELEASE" = "production" ]; then |
---|
31 | apt_release="" |
---|
32 | else |
---|
33 | apt_release="$DEBATHENA_RELEASE" |
---|
34 | fi |
---|
35 | |
---|
36 | do_binary=no |
---|
37 | do_upload=no |
---|
38 | for arg; do |
---|
39 | case $arg in |
---|
40 | source) |
---|
41 | ;; |
---|
42 | binary) |
---|
43 | do_binary=yes |
---|
44 | ;; |
---|
45 | upload) |
---|
46 | do_upload=yes |
---|
47 | ;; |
---|
48 | *) |
---|
49 | fail "Usage: $0 DIST_ARCH [-A] source|binary|upload ..." |
---|
50 | ;; |
---|
51 | esac |
---|
52 | done |
---|
53 | |
---|
54 | sid=$(schroot -b -c "$chroot") || exit 1 |
---|
55 | trap 'schroot -e -c "$sid"' EXIT |
---|
56 | sch() { schroot -r -c "$sid" -- "$@"; } # Run in the chroot |
---|
57 | schq() { schroot -q -r -c "$sid" -- "$@"; } # Run in the chroot quietly |
---|
58 | schr() { schroot -r -c "$sid" -u root -- "$@"; } # Run in the chroot as root |
---|
59 | schr apt-get -qq -y update || exit 3 |
---|
60 | |
---|
61 | afsv=$(schq apt-cache show --no-all-versions openafs-modules-source | \ |
---|
62 | sed -n 's/^Version: // p') |
---|
63 | |
---|
64 | # Get all of the packages named linux-image-*. This list includes |
---|
65 | # three types of packages: |
---|
66 | # - Actual kernel images (e.g. linux-image-2.6.24-19-generic) |
---|
67 | # - Metapackages (e.g. linux-image-generic) which are used to keep |
---|
68 | # kernel images up to date |
---|
69 | # - Meta-metapackages which depend on other metapackages; these |
---|
70 | # exist for transitional reasons or to provide more generic names |
---|
71 | # (e.g. linux-image-amd64 depends on linux-image-2.6-amd64 in |
---|
72 | # lenny) |
---|
73 | # |
---|
74 | # We can distinguish actual kernel images from metapackages by looking |
---|
75 | # at the source package; actual images will have the source "linux" |
---|
76 | # (Ubuntu) or "linux-2.6" (Debian) while both kinds of metapackages |
---|
77 | # will have the source "linux-meta" (Ubuntu) or "linux-latest-2.6" |
---|
78 | # (Debian). |
---|
79 | # |
---|
80 | # To distinguish metapackages from meta-metapackages, we need to look |
---|
81 | # at whether the package's linux-image-* dependency is an actual |
---|
82 | # kernel image or a metapackage. |
---|
83 | pkgs=$(sch apt-cache search --names-only '^linux-image-' | awk '{print $1}') |
---|
84 | |
---|
85 | # Identify the metapackages which depend directly on actual kernel |
---|
86 | # images, as well as the header packages corresponding to those |
---|
87 | # dependencies. |
---|
88 | metareg='linux-meta\|linux-latest.*' |
---|
89 | mpkgs= |
---|
90 | headers= |
---|
91 | for pkg in $pkgs; do |
---|
92 | info=$(schq apt-cache show --no-all-versions "$pkg") |
---|
93 | |
---|
94 | # Disregard if this is not a metapackage. |
---|
95 | src=$(echo "$info" | sed -ne 's/^Source: //p') |
---|
96 | if [ $(expr "$src" : "$metareg") = 0 ]; then |
---|
97 | continue |
---|
98 | fi |
---|
99 | |
---|
100 | # Disregard if this package's linux-image dependency is a metapackage. |
---|
101 | dep=$(echo "$info" | sed -ne 's/^Depends:.*\(linux-image-[^ ,]*\).*$/\1/p') |
---|
102 | depsrc=$(schq apt-cache show --no-all-versions "$dep" \ |
---|
103 | | sed -ne 's/^Source: //p') |
---|
104 | if [ $(expr "$depsrc" : "$metareg") != 0 ]; then |
---|
105 | continue |
---|
106 | fi |
---|
107 | |
---|
108 | # Find the corresponding linux-headers package. If there isn't one, |
---|
109 | # this is probably an Ubuntu linux-image-debug metapackage and we |
---|
110 | # can ignore it. |
---|
111 | hdr=$(echo "$dep" | sed -e 's/image/headers/') |
---|
112 | hdrinfo=$(schq apt-cache show "$hdr" 2>/dev/null) |
---|
113 | if [ -z "$hdrinfo" ]; then |
---|
114 | continue |
---|
115 | fi |
---|
116 | |
---|
117 | mpkgs="$mpkgs $pkg" |
---|
118 | headers="$headers $hdr" |
---|
119 | done |
---|
120 | |
---|
121 | # For each header package found, attempt to build and/or upload |
---|
122 | # (according to the command-line arguments) a corresponding |
---|
123 | # openafs-modules package if one does not already exist. |
---|
124 | for hdr in $headers; do |
---|
125 | hdrv=$(schq apt-cache show --no-all-versions "$hdr" | \ |
---|
126 | sed -n 's/^Version: // p') |
---|
127 | |
---|
128 | # Check if we already have one. |
---|
129 | module=$(echo "$hdr" | sed -e 's/^linux-headers/openafs-modules/') |
---|
130 | if zcat $pkgfiles | \ |
---|
131 | dpkg-awk -f - "Package:^$module\$" "Version:^$(quote "$afsv+$hdrv")\$" | \ |
---|
132 | grep -q .; then |
---|
133 | echo "*** Already exists: $dist_arch $module" |
---|
134 | continue |
---|
135 | fi |
---|
136 | |
---|
137 | if fgrep -qx "$dist_arch $hdr" failed.log; then |
---|
138 | echo "*** Prior build failure: $dist_arch $module" |
---|
139 | continue |
---|
140 | fi |
---|
141 | |
---|
142 | # Attempt to build the module if requested. |
---|
143 | if [ yes = "$do_binary" ]; then |
---|
144 | echo "*** Building: $dist_arch $module" |
---|
145 | kversion=$(echo "$hdr" | sed 's/^linux-headers-//') |
---|
146 | schr apt-get -y install module-assistant "$hdr" |
---|
147 | schr m-a -i -t -l "$kversion" get openafs |
---|
148 | schr m-a -i -t -l "$kversion" unpack openafs |
---|
149 | schr touch \ |
---|
150 | "/usr/src/openafs-modules-${kversion}_${afsv}+${hdrv}_$arch.changes.pt" |
---|
151 | here=$(readlink -f .) |
---|
152 | schr sh -xec " |
---|
153 | eval \"\$(dpkg-architecture)\" |
---|
154 | if [ \"\$DEB_HOST_ARCH\" != amd64 ] && \ |
---|
155 | fgrep -x CONFIG_X86_64=y '/lib/modules/$kversion/build/.config'; then |
---|
156 | apt-get -y install binutils-multiarch util-linux |
---|
157 | type linux64 >/dev/null || apt-get -y install linux32 |
---|
158 | export KPKG_ARCH=amd64 |
---|
159 | export ARCH=x86_64 |
---|
160 | export PERSONALITY=linux64 |
---|
161 | export PATH=$here/hacked-arch:\$PATH |
---|
162 | fi |
---|
163 | if ! [ -e /usr/src/modules/openafs/debian/genchanges* ]; then |
---|
164 | install -m a=rx,u+w $here/genchanges.sh \ |
---|
165 | /usr/src/modules/openafs/debian/ |
---|
166 | fi |
---|
167 | if [ lenny = \"$dist\" ]; then |
---|
168 | install -m a=rx,u+w $here/genchanges.sh \ |
---|
169 | /usr/src/modules/openafs/debian/genchanges |
---|
170 | fi |
---|
171 | $PERSONALITY SIGNCHANGES=1 module-assistant -i -t -l '$kversion' \ |
---|
172 | auto-build openafs" </dev/null |
---|
173 | if [ $? -eq 0 ]; then |
---|
174 | echo "*** Successful build: $dist_arch $module" |
---|
175 | mkdir -p "$dist_arch" |
---|
176 | schr sh -c "cp /usr/src/openafs-modules* $dist_arch" |
---|
177 | else |
---|
178 | echo "*** Failed build: $dist_arch $module" |
---|
179 | echo "$dist_arch $hdr" >> failed.log |
---|
180 | fi |
---|
181 | schr sh -c "rm -f /usr/src/openafs-modules*" |
---|
182 | fi |
---|
183 | |
---|
184 | # Upload the module if requested, if we successfully built one. |
---|
185 | if [ yes = "$do_upload" ]; then |
---|
186 | ch="$dist_arch/${module}_${afsv}+${hdrv}_$arch.changes" |
---|
187 | if [ -e "$ch" ]; then |
---|
188 | echo "*** Uploading: $dist_arch $module" |
---|
189 | dareprepro -C openafs include "${dist}${apt_release}" $ch |
---|
190 | else |
---|
191 | echo "*** No module: $dist_arch $module" |
---|
192 | fi |
---|
193 | fi |
---|
194 | done |
---|
195 | |
---|
196 | if [ dapper = "$dist" ]; then |
---|
197 | # Dapper's equivs-build doesn't handle --arch correctly, so we can't |
---|
198 | # easily synthesize architecture-specific metapackages. |
---|
199 | echo "*** Skipping metapackage creation on dapper" |
---|
200 | exit |
---|
201 | fi |
---|
202 | |
---|
203 | # For each upstream metapackage found, if we have an appropriate |
---|
204 | # OpenAFS module, create and/or upload a metapackage tying the OpenAFS |
---|
205 | # module to the current version of the upstream metapackage, if one |
---|
206 | # does not already exist at the current version. |
---|
207 | for image_mpkg in $mpkgs; do |
---|
208 | info=$(schq apt-cache show --no-all-versions "$image_mpkg") |
---|
209 | ver=$(echo "$info" | sed -ne 's/^Version: //p') |
---|
210 | afs_mpkg=$(echo "$image_mpkg" | sed -e 's/^linux-image/openafs-modules/') |
---|
211 | hdr_mpkg=$(echo "$image_mpkg" | sed -e 's/^linux-image/linux-headers/') |
---|
212 | |
---|
213 | # Check if we have dkms |
---|
214 | if schq apt-cache show openafs-modules-dkms > /dev/null 2>&1; then |
---|
215 | # epoch |
---|
216 | ver=1:1.0.1 |
---|
217 | # Check if the headers we identified above actually exist |
---|
218 | # and deal appropriately (Trac: #948) |
---|
219 | should_skip=0 |
---|
220 | if ! schq apt-cache show "$hdr_mpkg" >/dev/null 2>&1; then |
---|
221 | # This is why we can't have nice things |
---|
222 | echo "*** $image_mpkg has no corresponding $hdr_mpkg, looking for alternatives..." |
---|
223 | should_skip=1 |
---|
224 | # OK, there's no header for it. Let's see what its siblings are |
---|
225 | # Get its dependency |
---|
226 | dep=$(echo "$info" | sed -ne 's/^Depends:.*\(linux-image-[^ ,]*\).*$/\1/p') |
---|
227 | # See what reverse-depends on that (i.e. what else provides it) |
---|
228 | rdeps=$(apt-cache --no-pre-depends --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances rdepends "$dep" | tr -d '\n' | sed -e "s/${dep}Reverse Depends://") |
---|
229 | for rd in $rdeps; do |
---|
230 | # If we managed to find ourself, skip it |
---|
231 | [ "$rd" = "$image_mpkg" ] && continue |
---|
232 | # See if it is a metapackage |
---|
233 | rdinfo=$(schq apt-cache show --no-all-versions "$rd") |
---|
234 | rdsrc=$(echo "$rdinfo" | sed -ne 's/^Source: //p') |
---|
235 | if [ $(expr "$rdsrc" : "$metareg") != 0 ]; then |
---|
236 | # OK, we found another metapackage that provides this. |
---|
237 | # Let's see if it has headers |
---|
238 | rdhdr=$(echo "$rd" | sed -e 's/^linux-image/linux-headers/') |
---|
239 | if schq apt-cache show "$rdhdr" > /dev/null 2>&1; then |
---|
240 | # Yay. Use it instead |
---|
241 | image_mpkg=$rd |
---|
242 | hdr_mpkg=$rdhdr |
---|
243 | should_skip=0 |
---|
244 | break |
---|
245 | fi |
---|
246 | fi |
---|
247 | done |
---|
248 | if [ $should_skip -ne 0 ]; then |
---|
249 | echo "*** Skipping $afs_mpkg (DKMS), can't find matching headers for $image_mpkg" |
---|
250 | continue |
---|
251 | fi |
---|
252 | fi |
---|
253 | fi |
---|
254 | |
---|
255 | # Check if we already have an up-to-date OpenAFS metapackage. |
---|
256 | if zcat $pkgfiles \ |
---|
257 | | dpkg-awk -f - "Package:^$(quote $afs_mpkg)\$" -- Version \ |
---|
258 | | sed -ne 's/^Version: //p' \ |
---|
259 | | fgrep -qx "$ver$tag"; then |
---|
260 | echo "*** Already up to date: $dist_arch $afs_mpkg" |
---|
261 | continue |
---|
262 | fi |
---|
263 | |
---|
264 | # Check if we have an OpenAFS module package, either in the apt |
---|
265 | # repository or in the build directory. |
---|
266 | case $ver in |
---|
267 | 1:*) |
---|
268 | # using dkms |
---|
269 | ;; |
---|
270 | *) |
---|
271 | dep=$(echo "$info" | sed -ne 's/^Depends:.*\(linux-image-[^ ,]*\).*$/\1/p') |
---|
272 | module=$(echo "$dep" | sed -e 's/^linux-image/openafs-modules/') |
---|
273 | if ! zcat $pkgfiles | fgrep -qx "Package: $module"; then |
---|
274 | ch=$(ls "$dist_arch/$module"_*.changes 2>/dev/null) |
---|
275 | if [ -z "$ch" ]; then |
---|
276 | echo "*** No module: $dist_arch $afs_mpkg" |
---|
277 | continue |
---|
278 | fi |
---|
279 | fi |
---|
280 | ;; |
---|
281 | esac |
---|
282 | |
---|
283 | # Build the metapackage if requested. |
---|
284 | if [ yes = "$do_binary" ]; then |
---|
285 | echo "*** Creating: $dist_arch $afs_mpkg" |
---|
286 | mkdir -p "meta/$dist_arch" |
---|
287 | case $ver in |
---|
288 | 1:*) |
---|
289 | # using dkms |
---|
290 | cat > meta/$dist_arch/$afs_mpkg.equivs <<EOF |
---|
291 | Section: openafs |
---|
292 | Priority: extra |
---|
293 | Standards-Version: 3.6.2 |
---|
294 | |
---|
295 | Package: $afs_mpkg |
---|
296 | Version: $ver$tag |
---|
297 | Maintainer: Debathena Project <debathena@mit.edu> |
---|
298 | Depends: openafs-modules-dkms, $image_mpkg, $hdr_mpkg |
---|
299 | Copyright: ../common/copyright |
---|
300 | Readme: ../common/README.in |
---|
301 | Description: Transitional package to install dkms |
---|
302 | Kernel specific openafs module packages are replaced with dkms |
---|
303 | modules. |
---|
304 | EOF |
---|
305 | ;; |
---|
306 | *) |
---|
307 | cat > meta/$dist_arch/$afs_mpkg.equivs <<EOF |
---|
308 | Section: openafs |
---|
309 | Priority: extra |
---|
310 | Standards-Version: 3.6.2 |
---|
311 | |
---|
312 | Package: $afs_mpkg |
---|
313 | Version: $ver$tag |
---|
314 | Maintainer: Debathena Project <debathena@mit.edu> |
---|
315 | Depends: $module, $image_mpkg (= $ver) |
---|
316 | Copyright: ../common/copyright |
---|
317 | Readme: ../common/README.in |
---|
318 | Description: Metapackage to enforce OpenAFS modules for kernel |
---|
319 | This package prevents automatic upgrades of the $img_mpkg |
---|
320 | kernel until there is a corresponding openafs-modules Debathena |
---|
321 | package available. |
---|
322 | EOF |
---|
323 | ;; |
---|
324 | esac |
---|
325 | schr apt-get -y install equivs |
---|
326 | (cd "meta/$dist_arch" && sch equivs-build -a "$arch" "$afs_mpkg.equivs") \ |
---|
327 | || exit 1 |
---|
328 | fi |
---|
329 | |
---|
330 | if [ yes = "$do_upload" ]; then |
---|
331 | deb=meta/$dist_arch/${afs_mpkg}_${ver/*:/}${tag}_${arch}.deb |
---|
332 | if [ -e "$deb" ]; then |
---|
333 | echo "*** Uploading: $dist_arch $afs_mpkg" |
---|
334 | dareprepro includedeb "${dist}${apt_release}" "$deb" |
---|
335 | else |
---|
336 | echo "*** No package: $dist_arch $afs_mpkg" |
---|
337 | fi |
---|
338 | fi |
---|
339 | done |
---|