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.bz2; then
82 echo linux-$kver.tar.bz2 does not exist >&2
86 if test -f deblob-$mver; then
88 elif test -f deblob; then
90 elif test -f $dir/deblob-$mver; then
91 cp $dir/deblob-$mver deblob
94 echo deblob does not exist >&2
98 x1="kver=$mver extra=$extra"
99 x2=`grep "^kver=[^ ]* extra=" $deblob`
100 if test "$x1" = "$x2"; then
103 echo deblob script does not match command-line arguments >&2
104 echo expected: $x1 >&2
112 linux-libre-$kver-$gnu.tar.bz2 \
113 linux-libre-$kver-$gnu.tar.bz2.asc \
114 linux-libre-$kver-$gnu.tar.bz2.sign \
115 linux-libre-$kver-$gnu.tar.xz \
116 linux-libre-$kver-$gnu.tar.xz.asc \
117 linux-libre-$kver-$gnu.tar.xz.sign \
118 linux-libre-$kver-$gnu.tar.lz \
119 linux-libre-$kver-$gnu.tar.lz.asc \
120 linux-libre-$kver-$gnu.tar.lz.sign \
122 linux-libre-$kver-$gnu.tar \
123 linux-libre-$kver-$gnu.patch \
124 linux-libre-$kver-$gnu.log \
125 linux-libre-$kver-$gnu.vcdiff \
126 linux-libre-$kver-$gnu.vcdiff.bz2 \
127 linux-libre-$kver-$gnu.vcdiff.bz2.asc \
128 linux-libre-$kver-$gnu.vcdiff.bz2.sign \
129 linux-libre-$kver-$gnu.vcdiff.xz \
130 linux-libre-$kver-$gnu.vcdiff.xz.asc \
131 linux-libre-$kver-$gnu.vcdiff.xz.sign \
132 linux-libre-$kver-$gnu.vcdiff.lz \
133 linux-libre-$kver-$gnu.vcdiff.lz.asc \
134 linux-libre-$kver-$gnu.vcdiff.lz.sign \
135 linux-libre-$kver-$gnu.xdelta \
136 linux-libre-$kver-$gnu.xdelta.bz2 \
137 linux-libre-$kver-$gnu.xdelta.bz2.asc \
138 linux-libre-$kver-$gnu.xdelta.bz2.sign \
139 linux-libre-$kver-$gnu.xdelta.xz \
140 linux-libre-$kver-$gnu.xdelta.xz.asc \
141 linux-libre-$kver-$gnu.xdelta.xz.sign \
142 linux-libre-$kver-$gnu.xdelta.lz \
143 linux-libre-$kver-$gnu.xdelta.lz.asc \
144 linux-libre-$kver-$gnu.xdelta.lz.sign \
147 echo $f already exists >&2
150 cleanup="$cleanup $f"
155 linux-libre-$kver-$gnu \
159 echo $d already exists >&2
162 cleanup="$cleanup $d"
165 if test -f $dir/deblob-$kver; then
166 if cmp $dir/deblob-$kver $deblob; then
169 echo $dir/deblob-$kver and $deblob are different >&2
174 if test ! -f deblob-check; then
175 if test -f $dir/deblob-check; then
176 cp $dir/deblob-check deblob-check
179 if test -f $dir/deblob-check; then
180 if cmp $dir/deblob-check deblob-check; then
183 echo $dir/deblob-check and deblob-check are different >&2
189 trap "status=$?; echo cleaning up...; rm -rf $cleanup; (exit $status); exit" 0 1 2 15
193 echo Uncompressing linux-$kver.tar.bz2 into linux-$kver.tar
194 rm -rf linux-$kver linux-$kver.tar
195 bunzip2 < linux-$kver.tar.bz2 > linux-$kver.tar
197 echo Extracting linux-$kver.tar into linux-$kver
198 tar -xf linux-$kver.tar
199 rm -rf linux-libre-$kver-$gnu linux-libre-$kver-$gnu.tar
201 echo Copying linux-$kver to linux-libre-$kver-$gnu
202 cp linux-$kver.tar linux-libre-$kver-$gnu.tar
203 cp -lR linux-$kver/. linux-libre-$kver-$gnu
205 rm -f linux-libre-$kver-$gnu.log linux-libre-$kver-$gnu.log.tmp
206 echo Deblobbing within linux-libre-$kver-$gnu, saving output to linux-libre-$kver-$gnu.log
207 # We can't just pipe deblob into tee, for then we fail to detect
208 # error conditions. Use file renaming to tell whether we succeeded.
209 if (cd linux-libre-$kver-$gnu && /bin/sh ../$deblob $force) 2>&1; then
210 mv linux-libre-$kver-$gnu.log.tmp linux-libre-$kver-$gnu.log
211 fi | tee linux-libre-$kver-$gnu.log.tmp
212 if test ! -f linux-libre-$kver-$gnu.log; then
213 mv linux-libre-$kver-$gnu.log.tmp linux-libre-$kver-$gnu.log
214 echo $deblob failed, aborting >&2
217 rm -f linux-libre-$kver-$gnu.patch
219 # Do not copy these scripts for now, deblob-check regards itself as a blob.
220 # cp -p $0 $deblob deblob-check linux-libre-$kver-$gnu
222 echo Generating linux-libre-$kver-$gnu.patch
223 diff -druN linux-$kver linux-libre-$kver-$gnu > linux-libre-$kver-$gnu.patch || :
225 echo Removing removed or modified files from linux-libre-$kver-$gnu.tar
226 diff -rq linux-$kver linux-libre-$kver-$gnu |
228 s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\1/\3,p;
229 s,^Files \\(linux-$kver\\)/\\(.*\\) and linux-libre-$kver-$gnu/\\2 differ,\\1/\\2,p;
231 xargs tar --delete -f linux-libre-$kver-$gnu.tar
233 echo Adding modified or added files to linux-libre-$kver-$gnu.tar
234 rm -rf orig-linux-$kver
235 mv linux-$kver orig-linux-$kver
236 mv linux-libre-$kver-$gnu linux-$kver
237 diff -rq orig-linux-$kver linux-$kver |
239 s,^Files orig-\\(linux-$kver/.*\\) and \\1 differ,\\1,p;
240 s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\\1/\\3,p;
242 xargs tar --append -f linux-libre-$kver-$gnu.tar
244 echo Wiping out extracted trees
245 rm -rf linux-$kver orig-linux-$kver
247 echo Creating vcdiff between linux-$kver.tar and linux-libre-$kver-$gnu.tar
248 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
250 echo Creating xdelta between linux-$kver.tar and linux-libre-$kver-$gnu.tar
251 xdelta delta -0 linux-$kver.tar linux-libre-$kver-$gnu.tar linux-libre-$kver-$gnu.xdelta || : # xdelta returns nonzero on success
253 echo Compressing binary deltas and linux-libre-$kver-$gnu.tar
254 rm -f linux-$kver.tar
255 if test -f linux-libre-$kver-$gnu.vcdiff; then
256 bzip2 -k9 linux-libre-$kver-$gnu.vcdiff
257 xz -k9 linux-libre-$kver-$gnu.vcdiff || :
258 lzip -k9 linux-libre-$kver-$gnu.vcdiff || :
259 rm -f linux-libre-$kver-$gnu.vcdiff
261 if test -f linux-libre-$kver-$gnu.xdelta; then
262 bzip2 -k9 linux-libre-$kver-$gnu.xdelta
263 xz -k9 linux-libre-$kver-$gnu.xdelta || :
264 lzip -k9 linux-libre-$kver-$gnu.xdelta || :
265 rm -f linux-libre-$kver-$gnu.xdelta
267 bzip2 -k9 linux-libre-$kver-$gnu.tar
268 xz -k9 linux-libre-$kver-$gnu.tar || :
269 lzip -k9 linux-libre-$kver-$gnu.tar || :
270 rm -f linux-libre-$kver-$gnu.tar
272 trap "status=$?; (exit $status); exit" 0 1 2 15
274 echo Done except for signing, feel free to interrupt
276 linux-libre-$kver-$gnu.tar.bz2 \
277 linux-libre-$kver-$gnu.tar.xz \
278 linux-libre-$kver-$gnu.tar.lz \
279 linux-libre-$kver-$gnu.vcdiff.bz2 \
280 linux-libre-$kver-$gnu.vcdiff.xz \
281 linux-libre-$kver-$gnu.vcdiff.lz \
282 linux-libre-$kver-$gnu.xdelta.bz2 \
283 linux-libre-$kver-$gnu.xdelta.xz \
284 linux-libre-$kver-$gnu.xdelta.lz \
287 gpg -a --detach-sign $f
292 echo All set, please review linux-libre-$kver-$gnu.patch