#!/usr/bin/perl
$ID = q$Id: mkpackage 1985 2003-08-13 22:25:12Z eagle $;
#
# mkpackage -- Wrapper around tar to create a WebAuth module package.
#
# This is a small and fairly simple wrapper around tar to create a module
# package.  It takes the root of the Apache tree, the name of the tar file to
# create, and then a series of file specifications (possibly with wildcards)
# of the files inside the Apache tree to put into the tar file.  It's used for
# generating binary packages of the WebAuth modules.

require 5.005;

use strict;
use vars qw($ID);

use Cwd qw(getcwd);

die "Usage: mkpackage <apache-root> <tar-name> <files> [<files> ...]\n"
    unless (@ARGV >= 3);
my $root = shift;
my $tarname = shift;
my $apachedir = $root;
$apachedir =~ s%/+$%%;
if (($apachedir =~ tr%/%/%) > 1 || $apachedir !~ m%^/%) {
    $apachedir =~ s%^.*/%%;
} else {
    $apachedir =~ s%^/%%;
}
my @files = map { "$apachedir/$_" } @ARGV;
$tarname = getcwd . '/' . $tarname;
chdir "$root/.." or die "$0: cannot chdir to $root: $!\n";
system ("tar --create --owner=0 --group=0 --file='$tarname' @files") == 0
    or die "$0: tar exited with status ", ($? >> 8), "\n";
system ('gzip', '-9', $tarname) == 0
    or die "$0: gzip exited with status ", ($? >> 8), "\n";
exit 0;

