Skip to content

Commit

Permalink
shar: support directory args from find
Browse files Browse the repository at this point in the history
* DragonFly, FreeBSD, NetBSD and OpenBSD manual pages share the example of using the
  find command to provide the arguments to shar
* The output of find lists a directory before the files it contains
* Add support for this usage by writing mkdir command on output if an argument is a directory
* mkdir still runs for . directory in the following example but this is consistent with OpenBSD version
* Print directory name with "/" suffix when extracting
* Update POD

perl ~/ppt/shar $(find . -print) > ~/new.shar

cd; sh new.shar
x - ./
x - ./b/
x - ./b/false
x - ./apply
  • Loading branch information
mknos authored Oct 27, 2023
1 parent 9217d2b commit 2b63a8d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions bin/shar
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ binmode STDOUT;

my $dirty = 0;
ARGUMENT: for my $f ( @ARGV ) {
unless ($dirty) {
print '# --cut here--
# To extract, remove everything before the "cut here" line
# and run the command "sh file".
';
$dirty = 1;
}
if (-d $f) {
warn "$Program: '$f' is a directory\n";
print "echo x - $f/\n";
print "mkdir -p $f\n";
next ARGUMENT;
}
unless (open FH, '<', $f) {
Expand All @@ -45,13 +53,6 @@ ARGUMENT: for my $f ( @ARGV ) {
}
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
'
}
print "echo x - $f\n";
if (-B $f) {
my $mode = (stat $f)[2];
Expand Down Expand Up @@ -91,7 +92,8 @@ B<shar> reads input files and writes a shell archive to standard output.
The shell archive is a shell script, and executing it will recreate the I<files>.
File permissions are not preserved for archived files.
Extracted files are created with the default file permissions and owner.
Directories are I<not> recreated.
Directories will be recreated, but directory arguments must be provided before
the files they contain.
=head1 SEE ALSO
Expand Down

0 comments on commit 2b63a8d

Please sign in to comment.