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 mver=$1 extra=$2 sver=$3
78 kver=$mver$sver gnu=gnu$extra
79 deblob= dir=`echo "$0" | sed 's,[^/]*$,,;s,^$,.,;s,/*$,,'`
81 if test -f linux-$kver.tar; then
83 elif test -f linux-$kver.tar.bz2; then
84 zext=tar.bz2 zcmd=bunzip2
85 elif test -f linux-$kver.tar.xz; then
87 elif test -f linux-$kver.tar.lz; then
88 zext=tar.lz zcmd="lzip -d"
89 elif test -f linux-$kver.tar.gz; then
90 zext=tar.gz zcmd=gunzip
91 elif test -f linux-$kver.tgz; then
94 echo linux-$kver.tar not found, tried .bz2, .xz, .lz, .gz and .tgz too >&2
98 if test -f deblob-$mver; then
100 elif test -f deblob; then
102 elif test -f $dir/deblob-$mver; then
103 cp $dir/deblob-$mver deblob
106 echo deblob does not exist >&2
110 x1="kver=$mver extra=$extra"
111 x2=`grep "^kver=[^ ]* extra=" $deblob`
112 if test "$x1" = "$x2"; then
115 echo deblob script does not match command-line arguments >&2
116 echo expected: $x1 >&2
124 linux-libre-$kver-$gnu.tar.bz2 \
125 linux-libre-$kver-$gnu.tar.bz2.asc \
126 linux-libre-$kver-$gnu.tar.bz2.sign \
127 linux-libre-$kver-$gnu.tar.xz \
128 linux-libre-$kver-$gnu.tar.xz.asc \
129 linux-libre-$kver-$gnu.tar.xz.sign \
130 linux-libre-$kver-$gnu.tar.lz \
131 linux-libre-$kver-$gnu.tar.lz.asc \
132 linux-libre-$kver-$gnu.tar.lz.sign \
133 linux-libre-$kver-$gnu.tar \
134 linux-libre-$kver-$gnu.tar.asc \
135 linux-libre-$kver-$gnu.tar.sign \
136 linux-libre-$kver-$gnu.patch \
137 linux-libre-$kver-$gnu.log \
138 linux-libre-$kver-$gnu.vcdiff \
139 linux-libre-$kver-$gnu.vcdiff.bz2 \
140 linux-libre-$kver-$gnu.vcdiff.bz2.asc \
141 linux-libre-$kver-$gnu.vcdiff.bz2.sign \
142 linux-libre-$kver-$gnu.vcdiff.xz \
143 linux-libre-$kver-$gnu.vcdiff.xz.asc \
144 linux-libre-$kver-$gnu.vcdiff.xz.sign \
145 linux-libre-$kver-$gnu.vcdiff.lz \
146 linux-libre-$kver-$gnu.vcdiff.lz.asc \
147 linux-libre-$kver-$gnu.vcdiff.lz.sign \
148 linux-libre-$kver-$gnu.xdelta \
149 linux-libre-$kver-$gnu.xdelta.bz2 \
150 linux-libre-$kver-$gnu.xdelta.bz2.asc \
151 linux-libre-$kver-$gnu.xdelta.bz2.sign \
152 linux-libre-$kver-$gnu.xdelta.xz \
153 linux-libre-$kver-$gnu.xdelta.xz.asc \
154 linux-libre-$kver-$gnu.xdelta.xz.sign \
155 linux-libre-$kver-$gnu.xdelta.lz \
156 linux-libre-$kver-$gnu.xdelta.lz.asc \
157 linux-libre-$kver-$gnu.xdelta.lz.sign \
160 echo $f already exists >&2
163 cleanup="$cleanup $f"
168 linux-libre-$kver-$gnu \
172 echo $d already exists >&2
175 cleanup="$cleanup $d"
178 if test -f $dir/deblob-$kver; then
179 if cmp $dir/deblob-$kver $deblob; then
182 echo $dir/deblob-$kver and $deblob are different >&2
187 if test ! -f deblob-check; then
188 if test -f $dir/deblob-check; then
189 cp $dir/deblob-check deblob-check
192 if test -f $dir/deblob-check; then
193 if cmp $dir/deblob-check deblob-check; then
196 echo $dir/deblob-check and deblob-check are different >&2
202 trap 'status=$?; echo cleaning up...; rm -rf $cleanup; (exit $status); exit' 0 1 2 15
206 if test -n "$zcmd"; then
207 echo Uncompressing linux-$kver.$zext into linux-$kver.tar
208 rm -rf linux-$kver.tar
209 cleanup="$cleanup linux-$kver.tar"
210 $zcmd < linux-$kver.$zext > linux-$kver.tar
213 echo Extracting linux-$kver.tar into linux-$kver
215 tar -xf linux-$kver.tar
216 rm -rf linux-libre-$kver-$gnu linux-libre-$kver-$gnu.tar
218 echo Copying linux-$kver to linux-libre-$kver-$gnu
219 cp linux-$kver.tar linux-libre-$kver-$gnu.tar
220 cp -lR linux-$kver/. linux-libre-$kver-$gnu
222 rm -f linux-libre-$kver-$gnu.log linux-libre-$kver-$gnu.log.tmp
223 echo Deblobbing within linux-libre-$kver-$gnu, saving output to linux-libre-$kver-$gnu.log
224 # We can't just pipe deblob into tee, for then we fail to detect
225 # error conditions. Use file renaming to tell whether we succeeded.
226 if (cd linux-libre-$kver-$gnu && /bin/sh ../$deblob $force) 2>&1; then
227 mv linux-libre-$kver-$gnu.log.tmp linux-libre-$kver-$gnu.log
228 fi | tee linux-libre-$kver-$gnu.log.tmp
229 if test ! -f linux-libre-$kver-$gnu.log; then
230 mv linux-libre-$kver-$gnu.log.tmp linux-libre-$kver-$gnu.log
231 echo $deblob failed, aborting >&2
234 rm -f linux-libre-$kver-$gnu.patch
236 # Do not copy these scripts for now, deblob-check regards itself as a blob.
237 # cp -p $0 $deblob deblob-check linux-libre-$kver-$gnu
239 echo Generating linux-libre-$kver-$gnu.patch
240 diff -druN linux-$kver linux-libre-$kver-$gnu > linux-libre-$kver-$gnu.patch || :
242 echo Removing removed or modified files from linux-libre-$kver-$gnu.tar
243 diff -rq linux-$kver linux-libre-$kver-$gnu |
245 s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\1/\3,p;
246 s,^Files \\(linux-$kver\\)/\\(.*\\) and linux-libre-$kver-$gnu/\\2 differ,\\1/\\2,p;
248 xargs tar --delete -f linux-libre-$kver-$gnu.tar
250 echo Adding modified or added files to linux-libre-$kver-$gnu.tar
251 rm -rf orig-linux-$kver
252 mv linux-$kver orig-linux-$kver
253 mv linux-libre-$kver-$gnu linux-$kver
254 diff -rq orig-linux-$kver linux-$kver |
256 s,^Files orig-\\(linux-$kver/.*\\) and \\1 differ,\\1,p;
257 s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\\1/\\3,p;
259 xargs tar --append -f linux-libre-$kver-$gnu.tar
261 echo Wiping out extracted trees
262 rm -rf linux-$kver orig-linux-$kver
264 echo Creating vcdiff between linux-$kver.tar and linux-libre-$kver-$gnu.tar
265 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
267 echo Creating xdelta between linux-$kver.tar and linux-libre-$kver-$gnu.tar
268 xdelta delta -0 linux-$kver.tar linux-libre-$kver-$gnu.tar linux-libre-$kver-$gnu.xdelta || : # xdelta returns nonzero on success
270 echo Compressing binary deltas and linux-libre-$kver-$gnu.tar
271 rm -f linux-$kver.tar
272 if test -f linux-libre-$kver-$gnu.vcdiff; then
273 bzip2 -k9 linux-libre-$kver-$gnu.vcdiff
274 xz -k9 linux-libre-$kver-$gnu.vcdiff || :
275 lzip -k9 linux-libre-$kver-$gnu.vcdiff || :
276 rm -f linux-libre-$kver-$gnu.vcdiff
278 if test -f linux-libre-$kver-$gnu.xdelta; then
279 bzip2 -k9 linux-libre-$kver-$gnu.xdelta
280 xz -k9 linux-libre-$kver-$gnu.xdelta || :
281 lzip -k9 linux-libre-$kver-$gnu.xdelta || :
282 rm -f linux-libre-$kver-$gnu.xdelta
284 bzip2 -k9 linux-libre-$kver-$gnu.tar
285 xz -k9 linux-libre-$kver-$gnu.tar || :
286 lzip -k9 linux-libre-$kver-$gnu.tar || :
288 cleanup=linux-libre-$kver-$gnu.tar
290 echo Done except for signing, feel free to interrupt
292 linux-libre-$kver-$gnu.tar \
293 linux-libre-$kver-$gnu.tar.bz2 \
294 linux-libre-$kver-$gnu.tar.xz \
295 linux-libre-$kver-$gnu.tar.lz \
296 linux-libre-$kver-$gnu.vcdiff.bz2 \
297 linux-libre-$kver-$gnu.vcdiff.xz \
298 linux-libre-$kver-$gnu.vcdiff.lz \
299 linux-libre-$kver-$gnu.xdelta.bz2 \
300 linux-libre-$kver-$gnu.xdelta.xz \
301 linux-libre-$kver-$gnu.xdelta.lz \
304 gpg -a --detach-sign $f
309 rm -f linux-libre-$kver-$gnu.tar
312 trap 'status=$?; (exit $status); exit' 0 1 2 15
314 echo All set, please review linux-libre-$kver-$gnu.patch