3 # Copyright (C) 2008-2012 Alexandre Oliva <lxoliva@fsfla.org>
5 # This program is part of GNU Linux-libre, a GNU project that
6 # publishes scripts to clean up Linux so as to make it suitable for
7 # use in the GNU Project and in Free System Distributions.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
24 # deblob-main - prepare a GNU Linux-libre tarball out of a non-libre
25 # Linux tarball. It expects the Linux release (mver, say 3.0) as the
26 # first argument, the gnu sub-release (extra) as the second optional
27 # argument, and the patch release (sver, say .13) as an optional third
28 # argument. mver and sver are pasted together to form kver.
30 # linux-$kver.tar.bz2 and deblob-$mver must exist in the current
31 # directory, and the line that sets kver and extra in deblob-$mver
32 # must match mver and extra.
34 # The resulting tarball is put in linux-libre-$kver-gnu$extra.tar.bz2.
35 # An uncompressed xdelta that produces linux-libre-$kver-gnu$extra.tar
36 # out of linux-$kver.tar is put in linux-libre-$kver-gnu$extra.xdelta.
37 # This xdelta can be distributed to enable third parties to easily
38 # reconstruct the binary tarball starting out of sources downloaded
39 # from kernel.org, but without distributing non-Free Software
40 # yourself, because xdelta (unlike patches) is not reversible: the
41 # removed bits are not present in it at all.
43 # xdelta version 3 uses different command line syntax, and it switched
44 # to the more standardized but less efficient vcdiff file format.
45 # This script will also produce a vcdiff file if xdelta3 is present,
46 # and it expects the xdelta program to use the version 1 syntax.
48 # To enable you to check the differences between the tarballs, a patch
49 # file is generated in linux-libre-$kver-gnu$extra.patch. This patch
50 # file contains the non-Free blobs, even though in reversed form, so
51 # its distribution is discouraged.
53 # The tar files and binary deltas are finally compressed with bzip2,
54 # and optionally with lzip and xz too, if the compressors are
57 # At the end, the script attempts to generate a digital signature for
58 # the newly-created tarball. This is the last thing the script does,
59 # so interrupting it at that point to skip the signing won't fail to
62 # It is safe to interrupt the script at any other point. When it gets
63 # a ^C (other than during signing), it starts cleaning up all of its
64 # temporary and output files. If you insist, it may leave junk
65 # behind, and then it will refuse to run again before you clean it up
66 # by hand. It takes extra care to avoid overwriting useful files.
68 # If deblob-$mver finds any unexpected situation, it will error out,
69 # and then deblob-main will quit. Pass --force to deblob-main, before
70 # any other argument, for deblob-main to ignore any such situations.
73 --force) force=--force; shift;;
77 # We don't want e.g. diff output translations to affect us.
78 LC_ALL=C; export LC_ALL
79 LANGUAGE=C; export LANGUAGE
81 mver=$1 extra=$2 sver=$3
82 kver=$mver$sver gnu=gnu$extra
83 deblob= dir=`echo "$0" | sed 's,[^/]*$,,;s,^$,.,;s,/*$,,'`
85 if test -f linux-$kver.tar; then
87 elif test -f linux-$kver.tar.bz2; then
88 zext=tar.bz2 zcmd=bunzip2
89 elif test -f linux-$kver.tar.xz; then
91 elif test -f linux-$kver.tar.lz; then
92 zext=tar.lz zcmd="lzip -d"
93 elif test -f linux-$kver.tar.gz; then
94 zext=tar.gz zcmd=gunzip
95 elif test -f linux-$kver.tgz; then
98 echo linux-$kver.tar not found, tried .bz2, .xz, .lz, .gz and .tgz too >&2
102 if test -f deblob-$mver; then
104 elif test -f deblob; then
106 elif test -f $dir/deblob-$mver; then
107 cp $dir/deblob-$mver deblob
110 echo deblob does not exist >&2
114 x1="kver=$mver extra=$extra"
115 x2=`grep "^kver=[^ ]* extra=" $deblob`
116 if test "$x1" = "$x2"; then
119 echo deblob script does not match command-line arguments >&2
120 echo expected: $x1 >&2
128 linux-libre-$kver-$gnu.tar.bz2 \
129 linux-libre-$kver-$gnu.tar.bz2.asc \
130 linux-libre-$kver-$gnu.tar.bz2.sign \
131 linux-libre-$kver-$gnu.tar.xz \
132 linux-libre-$kver-$gnu.tar.xz.asc \
133 linux-libre-$kver-$gnu.tar.xz.sign \
134 linux-libre-$kver-$gnu.tar.lz \
135 linux-libre-$kver-$gnu.tar.lz.asc \
136 linux-libre-$kver-$gnu.tar.lz.sign \
137 linux-libre-$kver-$gnu.tar \
138 linux-libre-$kver-$gnu.tar.asc \
139 linux-libre-$kver-$gnu.tar.sign \
140 linux-libre-$kver-$gnu.patch \
141 linux-libre-$kver-$gnu.log \
142 linux-libre-$kver-$gnu.vcdiff \
143 linux-libre-$kver-$gnu.vcdiff.bz2 \
144 linux-libre-$kver-$gnu.vcdiff.bz2.asc \
145 linux-libre-$kver-$gnu.vcdiff.bz2.sign \
146 linux-libre-$kver-$gnu.vcdiff.xz \
147 linux-libre-$kver-$gnu.vcdiff.xz.asc \
148 linux-libre-$kver-$gnu.vcdiff.xz.sign \
149 linux-libre-$kver-$gnu.vcdiff.lz \
150 linux-libre-$kver-$gnu.vcdiff.lz.asc \
151 linux-libre-$kver-$gnu.vcdiff.lz.sign \
152 linux-libre-$kver-$gnu.xdelta \
153 linux-libre-$kver-$gnu.xdelta.bz2 \
154 linux-libre-$kver-$gnu.xdelta.bz2.asc \
155 linux-libre-$kver-$gnu.xdelta.bz2.sign \
156 linux-libre-$kver-$gnu.xdelta.xz \
157 linux-libre-$kver-$gnu.xdelta.xz.asc \
158 linux-libre-$kver-$gnu.xdelta.xz.sign \
159 linux-libre-$kver-$gnu.xdelta.lz \
160 linux-libre-$kver-$gnu.xdelta.lz.asc \
161 linux-libre-$kver-$gnu.xdelta.lz.sign \
164 echo $f already exists >&2
167 cleanup="$cleanup $f"
172 linux-libre-$kver-$gnu \
176 echo $d already exists >&2
179 cleanup="$cleanup $d"
182 if test -f $dir/deblob-$kver; then
183 if cmp $dir/deblob-$kver $deblob; then
186 echo $dir/deblob-$kver and $deblob are different >&2
191 if test ! -f deblob-check; then
192 if test -f $dir/deblob-check; then
193 cp $dir/deblob-check deblob-check
196 if test -f $dir/deblob-check; then
197 if cmp $dir/deblob-check deblob-check; then
200 echo $dir/deblob-check and deblob-check are different >&2
206 trap 'status=$?; echo cleaning up...; rm -rf $cleanup; (exit $status); exit' 0 1 2 15
210 if test -n "$zcmd"; then
211 echo Uncompressing linux-$kver.$zext into linux-$kver.tar
212 rm -rf linux-$kver.tar
213 cleanup="$cleanup linux-$kver.tar"
214 $zcmd < linux-$kver.$zext > linux-$kver.tar
217 echo Extracting linux-$kver.tar into linux-$kver
219 tar -xf linux-$kver.tar
220 rm -rf linux-libre-$kver-$gnu linux-libre-$kver-$gnu.tar
222 echo Copying linux-$kver to linux-libre-$kver-$gnu
223 cp linux-$kver.tar linux-libre-$kver-$gnu.tar
224 cp -lR linux-$kver/. linux-libre-$kver-$gnu
226 rm -f linux-libre-$kver-$gnu.log linux-libre-$kver-$gnu.log.tmp
227 echo Deblobbing within linux-libre-$kver-$gnu, saving output to linux-libre-$kver-$gnu.log
228 # We can't just pipe deblob into tee, for then we fail to detect
229 # error conditions. Use file renaming to tell whether we succeeded.
230 if (cd linux-libre-$kver-$gnu && /bin/sh ../$deblob $force) 2>&1; then
231 mv linux-libre-$kver-$gnu.log.tmp linux-libre-$kver-$gnu.log
232 fi | tee linux-libre-$kver-$gnu.log.tmp
233 if test ! -f linux-libre-$kver-$gnu.log; then
234 mv linux-libre-$kver-$gnu.log.tmp linux-libre-$kver-$gnu.log
235 echo $deblob failed, aborting >&2
238 rm -f linux-libre-$kver-$gnu.patch
240 # Do not copy these scripts for now, deblob-check regards itself as a blob.
241 # cp -p $0 $deblob deblob-check linux-libre-$kver-$gnu
243 echo Generating linux-libre-$kver-$gnu.patch
244 diff -druN linux-$kver linux-libre-$kver-$gnu > linux-libre-$kver-$gnu.patch || :
246 echo Removing removed or modified files from linux-libre-$kver-$gnu.tar
247 diff -rq linux-$kver linux-libre-$kver-$gnu |
249 s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\1/\3,p;
250 s,^Files \\(linux-$kver\\)/\\(.*\\) and linux-libre-$kver-$gnu/\\2 differ,\\1/\\2,p;
252 xargs tar --delete -f linux-libre-$kver-$gnu.tar
254 echo Adding modified or added files to linux-libre-$kver-$gnu.tar
255 rm -rf orig-linux-$kver
256 mv linux-$kver orig-linux-$kver
257 mv linux-libre-$kver-$gnu linux-$kver
258 diff -rq orig-linux-$kver linux-$kver |
260 s,^Files orig-\\(linux-$kver/.*\\) and \\1 differ,\\1,p;
261 s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\\1/\\3,p;
263 xargs tar --append -f linux-libre-$kver-$gnu.tar
265 echo Wiping out extracted trees
266 rm -rf linux-$kver orig-linux-$kver
268 echo Creating vcdiff between linux-$kver.tar and linux-libre-$kver-$gnu.tar
269 xdelta3 -e -9 -S djw -s linux-$kver.tar linux-libre-$kver-$gnu.tar linux-libre-$kver-$gnu.vcdiff || : # don't fail if xdelta3 is not present
271 echo Creating xdelta between linux-$kver.tar and linux-libre-$kver-$gnu.tar
272 xdelta delta -0 linux-$kver.tar linux-libre-$kver-$gnu.tar linux-libre-$kver-$gnu.xdelta || : # xdelta returns nonzero on success
274 cleanup="linux-libre-$kver-$gnu.tar linux-libre-$kver-$gnu.vcdiff linux-libre-$kver-$gnu.xdelta"
276 echo Compressing binary deltas and linux-libre-$kver-$gnu.tar
277 rm -f linux-$kver.tar
278 if test -f linux-libre-$kver-$gnu.vcdiff; then
279 bzip2 -k9 linux-libre-$kver-$gnu.vcdiff
280 xz -k9 linux-libre-$kver-$gnu.vcdiff || :
281 lzip -k9 linux-libre-$kver-$gnu.vcdiff || :
283 if test -f linux-libre-$kver-$gnu.xdelta; then
284 bzip2 -k9 linux-libre-$kver-$gnu.xdelta
285 xz -k9 linux-libre-$kver-$gnu.xdelta || :
286 lzip -k9 linux-libre-$kver-$gnu.xdelta || :
288 bzip2 -k9 linux-libre-$kver-$gnu.tar
289 xz -k9 linux-libre-$kver-$gnu.tar || :
290 lzip -k9 linux-libre-$kver-$gnu.tar || :
292 echo Done except for signing, feel free to interrupt
294 linux-libre-$kver-$gnu.tar \
295 linux-libre-$kver-$gnu.tar.bz2 \
296 linux-libre-$kver-$gnu.tar.xz \
297 linux-libre-$kver-$gnu.tar.lz \
298 linux-libre-$kver-$gnu.vcdiff \
299 linux-libre-$kver-$gnu.vcdiff.bz2 \
300 linux-libre-$kver-$gnu.vcdiff.xz \
301 linux-libre-$kver-$gnu.vcdiff.lz \
302 linux-libre-$kver-$gnu.xdelta \
303 linux-libre-$kver-$gnu.xdelta.bz2 \
304 linux-libre-$kver-$gnu.xdelta.xz \
305 linux-libre-$kver-$gnu.xdelta.lz \
308 gpg -a --detach-sign $f
315 trap 'status=$?; (exit $status); exit' 0 1 2 15
317 echo All set, please review linux-libre-$kver-$gnu.patch