1#! /usr/bin/perl 2# 3# ex:ts=8 sw=4: 4# $OpenBSD: minitar,v 1.1 2005/07/20 15:33:50 espie Exp $ 5# 6# Copyright (c) 2005 Marc Espie <espie@openbsd.org> 7# 8# Permission to use, copy, modify, and distribute this software for any 9# purpose with or without fee is hereby granted, provided that the above 10# copyright notice and this permission notice appear in all copies. 11# 12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 20use OpenBSD::Ustar; 21use strict; 22 23my $mode = shift; 24my $arcname; 25my ($what, $verbose); 26 27sub create 28{ 29 my $arcname = shift; 30 open my $out, '>', $arcname or die "bad archive $arcname: $!\n"; 31 my $arc = OpenBSD::Ustar->new($out, '.'); 32 for my $f (@_) { 33 my $e = $arc->prepare($f); 34 $e->write(); 35 } 36 $arc->close(); 37} 38 39sub extract 40{ 41 my $arcname = shift; 42 open my $in, '<', $arcname or die "bad archive $arcname: $!\n"; 43 my $arc = OpenBSD::Ustar->new($in); 44 while (my $e = $arc->next()) { 45 $e->create(); 46 } 47 $arc->close(); 48} 49 50sub test 51{ 52 my $arcname = shift; 53 open my $in, '<', $arcname or die "bad archive $arcname: $!\n"; 54 my $arc = OpenBSD::Ustar->new($in); 55 while (my $e = $arc->next()) { 56 print $e->{name}, "\n"; 57 } 58 $arc->close(); 59} 60 61if ($mode =~ s/c//) { 62 $what = \&create; 63} elsif ($mode =~ s/t//) { 64 $what = \&test; 65} elsif ($mode =~ s/x//) { 66 $what = \&extract; 67} 68if ($mode =~ s/f//) { 69 $arcname = shift; 70} 71if ($mode =~ s/v//) { 72 $verbose = 1; 73} 74 75if ($mode ne '') { 76 die "Bad mode\n"; 77} 78 79if (!defined $what) { 80 die "Bad mode\n"; 81} 82 83&$what($arcname, @ARGV); 84