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

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