Add 3.16.85-gnu from https://fsfla.org/svn/fsfla/software/linux-libre/releases/tags/
[librecmc/linux-deblob.git] / 2.6.22-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 (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 mver=$1 extra=$2 sver=$3
56 kver=$mver$sver libre=libre$extra
57 deblob= dir=`echo $0 | sed 's,/[^/]*$,,'`
58
59 if test ! -f linux-$kver.tar.bz2; then
60   echo linux-$kver.tar.bz2 does not exist >&2
61   exit 1
62 fi
63
64 if test -f deblob-$mver; then
65   deblob=deblob-$mver
66 elif test -f deblob; then
67   deblob=deblob
68 elif test -f $dir/deblob-$mver; then
69   cp $dir/deblob-$mver deblob
70   deblob=deblob
71 else
72   echo deblob does not exist >&2
73   exit 1
74 fi
75
76 x1="kver=$mver extra=$extra"
77 x2=`grep "^kver=[^ ]* extra=[0-9]*$" $deblob`
78 if test "$x1" = "$x2"; then
79   :
80 else
81   echo deblob script does not match command-line arguments >&2
82   echo expected: $x1 >&2
83   echo found   : $x2 >&2
84   exit 1
85 fi
86
87 if test -f linux-$kver-$libre.tar.bz2; then
88   echo linux-$kver-$libre.tar.bz2 already exists >&2
89   exit 1
90 fi
91
92 if test -f linux-$kver.tar; then
93   echo linux-$kver.tar already exists >&2
94   exit 1
95 fi
96
97 if test -f linux-$kver-$libre.tar; then
98   echo linux-$kver-$libre.tar already exists >&2
99   exit 1
100 fi
101
102 if test -f linux-$kver-$libre.patch; then
103   echo linux-$kver-$libre.patch already exists >&2
104   exit 1
105 fi
106
107 if test -f linux-$kver-$libre.xdelta; then
108   echo linux-$kver-$libre.xdelta already exists >&2
109   exit 1
110 fi
111
112 if test -d linux-$kver; then
113   echo linux-$kver already exists >&2
114   exit 1
115 fi
116
117 if test -d linux-$kver-$libre; then
118   echo linux-$kver-$libre already exists >&2
119   exit 1
120 fi
121
122 if test -d orig-linux-$kver; then
123   echo orig-linux-$kver already exists >&2
124   exit 1
125 fi
126
127 if test -f $dir/deblob-$kver; then
128   if cmp $dir/deblob-$kver $deblob; then
129     :
130   else
131     echo $dir/deblob-$kver and $deblob are different >&2
132     exit 1
133   fi
134 fi
135
136 if test ! -f deblob-check; then
137   if test -f $dir/deblob-check; then
138     cp $dir/deblob-check deblob-check
139   fi
140 else
141   if test -f $dir/deblob-check; then
142     if cmp $dir/deblob-check deblob-check; then
143       :
144     else
145       echo $dir/deblob-check and deblob-check are different >&2
146       exit 1
147     fi
148   fi
149 fi
150
151 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
152
153 set -e
154
155 echo Uncompressing linux-$kver.tar.bz2 into linux-$kver.tar
156 rm -rf linux-$kver linux-$kver.tar
157 bunzip2 < linux-$kver.tar.bz2 > linux-$kver.tar
158
159 echo Extracing linux-$kver.tar into linux-$kver
160 tar -xf linux-$kver.tar
161 rm -rf linux-$kver-$libre linux-$kver-$libre.tar
162
163 echo Copying linux-$kver to linux-$kver-$libre
164 cp linux-$kver.tar linux-$kver-$libre.tar
165 cp -lR linux-$kver/. linux-$kver-$libre
166
167 echo Deblobbing within linux-$kver-$libre
168 (cd linux-$kver-$libre && /bin/sh ../$deblob) || exit 1
169 rm -f linux-$kver-$libre.patch
170
171 # Do not copy these scripts for now, deblob-check regards itself as a blog.
172 # cp -p $0 $deblob deblob-check linux-$kver-$libre
173
174 echo Generating linux-$kver-$libre.patch
175 diff -druN linux-$kver linux-$kver-$libre > linux-$kver-$libre.patch || :
176
177 echo Removing removed or modified files from linux-$kver-$libre.tar
178 diff -rq linux-$kver linux-$kver-$libre |
179 sed -n "
180   s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\1/\3,p;
181   s,^Files \\(linux-$kver\\)/\\(.*\\) and \\1-$libre/\\2 differ,\\1/\\2,p;
182 " |
183 xargs tar --delete -f linux-$kver-$libre.tar
184
185 echo Adding modified or added files to linux-$kver-$libre.tar
186 rm -rf orig-linux-$kver
187 mv linux-$kver orig-linux-$kver
188 mv linux-$kver-$libre linux-$kver
189 diff -rq orig-linux-$kver linux-$kver |
190 sed -n "
191   s,^Files orig-\\(linux-$kver/.*\\) and \\1 differ,\\1,p;
192   s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\\1/\\3,p;
193 " |
194 xargs tar --append -f linux-$kver-$libre.tar
195
196 echo Wiping out extracted trees
197 rm -rf linux-$kver orig-linux-$kver
198
199 echo Creating xdelta between linux-$kver.tar and linux-$kver-$libre.tar
200 xdelta delta -0 linux-$kver.tar linux-$kver-$libre.tar linux-$kver-$libre.xdelta || :
201
202 echo Compressing linux-$kver-$libre.tar and linux-$kver-$libre.xdelta
203 rm -f linux-$kver.tar
204 bzip2 -9 linux-$kver-$libre.tar linux-$kver-$libre.xdelta
205
206 trap "status=$?; (exit $status); exit" 0 1 2 15
207
208 echo Done except for signing, feel free to interrupt
209 gpg -a --detach-sign linux-$kver-$libre.tar.bz2
210 mv linux-$kver-$libre.tar.bz2.asc linux-$kver-$libre.tar.bz2.sign
211
212 gpg -a --detach-sign linux-$kver-$libre.xdelta.bz2
213 mv linux-$kver-$libre.xdelta.bz2.asc linux-$kver-$libre.xdelta.bz2.sign
214
215 echo All set, please review linux-$kver-$libre.patch
216
217 exit 0