deblob-main 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #! /bin/sh
  2. # Copyright (C) 2008, 2009 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.sh - prepare a linux-libre tarball out of a non-libre Linux
  16. # tarball. It expects the Linux release (mver, say 2.6.25) as the
  17. # first 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. # To enable you to check the differences between the tarballs, a patch
  32. # file is generated in linux-$kver-libre$extra.patch. This patch file
  33. # contains the non-Free blobs, even though in reversed form, so its
  34. # distribution is discouraged.
  35. # At the end, the script attempts to generate a digital signature for
  36. # the newly-created tarball. This is the last thing the script does,
  37. # so interrupting it at that point to skip the signing won't fail to
  38. # do anything else.
  39. # It is safe to interrupt the script at any other point. When it gets
  40. # a ^C (other than during signing), it starts cleaning up all of its
  41. # temporary and output files. If you insist, it may leave junk
  42. # behind, and then it will refuse to run again before you clean it up
  43. # by hand. It takes extra care to avoid overwriting useful files.
  44. # If deblob-$mver finds any unexpected situation, it will error out,
  45. # and then deblob-main will quit. Pass --force to deblob-main, before
  46. # any other argument, for deblob-main to ignore any such situations.
  47. case $1 in
  48. --force) force=--force; shift;;
  49. *) force=;;
  50. esac
  51. mver=$1 extra=$2 sver=$3
  52. kver=$mver$sver libre=libre$extra
  53. deblob= dir=`echo "$0" | sed 's,[^/]*$,,;s,^$,.,;s,/*$,,'`
  54. if test ! -f linux-$kver.tar.bz2; then
  55. echo linux-$kver.tar.bz2 does not exist >&2
  56. exit 1
  57. fi
  58. if test -f deblob-$mver; then
  59. deblob=deblob-$mver
  60. elif test -f deblob; then
  61. deblob=deblob
  62. elif test -f $dir/deblob-$mver; then
  63. cp $dir/deblob-$mver deblob
  64. deblob=deblob
  65. else
  66. echo deblob does not exist >&2
  67. exit 1
  68. fi
  69. x1="kver=$mver extra=$extra"
  70. x2=`grep "^kver=[^ ]* extra=" $deblob`
  71. if test "$x1" = "$x2"; then
  72. :
  73. else
  74. echo deblob script does not match command-line arguments >&2
  75. echo expected: $x1 >&2
  76. echo found : $x2 >&2
  77. exit 1
  78. fi
  79. if test -f linux-$kver-$libre.tar.bz2; then
  80. echo linux-$kver-$libre.tar.bz2 already exists >&2
  81. exit 1
  82. fi
  83. if test -f linux-$kver.tar; then
  84. echo linux-$kver.tar already exists >&2
  85. exit 1
  86. fi
  87. if test -f linux-$kver-$libre.tar; then
  88. echo linux-$kver-$libre.tar already exists >&2
  89. exit 1
  90. fi
  91. if test -f linux-$kver-$libre.patch; then
  92. echo linux-$kver-$libre.patch already exists >&2
  93. exit 1
  94. fi
  95. if test -f linux-$kver-$libre.log; then
  96. echo linux-$kver-$libre.log already exists >&2
  97. exit 1
  98. fi
  99. if test -f linux-$kver-$libre.xdelta; then
  100. echo linux-$kver-$libre.xdelta already exists >&2
  101. exit 1
  102. fi
  103. if test -d linux-$kver; then
  104. echo linux-$kver already exists >&2
  105. exit 1
  106. fi
  107. if test -d linux-$kver-$libre; then
  108. echo linux-$kver-$libre already exists >&2
  109. exit 1
  110. fi
  111. if test -d orig-linux-$kver; then
  112. echo orig-linux-$kver already exists >&2
  113. exit 1
  114. fi
  115. if test -f $dir/deblob-$kver; then
  116. if cmp $dir/deblob-$kver $deblob; then
  117. :
  118. else
  119. echo $dir/deblob-$kver and $deblob are different >&2
  120. exit 1
  121. fi
  122. fi
  123. if test ! -f deblob-check; then
  124. if test -f $dir/deblob-check; then
  125. cp $dir/deblob-check deblob-check
  126. fi
  127. else
  128. if test -f $dir/deblob-check; then
  129. if cmp $dir/deblob-check deblob-check; then
  130. :
  131. else
  132. echo $dir/deblob-check and deblob-check are different >&2
  133. exit 1
  134. fi
  135. fi
  136. fi
  137. 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
  138. set -e
  139. echo Uncompressing linux-$kver.tar.bz2 into linux-$kver.tar
  140. rm -rf linux-$kver linux-$kver.tar
  141. bunzip2 < linux-$kver.tar.bz2 > linux-$kver.tar
  142. echo Extracing linux-$kver.tar into linux-$kver
  143. tar -xf linux-$kver.tar
  144. rm -rf linux-$kver-$libre linux-$kver-$libre.tar
  145. echo Copying linux-$kver to linux-$kver-$libre
  146. cp linux-$kver.tar linux-$kver-$libre.tar
  147. cp -lR linux-$kver/. linux-$kver-$libre
  148. rm -f linux-$kver-$libre.log linux-$kver-$libre.log.tmp
  149. echo Deblobbing within linux-$kver-$libre, saving output to linux-$kver-$libre.log
  150. # We can't just pipe deblob into tee, for then we fail to detect
  151. # error conditions. Use file renaming to tell whether we succeeded.
  152. if (cd linux-$kver-$libre && /bin/sh ../$deblob $force) 2>&1; then
  153. mv linux-$kver-$libre.log.tmp linux-$kver-$libre.log
  154. fi | tee linux-$kver-$libre.log.tmp
  155. if test ! -f linux-$kver-$libre.log; then
  156. mv linux-$kver-$libre.log.tmp linux-$kver-$libre.log
  157. echo $deblob failed, aborting >&2
  158. exit 1
  159. fi
  160. rm -f linux-$kver-$libre.patch
  161. # Do not copy these scripts for now, deblob-check regards itself as a blob.
  162. # cp -p $0 $deblob deblob-check linux-$kver-$libre
  163. echo Generating linux-$kver-$libre.patch
  164. diff -druN linux-$kver linux-$kver-$libre > linux-$kver-$libre.patch || :
  165. echo Removing removed or modified files from linux-$kver-$libre.tar
  166. diff -rq linux-$kver linux-$kver-$libre |
  167. sed -n "
  168. s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\1/\3,p;
  169. s,^Files \\(linux-$kver\\)/\\(.*\\) and \\1-$libre/\\2 differ,\\1/\\2,p;
  170. " |
  171. xargs tar --delete -f linux-$kver-$libre.tar
  172. echo Adding modified or added files to linux-$kver-$libre.tar
  173. rm -rf orig-linux-$kver
  174. mv linux-$kver orig-linux-$kver
  175. mv linux-$kver-$libre linux-$kver
  176. diff -rq orig-linux-$kver linux-$kver |
  177. sed -n "
  178. s,^Files orig-\\(linux-$kver/.*\\) and \\1 differ,\\1,p;
  179. s,^Only in \\(linux-$kver\\(/.*\\)\\?\\): \\(.*\\),\\1/\\3,p;
  180. " |
  181. xargs tar --append -f linux-$kver-$libre.tar
  182. echo Wiping out extracted trees
  183. rm -rf linux-$kver orig-linux-$kver
  184. echo Creating xdelta between linux-$kver.tar and linux-$kver-$libre.tar
  185. xdelta delta -0 linux-$kver.tar linux-$kver-$libre.tar linux-$kver-$libre.xdelta || : # xdelta returns nonzero on success
  186. echo Compressing linux-$kver-$libre.tar and linux-$kver-$libre.xdelta
  187. rm -f linux-$kver.tar
  188. bzip2 -9 linux-$kver-$libre.tar
  189. if test -f linux-$kver-$libre.xdelta; then
  190. bzip2 -9 linux-$kver-$libre.xdelta
  191. fi
  192. trap "status=$?; (exit $status); exit" 0 1 2 15
  193. echo Done except for signing, feel free to interrupt
  194. gpg -a --detach-sign linux-$kver-$libre.tar.bz2
  195. mv linux-$kver-$libre.tar.bz2.asc linux-$kver-$libre.tar.bz2.sign
  196. if test -f linux-$kver-$libre.xdelta.bz2; then
  197. gpg -a --detach-sign linux-$kver-$libre.xdelta.bz2
  198. mv linux-$kver-$libre.xdelta.bz2.asc linux-$kver-$libre.xdelta.bz2.sign
  199. fi
  200. echo All set, please review linux-$kver-$libre.patch
  201. exit 0