mksplit.pl 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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
  19. # License along with dpkg; if not, write to the Free Software
  20. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. @ARGV == 6 || die "mksplit: bad invocation\n";
  22. ($sourcefile,$partsize,$prefix,$orgsize,$partsizeallow,$msdos) = @ARGV;
  23. sub output {
  24. $!=0; $rv= `$_[0]`; $? && die "mksplit $_[0]: $! $?\n";
  25. $rv =~ s/\n$//; $rv =~ s/\s+$//; $rv =~ s/^\s+//;
  26. $rv;
  27. }
  28. $myversion='2.1';
  29. $csum= &output("md5sum <\"$sourcefile\"");
  30. $csum =~ s/\s.*//;
  31. $package= &output("dpkg-deb --field \"$sourcefile\" Package");
  32. $version= &output("dpkg-deb --field \"$sourcefile\" Version");
  33. $revision= &output("dpkg-deb --field \"$sourcefile\" Package_Revision");
  34. $version.= "-$revision" if length($revision);
  35. $nparts=int(($orgsize+$partsize-1)/$partsize);
  36. $startat=0;
  37. $showpartnum=1;
  38. $|=1;
  39. print("Splitting package $package into $nparts parts: ");
  40. $msdos= ($msdos eq 'yes');
  41. if ($msdos) {
  42. $prefixdir= $prefix; $prefixdir =~ s:(/?)/*[^/]+$:$1:;
  43. $cleanprefix= $prefix; $cleanprefix =~ s:^.*/+::;
  44. $cleanprefix =~ y/A-Za-z0-9+/a-za-z0-9x/;
  45. $cleanprefix =~ y/a-z0-9//cd;
  46. }
  47. sub add {
  48. $data .=
  49. sprintf("%-16s%-12d0 0 100644 %-10d%c\n%s%s",
  50. $_[0], time, length($_[1]), 0140, $_[1],
  51. (length($_[1]) & 1) ? "\n" : "");
  52. }
  53. while ($startat < $orgsize) {
  54. $dsp= "$myversion\n$package\n$version\n$csum\n$orgsize\n$partsize\n".
  55. "$showpartnum/$nparts\n";
  56. defined($thispartreallen= read(STDIN,$pd,$partsize)) || die "mksplit: read: $!\n";
  57. $data= "!<arch>\n";
  58. print("$showpartnum ");
  59. &add('debian-split',$dsp);
  60. &add("data.$showpartnum",$pd);
  61. if ($thispartreallen > $partsizeallow) {
  62. die "Header is too long, making part too long. Your package name or version\n".
  63. "numbers must be extraordinarily long, or something. Giving up.\n";
  64. }
  65. if ($msdos) {
  66. $basename= "${showpartnum}of$nparts.$cleanprefix";
  67. $basename= substr($basename,0,9);
  68. $basename =~ s/^([^.]*)\.(.*)$/$2$1/;
  69. $basename= "$prefixdir$basename";
  70. } else {
  71. $basename= "$prefix.${showpartnum}of$nparts";
  72. }
  73. open(O,"> $basename.deb") || die("mksplit: open $basename.deb: $!\n");
  74. print(O $data) || die("mksplit: write $basename.deb: $!\n");
  75. close(O) || die("mksplit: close $basename.deb: $!\n");
  76. $startat += $partsize;
  77. $showpartnum++;
  78. }
  79. print("done\n");
  80. exit(0);