source: trunk/debathena/third/openafs/debathenify-openafs @ 24680

Revision 24680, 8.5 KB checked in by broder, 14 years ago (diff)
Populate the build chroot sources.list based on the Debathena release target. Previously, the build chroots always had production and -proposed in their sources.list, which can be undesirable in several scenarios, e.g. you're re-building packages to go directly into production or you're trying to plan a transition in -development. Instead of keeping Debathena entries in the default sources.list, use sbuildhack's --setup-hook option to populate the sources.list at build time, based on the DEBATHENA_RELEASE environment variable. Assume builds are against the traditional value of production and -proposed if DEBATHENA_RELEASE is unset.
  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3quote() {
4  echo "$1" | sed 's/[^[:alnum:]]/\\&/g'
5}
6
7fail() {
8  echo "$@" >&2
9  exit 1
10}
11
12dist_arch=$1; shift
13a=
14if [ "$1" = "-A" ]; then a=-A; shift; fi
15chroot=$dist_arch-sbuild
16dist=$(echo "$dist_arch" | sed 's/^\(.*\)-\([^-]*\)$/\1/')
17arch=$(echo "$dist_arch" | sed 's/^\(.*\)-\([^-]*\)$/\2/')
18. /mit/debathena/bin/debian-versions.sh
19tag=$(gettag $dist)
20: ${DEBATHENA_APT=/mit/debathena/apt}
21: ${DEBATHENA_RELEASE=}
22export DEBATHENA_APT
23export DEBATHENA_RELEASE
24pkgfiles="$DEBATHENA_APT/dists/$dist/openafs/binary-$arch/Packages.gz $DEBATHENA_APT/dists/${dist}-proposed/openafs/binary-$arch/Packages.gz"
25
26do_binary=no
27do_upload=no
28for arg; do
29  case $arg in
30  source)
31    ;;
32  binary)
33    do_binary=yes
34    ;;
35  upload)
36    do_upload=yes
37    ;;
38  *)
39    fail "Usage: $0 DIST_ARCH [-A] source|binary|upload ..."
40    ;;
41  esac
42done
43
44sid=$(schroot -b -c "$chroot") || exit 1
45trap 'schroot -e -c "$sid"' EXIT
46sch() { schroot -r -c "$sid" -- "$@"; }           # Run in the chroot
47schq() { schroot -q -r -c "$sid" -- "$@"; }       # Run in the chroot quietly
48schr() { schroot -r -c "$sid" -u root -- "$@"; }  # Run in the chroot as root
49schr apt-get -qq -y update || exit 3
50
51afsv=$(schq apt-cache show --no-all-versions openafs-modules-source | \
52  sed -n 's/^Version: // p')
53
54# Get all of the packages named linux-image-*.  This list includes
55# three types of packages:
56#  - Actual kernel images (e.g. linux-image-2.6.24-19-generic)
57#  - Metapackages (e.g. linux-image-generic) which are used to keep
58#    kernel images up to date
59#  - Meta-metapackages which depend on other metapackages; these
60#    exist for transitional reasons or to provide more generic names
61#    (e.g. linux-image-amd64 depends on linux-image-2.6-amd64 in
62#    lenny)
63#
64# We can distinguish actual kernel images from metapackages by looking
65# at the source package; actual images will have the source "linux"
66# (Ubuntu) or "linux-2.6" (Debian) while both kinds of metapackages
67# will have the source "linux-meta" (Ubuntu) or "linux-latest-2.6"
68# (Debian).
69#
70# To distinguish metapackages from meta-metapackages, we need to look
71# at whether the package's linux-image-* dependency is an actual
72# kernel image or a metapackage.
73pkgs=$(sch apt-cache search --names-only '^linux-image-' | awk '{print $1}')
74
75# Identify the metapackages which depend directly on actual kernel
76# images, as well as the header packages corresponding to those
77# dependencies.
78metareg='linux-meta\|linux-latest.*'
79mpkgs=
80headers=
81for pkg in $pkgs; do
82  info=$(schq apt-cache show --no-all-versions "$pkg")
83
84  # Disregard if this is not a metapackage.
85  src=$(echo "$info" | sed -ne 's/^Source: //p')
86  if [ $(expr "$src" : "$metareg") = 0 ]; then
87    continue
88  fi
89
90  # Disregard if this package's linux-image dependency is a metapackage.
91  dep=$(echo "$info" | sed -ne 's/^Depends:.*\(linux-image-[^ ,]*\).*$/\1/p')
92  depsrc=$(schq apt-cache show --no-all-versions "$dep" \
93    | sed -ne 's/^Source: //p')
94  if [ $(expr "$depsrc" : "$metareg") != 0 ]; then
95    continue
96  fi
97
98  # Find the corresponding linux-headers package.  If there isn't one,
99  # this is probably an Ubuntu linux-image-debug metapackage and we
100  # can ignore it.
101  hdr=$(echo "$dep" | sed -e 's/image/headers/')
102  hdrinfo=$(schq apt-cache show "$hdr" 2>/dev/null)
103  if [ -z "$hdrinfo" ]; then
104    continue
105  fi
106
107  mpkgs="$mpkgs $pkg"
108  headers="$headers $hdr"
109done
110
111# For each header package found, attempt to build and/or upload
112# (according to the command-line arguments) a corresponding
113# openafs-modules package if one does not already exist.
114for hdr in $headers; do
115  hdrv=$(schq apt-cache show --no-all-versions "$hdr" | \
116    sed -n 's/^Version: // p')
117
118  # Check if we already have one.
119  module=$(echo "$hdr" | sed -e 's/^linux-headers/openafs-modules/')
120  if zcat $pkgfiles | \
121     dpkg-awk -f - "Package:^$module\$" "Version:^$(quote "$afsv+$hdrv")\$" | \
122     grep -q .; then
123    echo "*** Already exists: $dist_arch $module"
124    continue
125  fi
126
127  if fgrep -qx "$dist_arch $hdr" failed.log; then
128    echo "*** Prior build failure: $dist_arch $module"
129    continue
130  fi
131
132  # Attempt to build the module if requested.
133  if [ yes = "$do_binary" ]; then
134    echo "*** Building: $dist_arch $module"
135    kversion=$(echo "$hdr" | sed 's/^linux-headers-//')
136    schr apt-get -y install module-assistant "$hdr"
137    schr m-a -i -t -l "$kversion" get openafs
138    schr m-a -i -t -l "$kversion" unpack openafs
139    schr touch \
140      "/usr/src/openafs-modules-${kversion}_${afsv}+${hdrv}_$arch.changes.pt"
141    here=$(readlink -f .)
142    schr sh -xec "
143      eval \"\$(dpkg-architecture)\"
144      if [ \"\$DEB_HOST_ARCH\" != amd64 ] && \
145        fgrep -x CONFIG_X86_64=y '/lib/modules/$kversion/build/.config'; then
146        apt-get -y install binutils-multiarch util-linux
147        type linux64 >/dev/null || apt-get -y install linux32
148        export KPKG_ARCH=amd64
149        export ARCH=x86_64
150        export PERSONALITY=linux64
151        export PATH=$here/hacked-arch:\$PATH
152      fi
153      if ! [ -e /usr/src/modules/openafs/debian/genchanges* ]; then
154        install -m a=rx,u+w $here/genchanges.sh \
155          /usr/src/modules/openafs/debian/
156      fi
157      if [ lenny = \"$dist\" ]; then
158        install -m a=rx,u+w $here/genchanges.sh \
159          /usr/src/modules/openafs/debian/genchanges
160      fi
161      $PERSONALITY SIGNCHANGES=1 module-assistant -i -t -l '$kversion' \
162        auto-build openafs" </dev/null
163    if [ $? -eq 0 ]; then
164      echo "*** Successful build: $dist_arch $module"
165      mkdir -p "$dist_arch"
166      schr sh -c "cp /usr/src/openafs-modules* $dist_arch"
167    else
168      echo "*** Failed build: $dist_arch $module"
169      echo "$dist_arch $hdr" >> failed.log
170    fi
171    schr sh -c "rm -f /usr/src/openafs-modules*"
172  fi
173
174  # Upload the module if requested, if we successfully built one.
175  if [ yes = "$do_upload" ]; then
176    ch="$dist_arch/${module}_${afsv}+${hdrv}_$arch.changes"
177    if [ -e "$ch" ]; then
178      echo "*** Uploading: $dist_arch $module"
179      dareprepro -C openafs include "${dist}${DEBATHENA_RELEASE}" $ch
180    else
181      echo "*** No module: $dist_arch $module"
182    fi
183  fi
184done
185
186if [ dapper = "$dist" ]; then
187  # Dapper's equivs-build doesn't handle --arch correctly, so we can't
188  # easily synthesize architecture-specific metapackages.
189  echo "*** Skipping metapackage creation on dapper"
190  exit
191fi
192
193# For each upstream metapackage found, if we have an appropriate
194# OpenAFS module, create and/or upload a metapackage tying the OpenAFS
195# module to the current version of the upstream metapackage, if one
196# does not already exist at the current version.
197for image_mpkg in $mpkgs; do
198  info=$(schq apt-cache show --no-all-versions "$image_mpkg")
199  ver=$(echo "$info" | sed -ne 's/^Version: //p')
200  afs_mpkg=$(echo "$image_mpkg" | sed -e 's/^linux-image/openafs-modules/')
201
202  # Check if we already have an up-to-date OpenAFS metapackage.
203  repover=$(zcat $pkgfiles \
204    | dpkg-awk -f - "Package:^$(quote $afs_mpkg)\$" -- Version \
205    | sed -e 's/^Version: //')
206  if [ "x$repover" = "x$ver$tag" ]; then
207    echo "*** Already up to date: $dist_arch $afs_mpkg"
208    continue
209  fi
210
211  # Check if we have an OpenAFS module package, either in the apt
212  # repository or in the build directory.
213  dep=$(echo "$info" | sed -ne 's/^Depends:.*\(linux-image-[^ ,]*\).*$/\1/p')
214  module=$(echo "$dep" | sed -e 's/^linux-image/openafs-modules/')
215  if ! zcat $pkgfiles | fgrep -qx "Package: $module"; then
216    ch=$(ls "$dist_arch/$module"_*.changes 2>/dev/null)
217    if [ -z "$ch" ]; then
218      echo "*** No module: $dist_arch $afs_mpkg"
219      continue
220    fi
221  fi
222
223  # Build the metapackage if requested.
224  if [ yes = "$do_binary" ]; then
225    echo "*** Creating: $dist_arch $afs_mpkg"
226    mkdir -p "meta/$dist_arch"
227    cat > meta/$dist_arch/$afs_mpkg.equivs <<EOF
228Section: openafs
229Priority: extra
230Standards-Version: 3.6.2
231
232Package: $afs_mpkg
233Version: $ver$tag
234Maintainer: Debathena Project <debathena@mit.edu>
235Depends: $module, $image_mpkg (= $ver)
236Copyright: ../common/copyright
237Readme: ../common/README.in
238Description: Metapackage to enforce OpenAFS modules for kernel
239 This package prevents automatic upgrades of the $ktype generic until
240 there is a corresponding openafs-modules Debathena package available.
241EOF
242    schr apt-get -y install equivs
243    (cd "meta/$dist_arch" && sch equivs-build -a "$arch" "$afs_mpkg.equivs") \
244      || exit 1
245  fi
246
247  if [ yes = "$do_upload" ]; then
248    deb=meta/$dist_arch/${afs_mpkg}_${ver}${tag}_${arch}.deb
249    if [ -e "$deb" ]; then
250      echo "*** Uploading: $dist_arch $afs_mpkg"
251      dareprepro includedeb "${dist}${DEBATHENA_RELEASE}" "$deb"
252    else
253      echo "*** No package: $dist_arch $afs_mpkg"
254    fi
255  fi
256done
Note: See TracBrowser for help on using the repository browser.