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

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