All set for Linux-libre 3.0!
[releases.git] / deblob-main
1 #! /bin/sh
2
3 # Copyright (C) 2008, 2009, 2010 Alexandre Oliva <lxoliva@fsfla.org>
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18 # USA
19
20 # deblob.sh - prepare a linux-libre tarball out of a non-libre Linux
21 # tarball.  It expects the Linux release (mver, say 2.6.25) as the
22 # first argument, the libre sub-release (extra) as the second optional
23 # argument, and the patch release (sver, say .13) as an optional third
24 # argument.  mver and sver are pasted together to form kver.
25
26 # linux-$kver.tar.bz2 and deblob-$mver must exist in the current
27 # directory, and the line that sets kver and extra in deblob-$mver
28 # must match mver and extra.
29
30 # The resulting tarball is put in linux-$kver-libre$extra.tar.bz2, and
31 # an uncompressed xdelta that produces linux-$kver-libre$extra.tar out
32 # of linux-$kver.tar is created as linux-$kver-libre$extra.xdelta.
33 # This xdelta can be distributed to enable third parties to easily
34 # reconstruct the binary tarball starting out of sources downloaded
35 # from kernel.org, but without distributing non-Free Software
36 # yourself, because xdelta (unlike patches) is not reversible: the
37 # removed bits are not present in it at all.
38
39 # To enable you to check the differences between the tarballs, a patch
40 # file is generated in linux-$kver-libre$extra.patch.  This patch file
41 # contains the non-Free blobs, even though in reversed form, so its
42 # distribution is discouraged.
43
44 # At the end, the script attempts to generate a digital signature for
45 # the newly-created tarball.  This is the last thing the script does,
46 # so interrupting it at that point to skip the signing won't fail to
47 # do anything else.
48
49 # It is safe to interrupt the script at any other point.  When it gets
50 # a ^C (other than during signing), it starts cleaning up all of its
51 # temporary and output files.  If you insist, it may leave junk
52 # behind, and then it will refuse to run again before you clean it up
53 # by hand.  It takes extra care to avoid overwriting useful files.
54
55 # If deblob-$mver finds any unexpected situation, it will error out,
56 # and then deblob-main will quit.  Pass --force to deblob-main, before
57 # any other argument, for deblob-main to ignore any such situations.
58
59 case $1 in
60 --force) force=--force; shift;;
61 *) force=;;
62 esac
63
64 mver=$1 extra=$2 sver=$3
65 kver=$mver$sver libre=libre$extra
66 deblob= dir=`echo "$0" | sed 's,[^/]*$,,;s,^$,.,;s,/*$,,'`
67
68 if test ! -f linux-$kver.tar.bz2; then
69   echo linux-$kver.tar.bz2 does not exist >&2
70   exit 1
71 fi
72
73 if test -f deblob-$mver; then
74   deblob=deblob-$mver
75 elif test -f deblob; then
76   deblob=deblob
77 elif test -f $dir/deblob-$mver; then
78   cp $dir/deblob-$mver deblob
79   deblob=deblob
80 else
81   echo deblob does not exist >&2
82   exit 1
83 fi
84
85 x1="kver=$mver extra=$extra"
86 x2=`grep "^kver=[^ ]* extra=" $deblob`
87 if test "$x1" = "$x2"; then
88   :
89 else
90   echo deblob script does not match command-line arguments >&2
91   echo expected: $x1 >&2
92   echo found   : $x2 >&2
93   exit 1
94 fi
95
96 cleanup=
97
98 for f in \
99   linux-$kver-$libre.tar.bz2 \
100   linux-$kver-$libre.tar.bz2.asc \
101   linux-$kver-$libre.tar.bz2.sign \
102   linux-$kver-$libre.tar.lz \
103   linux-$kver-$libre.tar.lz.asc \
104   linux-$kver-$libre.tar.lz.sign \
105   linux-$kver.tar \
106   linux-$kver-$libre.tar \
107   linux-$kver-$libre.patch \
108   linux-$kver-$libre.log \
109   linux-$kver-$libre.vcdiff \
110   linux-$kver-$libre.vcdiff.asc \
111   linux-$kver-$libre.vcdiff.sign \
112   linux-$kver-$libre.xdelta \
113   linux-$kver-$libre.xdelta.asc \
114   linux-$kver-$libre.xdelta.sign \
115 ; do
116   if test -f $f; then
117     echo $f already exists >&2
118     exit 1
119   fi
120   cleanup="$cleanup $f"
121 done
122
123 for d in \
124   linux-$kver \
125   linux-$kver-$libre \
126   orig-linux-$kver \
127 ; do
128   if test -d $d; then
129     echo $d already exists >&2
130     exit 1
131   fi
132   cleanup="$cleanup $d"
133 done
134
135 if test -f $dir/deblob-$kver; then
136   if cmp $dir/deblob-$kver $deblob; then
137     :
138   else
139     echo $dir/deblob-$kver and $deblob are different >&2
140     exit 1
141   fi
142 fi
143
144 if test ! -f deblob-check; then
145   if test -f $dir/deblob-check; then
146     cp $dir/deblob-check deblob-check
147   fi
148 else
149   if test -f $dir/deblob-check; then
150     if cmp $dir/deblob-check deblob-check; then
151       :
152     else
153       echo $dir/deblob-check and deblob-check are different >&2
154       exit 1
155     fi
156   fi
157 fi
158
159 trap "status=$?; echo cleaning up...; rm -rf $cleanup; (exit $status); exit" 0 1 2 15
160
161 set -e
162
163 echo Uncompressing linux-$kver.tar.bz2 into linux-$kver.tar
164 rm -rf linux-$kver linux-$kver.tar
165 bunzip2 < linux-$kver.tar.bz2 > linux-$kver.tar
166
167 echo Extracting linux-$kver.tar into linux-$kver
168 tar -xf linux-$kver.tar
169 rm -rf linux-$kver-$libre linux-$kver-$libre.tar
170
171 echo Copying linux-$kver to linux-$kver-$libre
172 cp linux-$kver.tar linux-$kver-$libre.tar
173 cp -lR linux-$kver/. linux-$kver-$libre
174
175 rm -f linux-$kver-$libre.log linux-$kver-$libre.log.tmp
176 echo Deblobbing within linux-$kver-$libre, saving output to linux-$kver-$libre.log
177 # We can't just pipe deblob into tee, for then we fail to detect
178 # error conditions.  Use file renaming to tell whether we succeeded.
179 if (cd linux-$kver-$libre && /bin/sh ../$deblob $force) 2>&1; then
180   mv linux-$kver-$libre.log.tmp linux-$kver-$libre.log
181 fi | tee linux-$kver-$libre.log.tmp
182 if test ! -f linux-$kver-$libre.log; then
183   mv linux-$kver-$libre.log.tmp linux-$kver-$libre.log
184   echo $deblob failed, aborting >&2
185   exit 1
186 fi
187 rm -f linux-$kver-$libre.patch
188
189 # Do not copy these scripts for now, deblob-check regards itself as a blob.
190 # cp -p $0 $deblob deblob-check linux-$kver-$libre
191
192 echo Generating linux-$kver-$libre.patch
193 diff -druN linux-$kver linux-$kver-$libre > linux-$kver-$libre.patch || :
194
195 echo Removing removed or modified files from linux-$kver-$libre.tar
196 diff -rq linux-$kver linux-$kver-$libre |
197 sed -n "
198   s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\1/\3,p;
199   s,^Files \\(linux-$kver\\)/\\(.*\\) and \\1-$libre/\\2 differ,\\1/\\2,p;
200 " |
201 xargs tar --delete -f linux-$kver-$libre.tar
202
203 echo Adding modified or added files to linux-$kver-$libre.tar
204 rm -rf orig-linux-$kver
205 mv linux-$kver orig-linux-$kver
206 mv linux-$kver-$libre linux-$kver
207 diff -rq orig-linux-$kver linux-$kver |
208 sed -n "
209   s,^Files orig-\\(linux-$kver/.*\\) and \\1 differ,\\1,p;
210   s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\\1/\\3,p;
211 " |
212 xargs tar --append -f linux-$kver-$libre.tar
213
214 echo Wiping out extracted trees
215 rm -rf linux-$kver orig-linux-$kver
216
217 echo Creating vcdiff between linux-$kver.tar and linux-$kver-$libre.tar
218 xdelta3 -e -R -s linux-$kver.tar linux-$kver-$libre.tar linux-$kver-$libre.xdelta || : # don't fail if xdelta3 is not present
219
220 echo Creating xdelta between linux-$kver.tar and linux-$kver-$libre.tar
221 xdelta delta -0 linux-$kver.tar linux-$kver-$libre.tar linux-$kver-$libre.xdelta || : # xdelta returns nonzero on success
222
223 echo Compressing linux-$kver-$libre.tar and binary deltas
224 rm -f linux-$kver.tar
225 bzip2 -k9 linux-$kver-$libre.tar
226 lzip -k9 linux-$kver-$libre.tar
227 rm -f linux-$kver-$libre.tar
228 if test -f linux-$kver-$libre.vcdiff; then
229   bzip2 -k9 linux-$kver-$libre.vcdiff
230   lzip -k9 linux-$kver-$libre.vcdiff
231   rm -f linux-$kver-$libre.vcdiff
232 fi
233 if test -f linux-$kver-$libre.xdelta; then
234   bzip2 -k9 linux-$kver-$libre.xdelta
235   lzip -k9 linux-$kver-$libre.xdelta
236   rm -f linux-$kver-$libre.xdelta
237 fi
238
239 trap "status=$?; (exit $status); exit" 0 1 2 15
240
241 echo Done except for signing, feel free to interrupt
242 for f in \
243   linux-$kver-$libre.tar.bz2 \
244   linux-$kver-$libre.tar.lz \
245   linux-$kver-$libre.vcdiff.bz2 \
246   linux-$kver-$libre.vcdiff.lz \
247   linux-$kver-$libre.xdelta.bz2 \
248   linux-$kver-$libre.xdelta.lz \
249 ; do
250   if test -f $f; then
251     gpg -a --detach-sign $f
252     mv $f.asc $f.sign
253   fi
254 done
255
256 echo All set, please review linux-$kver-$libre.patch
257
258 exit 0