home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume3 / perlshar / shar.p
Text File  |  1989-02-03  |  1KB  |  32 lines

  1. print "#! /bin/sh
  2. # This is a shell archive, meaning:
  3. # 1. Remove everything above the #! /bin/sh line.
  4. # 2. Save the resulting text in a file.
  5. # 3. Execute the file with /bin/sh (not csh) to create the files:
  6. #    ",join("\n#\t",@ARGV),"\n#\n";
  7.  
  8. while ($arg = shift) {
  9.   @dirs = split(/\//,$arg);
  10.   for ($i=0; $i < $#dirs; $i++) {
  11.     $dir .= $dirs[$i];
  12.     if ($dir && !$done{$dir}) {
  13.       print "if test ! -d '$dir'\nthen\n\tmkdir '$dir'\nfi\n";
  14.       $done{$dir} = 1;
  15.     }
  16.     $dir .= "/";
  17.   }
  18.   @stat = stat($arg);
  19.   $size = $stat[7];
  20.   open(file, $arg);
  21.   print "if test -f '$arg'\nthen\n";
  22.   print "\techo shar: will not over-write existing file \"'$arg'\"\n";
  23.   print "else\n";
  24.   print "\techo x - '$arg'\n";
  25.   print "\tsed 's/^X//' >'$arg' << 'SHAR_EOF'\n";
  26.   while (<file>) { print "X",$_; }
  27.   print "SHAR_EOF\n";
  28.   print "if test $size -ne \"`wc -c < '$arg'`\"\nthen\n";
  29.   print "\techo shar: error transmitting \"'$arg'\" '(should have been $size characters)'\nfi\nfi\n";
  30. }
  31. print "echo Done\nexit 0\n";
  32.