Initial import of linux-libre deblob scripts from https://www.fsfla.org/svn/fsfla...
[librecmc/linux-deblob.git] / 2.6.24-libre / deblob-main
1 #! /bin/sh
2
3 # Copyright (C) 2008 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 (kver) as the first argument,
22 # and the libre sub-release (extra) as the second optional argument.
23
24 # linux-$kver.tar.bz2 and deblob-$kver must exist in the current
25 # directory, and the line that sets kver and extra in deblob-$kver
26 # must match the command-line arguments.  
27
28 # The resulting tarball is put in linux-$kver-libre$extra.tar.bz2, and
29 # an uncompressed xdelta that produces linux-$kver-libre$extra.tar out
30 # of linux-$kver.tar is created as linux-$kver-libre$extra.xdelta.
31 # This xdelta can be distributed to enable third parties to easily
32 # reconstruct the binary tarball starting out of sources downloaded
33 # from kernel.org, but without distributing non-Free Software
34 # yourself, because xdelta (unlike patches) is not reversible: the
35 # removed bits are not present in it at all.
36
37 # To enable you to check the differences between the tarballs, a patch
38 # file is generated in linux-$kver-libre$extra.patch.  This patch file
39 # contains the non-Free blobs, even though in reversed form, so its
40 # distribution is discouraged.
41
42 # At the end, the script attempts to generate a digital signature for
43 # the newly-created tarball.  This is the last thing the script does,
44 # so interrupting it at that point to skip the signing won't fail to
45 # do anything else.  
46
47 # It is safe to interrupt the script at any other point.  When it gets
48 # a ^C (other than during signing), it starts cleaning up all of its
49 # temporary and output files.  If you insist, it may leave junk
50 # behind, and then it will refuse to run again before you clean it up
51 # by hand.  It takes extra care to avoid overwriting useful files.
52
53 kver=$1 extra=$2 libre=libre$extra
54 deblob= dir=`echo $0 | sed 's,/[^/]*$,,'`
55
56 if test ! -f linux-$kver.tar.bz2; then
57   echo linux-$kver.tar.bz2 does not exist >&2
58   exit 1
59 fi
60
61 if test -f deblob-$kver; then
62   deblob=deblob-$kver
63 elif test -f deblob; then
64   deblob=deblob
65 elif test -f $dir/deblob-$kver; then
66   cp $dir/deblob-$kver deblob
67   deblob=deblob
68 else
69   echo deblob does not exist >&2
70   exit 1
71 fi
72
73 x1="kver=$kver extra=$extra"
74 x2=`grep \"^$x1$\" $deblob`
75 if test "$x1" != "$x2"; then
76   :
77 else
78   echo deblob script does not match command-line arguments >&2
79   echo expected: $x1 >&2
80   echo found   : $x2 >&2
81   exit 1
82 fi
83
84 if test -f linux-$kver-$libre.tar.bz2; then
85   echo linux-$kver-$libre.tar.bz2 already exists >&2
86   exit 1
87 fi
88
89 if test -f linux-$kver.tar; then
90   echo linux-$kver.tar already exists >&2
91   exit 1
92 fi
93
94 if test -f linux-$kver-$libre.tar; then
95   echo linux-$kver-$libre.tar already exists >&2
96   exit 1
97 fi
98
99 if test -f linux-$kver-$libre.patch; then
100   echo linux-$kver-$libre.patch already exists >&2
101   exit 1
102 fi
103
104 if test -f linux-$kver-$libre.xdelta; then
105   echo linux-$kver-$libre.xdelta already exists >&2
106   exit 1
107 fi
108
109 if test -d linux-$kver; then
110   echo linux-$kver already exists >&2
111   exit 1
112 fi
113
114 if test -d linux-$kver-$libre; then
115   echo linux-$kver-$libre already exists >&2
116   exit 1
117 fi
118
119 if test -d orig-linux-$kver; then
120   echo orig-linux-$kver already exists >&2
121   exit 1
122 fi
123
124 if test -f $dir/deblob-$kver; then
125   if cmp $dir/deblob-$kver $deblob; then
126     :
127   else
128     echo $dir/deblob-$kver and $deblob are different >&2
129     exit 1
130   fi
131 fi
132
133 if test ! -f deblob-check; then
134   if test -f $dir/deblob-check; then
135     cp $dir/deblob-check deblob-check
136   fi
137 else
138   if test -f $dir/deblob-check; then
139     if cmp $dir/deblob-check deblob-check; then
140       :
141     else
142       echo $dir/deblob-check and deblob-check are different >&2
143       exit 1
144     fi
145   fi
146 fi
147
148 trap "status=$?; echo cleaning up...; rm -rf orig-linux-$kver linux-$kver linux-$kver-$libre linux-$kver.tar linux-$kver-$libre.tar linux-$kver-$libre.tar.bz2 linux-$kver-$libre.patch linux-$kver-$libre.xdelta; (exit $status); exit" 0 1 2 15
149
150 echo Uncompressing linux-$kver.tar.bz2 into linux-$kver.tar
151 rm -rf linux-$kver linux-$kver.tar
152 bunzip2 < linux-$kver.tar.bz2 > linux-$kver.tar
153
154 echo Extracing linux-$kver.tar into linux-$kver
155 tar -xf linux-$kver.tar
156 rm -rf linux-$kver-$libre linux-$kver-$libre.tar
157
158 echo Copying linux-$kver to linux-$kver-$libre.tar
159 cp linux-$kver.tar linux-$kver-$libre.tar
160 cp -lR linux-$kver/. linux-$kver-$libre
161
162 echo Deblobbing within linux-$kver-$libre
163 (cd linux-$kver-$libre && /bin/sh ../$deblob)
164 rm -f linux-$kver-$libre.patch
165
166 echo Generating linux-$kver-$libre.patch
167 diff -druN linux-$kver linux-$kver-$libre > linux-$kver-$libre.patch
168
169 echo Removing removed or modified files from linux-$kver-$libre.tar
170 diff -rq linux-$kver linux-$kver-$libre |
171 sed -n "
172   s,^Only in \(linux-$kver/.*\): \(.*\),\1/\2,p;
173   s,^Files \(linux-$kver/.*\) and libre-\1 differ,\1,p;
174 " |
175 xargs tar --delete -f linux-$kver-$libre.tar
176
177 echo Adding modified or added files to linux-$kver-$libre.tar
178 rm -rf orig-linux-$kver
179 mv linux-$kver orig-linux-$kver
180 mv linux-$kver-$libre linux-$kver
181 diff -rq orig-linux-$kver linux-$kver |
182 sed -n "
183   s,^Files orig-\(linux-$kver/.*\) and \1 differ,\1,p;
184   s,^Only in \(linux-$kver/.*\): \(.*\),\1/\2,p;
185 " |
186 xargs tar --append -f linux-$kver-$libre.tar
187
188 echo Wiping out extracted trees
189 rm -rf linux-$kver orig-linux-$kver
190
191 echo Creating xdelta between linux-$kver.tar and linux-$kver-$libre.tar
192 xdelta delta -0 linux-$kver.tar linux-$kver-$libre.tar linux-$kver-$libre.xdelta
193
194 echo Compressing linux-$kver-$libre.tar
195 rm -f linux-$kver.tar
196 bzip2 -9 linux-$kver-$libre.tar
197
198 trap "status=$?; (exit $status); exit" 0 1 2 15
199
200 echo Done except for signing, feel free to interrupt
201 gpg -a --detach-sign linux-$kver-$libre.tar.bz2
202 mv linux-$kver-$libre.tar.bz2.asc linux-$kver-$libre.tar.bz2.sign
203
204 echo All set, please review linux-$kver-$libre.patch
205
206 exit 0