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

Revision 25851, 11.2 KB checked in by jdreed, 10 years ago (diff)
Bump DKMS metapackage version so that the metapackges will get rebuilt correctly
  • Property svn:executable set to *
Line 
1#!/bin/bash
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
19if [ -e nobuild ] && fgrep -q "$dist" nobuild; then
20  echo "Skipping $dist_$arch since $dist is listed in ./nobuild."
21  exit
22fi
23tag=$(gettag $dist)
24: ${DEBATHENA_APT=/mit/debathena/apt}
25: ${DEBATHENA_RELEASE=production}
26export DEBATHENA_APT
27export DEBATHENA_RELEASE
28pkgfiles="$DEBATHENA_APT/dists/$dist/openafs/binary-$arch/Packages.gz $DEBATHENA_APT/dists/${dist}-proposed/openafs/binary-$arch/Packages.gz"
29
30if [ "$DEBATHENA_RELEASE" = "production" ]; then
31    apt_release=""
32else
33    apt_release="$DEBATHENA_RELEASE"
34fi
35
36do_binary=no
37do_upload=no
38for 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
52done
53
54sid=$(schroot -b -c "$chroot") || exit 1
55trap 'schroot -e -c "$sid"' EXIT
56sch() { schroot -r -c "$sid" -- "$@"; }           # Run in the chroot
57schq() { schroot -q -r -c "$sid" -- "$@"; }       # Run in the chroot quietly
58schr() { schroot -r -c "$sid" -u root -- "$@"; }  # Run in the chroot as root
59schr apt-get -qq -y update || exit 3
60
61afsv=$(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.
83pkgs=$(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.
88metareg='linux-meta\|linux-latest.*'
89mpkgs=
90headers=
91for 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"
119done
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.
124for 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
194done
195
196if [ 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
201fi
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.
207for 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
291Section: openafs
292Priority: extra
293Standards-Version: 3.6.2
294
295Package: $afs_mpkg
296Version: $ver$tag
297Maintainer: Debathena Project <debathena@mit.edu>
298Depends: openafs-modules-dkms, $image_mpkg, $hdr_mpkg
299Copyright: ../common/copyright
300Readme: ../common/README.in
301Description: Transitional package to install dkms
302 Kernel specific openafs module packages are replaced with dkms
303 modules.
304EOF
305      ;;
306      *)
307        cat > meta/$dist_arch/$afs_mpkg.equivs <<EOF
308Section: openafs
309Priority: extra
310Standards-Version: 3.6.2
311
312Package: $afs_mpkg
313Version: $ver$tag
314Maintainer: Debathena Project <debathena@mit.edu>
315Depends: $module, $image_mpkg (= $ver)
316Copyright: ../common/copyright
317Readme: ../common/README.in
318Description: 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.
322EOF
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
339done
Note: See TracBrowser for help on using the repository browser.