deblob-main 9.3 KB

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