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

Revision 25141, 9.4 KB checked in by geofft, 13 years ago (diff)
debathenify-openafs: Epochs don't end up in .deb filenames
  • 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
208  # Check if we have dkms
209  if schq apt-cache show openafs-modules-dkms > /dev/null 2>&1; then
210    # epoch
211    ver=1:1.0
212  fi
213
214  # Check if we already have an up-to-date OpenAFS metapackage.
215  repover=$(zcat $pkgfiles \
216    | dpkg-awk -f - "Package:^$(quote $afs_mpkg)\$" -- Version \
217    | sed -e 's/^Version: //')
218  if [ "x$repover" = "x$ver$tag" ]; then
219    echo "*** Already up to date: $dist_arch $afs_mpkg"
220    continue
221  fi
222
223  # Check if we have an OpenAFS module package, either in the apt
224  # repository or in the build directory.
225  case $ver in
226    1:*)
227      # using dkms
228    ;;
229    *)
230      dep=$(echo "$info" | sed -ne 's/^Depends:.*\(linux-image-[^ ,]*\).*$/\1/p')
231      module=$(echo "$dep" | sed -e 's/^linux-image/openafs-modules/')
232      if ! zcat $pkgfiles | fgrep -qx "Package: $module"; then
233        ch=$(ls "$dist_arch/$module"_*.changes 2>/dev/null)
234        if [ -z "$ch" ]; then
235          echo "*** No module: $dist_arch $afs_mpkg"
236          continue
237        fi
238      fi
239    ;;
240  esac
241
242  # Build the metapackage if requested.
243  if [ yes = "$do_binary" ]; then
244    echo "*** Creating: $dist_arch $afs_mpkg"
245    mkdir -p "meta/$dist_arch"
246    case $ver in
247      1:*)
248        # using dkms
249        cat > meta/$dist_arch/$afs_mpkg.equivs <<EOF
250Section: openafs
251Priority: extra
252Standards-Version: 3.6.2
253
254Package: $afs_mpkg
255Version: $ver$tag
256Maintainer: Debathena Project <debathena@mit.edu>
257Depends: openafs-modules-dkms
258Copyright: ../common/copyright
259Readme: ../common/README.in
260Description: Transitional package to install dkms
261 Kernel specific openafs module packages are replaced with dkms
262 modules.
263EOF
264      ;;
265      *)
266        cat > meta/$dist_arch/$afs_mpkg.equivs <<EOF
267Section: openafs
268Priority: extra
269Standards-Version: 3.6.2
270
271Package: $afs_mpkg
272Version: $ver$tag
273Maintainer: Debathena Project <debathena@mit.edu>
274Depends: $module, $image_mpkg (= $ver)
275Copyright: ../common/copyright
276Readme: ../common/README.in
277Description: Metapackage to enforce OpenAFS modules for kernel
278 This package prevents automatic upgrades of the $img_mpkg
279 kernel until there is a corresponding openafs-modules Debathena
280 package available.
281EOF
282      ;;
283    esac
284    schr apt-get -y install equivs
285    (cd "meta/$dist_arch" && sch equivs-build -a "$arch" "$afs_mpkg.equivs") \
286      || exit 1
287  fi
288
289  if [ yes = "$do_upload" ]; then
290    deb=meta/$dist_arch/${afs_mpkg}_${ver/*:/}${tag}_${arch}.deb
291    if [ -e "$deb" ]; then
292      echo "*** Uploading: $dist_arch $afs_mpkg"
293      dareprepro includedeb "${dist}${apt_release}" "$deb"
294    else
295      echo "*** No package: $dist_arch $afs_mpkg"
296    fi
297  fi
298done
Note: See TracBrowser for help on using the repository browser.