1
0

deblob-main 9.9 KB

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