home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 2 / CD_Magazyn_EXEC_nr_2.iso / Linux / Archiwa / dpkg.tar.gz / dpkg-1.6.12_powerpc.nondebbin.tar / usr / lib / dpkg / mksplit
Text File  |  2000-04-07  |  3KB  |  90 lines

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