deblob-main 6.3 KB

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