mksplit.pl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/perl --
  2. # This script is only supposed to be called by dpkg-split.
  3. # Its arguments are:
  4. # <sourcefile> <partsize> <prefix> <totalsize> <partsizeallow> <msdostruncyesno>
  5. # Stdin is also redirected from the source archive by dpkg-split.
  6. # Copyright (C) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  7. #
  8. # This is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as
  10. # published by the Free Software Foundation; either version 2,
  11. # or (at your option) any later version.
  12. #
  13. # This is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. @ARGV == 6 || die "mksplit: bad invocation\n";
  21. ($sourcefile,$partsize,$prefix,$orgsize,$partsizeallow,$msdos) = @ARGV;
  22. sub output {
  23. $!=0; $rv= `$_[0]`; $? && die "mksplit $_[0]: $! $?\n";
  24. $rv =~ s/\n$//; $rv =~ s/\s+$//; $rv =~ s/^\s+//;
  25. $rv;
  26. }
  27. $myversion='2.1';
  28. $csum= &output("md5sum <\"$sourcefile\"");
  29. $csum =~ s/\s.*//;
  30. $package= &output("dpkg-deb --field \"$sourcefile\" Package");
  31. $version= &output("dpkg-deb --field \"$sourcefile\" Version");
  32. $revision= &output("dpkg-deb --field \"$sourcefile\" Package_Revision");
  33. $version.= "-$revision" if length($revision);
  34. $nparts=int(($orgsize+$partsize-1)/$partsize);
  35. $startat=0;
  36. $showpartnum=1;
  37. $|=1;
  38. print("Splitting package $package into $nparts parts: ");
  39. $msdos= ($msdos eq 'yes');
  40. if ($msdos) {
  41. $prefixdir= $prefix; $prefixdir =~ s:(/?)/*[^/]+$:$1:;
  42. $cleanprefix= $prefix; $cleanprefix =~ s:^.*/+::;
  43. $cleanprefix =~ y/A-Za-z0-9+/a-za-z0-9x/;
  44. $cleanprefix =~ y/a-z0-9//cd;
  45. }
  46. sub add {
  47. $data .=
  48. sprintf("%-16s%-12d0 0 100644 %-10d%c\n%s%s",
  49. $_[0], time, length($_[1]), 0140, $_[1],
  50. (length($_[1]) & 1) ? "\n" : "");
  51. }
  52. while ($startat < $orgsize) {
  53. $dsp= "$myversion\n$package\n$version\n$csum\n$orgsize\n$partsize\n".
  54. "$showpartnum/$nparts\n";
  55. defined($thispartreallen= read(STDIN,$pd,$partsize)) || die "mksplit: read: $!\n";
  56. $data= "!<arch>\n";
  57. print("$showpartnum ");
  58. &add('debian-split',$dsp);
  59. &add("data.$showpartnum",$pd);
  60. if ($thispartreallen > $partsizeallow) {
  61. die "Header is too long, making part too long. Your package name or version\n".
  62. "numbers must be extraordinarily long, or something. Giving up.\n";
  63. }
  64. if ($msdos) {
  65. $basename= "${showpartnum}of$nparts.$cleanprefix";
  66. $basename= substr($basename,0,9);
  67. $basename =~ s/^([^.]*)\.(.*)$/$2$1/;
  68. $basename= "$prefixdir$basename";
  69. } else {
  70. $basename= "$prefix.${showpartnum}of$nparts";
  71. }
  72. open(O,"> $basename.deb") || die("mksplit: open $basename.deb: $!\n");
  73. print(O $data) || die("mksplit: write $basename.deb: $!\n");
  74. close(O) || die("mksplit: close $basename.deb: $!\n");
  75. $startat += $partsize;
  76. $showpartnum++;
  77. }
  78. print("done\n");
  79. exit(0);