#! /usr/bin/perl
# public domain code by salzr@certo.com
# (formerly rsalz@osf.org, rsalz@bbn.com, mirror!rs)
require 'getopts.pl';
sub
Usage
{
print STDERR "@_.\nUsage: $av0 files...\n";
exit(1);
}
binmode STDOUT;
# Parse JCL.
$av0 = $0;
$av0 =~ s@.*/@@;
&Getopts("") || &Usage("Usage error");
# Do work.
$dirty = 0;
ARGUMENT: foreach $f ( @ARGV ) {
if ( ! open(FH, $f) ) {
warn "$av0: can't open $f, $!\n";
next ARGUMENT;
}
binmode FH;
if ( $dirty++ == 0 ) {
print '# --cut here--
#! /bin/sh
# To unshar, remove everything before the "cut here" line
# and feed the result to /bin/sh
'
}
if (-B $f) {
$mode = (stat $f)[2];
$mode = (join '', 0, ($mode&0700)>>6, ($mode&0070)>>3, ($mode&0007));
print "sed -e 's/^X//' | uudecode <<'FUNKY_STUFF'\n";
print "begin $mode $f\n";
print pack 'u', $block while read FH, $block, 45;
print "end\n";
print "FUNKY_STUFF\n";
} else {
print "sed -e 's/^X//' >$f <<'FUNKY_STUFF'\n";
print 'X', $_ while ( <FH> );
print "FUNKY_STUFF\n";
}
close(FH);
}
&Usage("No input files") unless $dirty;
exit(0);
__END__
=head1 NAME
shar - create a shell archive of files
=head1 SYNOPSIS
B<shar> file [files...]
=head1 DESCRIPTION
B<shar> creates a shell archive of the I<files> on the command line. The shell
archive is a shell script, and executing it will recreate the I<files>.
Directories are I<not> recreated.
=head1 SEE ALSO
B<unshar>
=head1 AUTHOR
Rich Salz | salzr@certo.com | rsalz@osf.org | rsalz@bbn.com
=head1 COPYRIGHT
This code is released to the public domain.
=cut