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