1999-09-08 03:30:45 +04:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Netscape Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/NPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is Mozilla Communicator client code, released
|
|
|
|
# March 31, 1998.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape
|
|
|
|
# Communications Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Jonathan Granrose (granrose@netscape.com)
|
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
# pkgcp.pl -
|
|
|
|
#
|
|
|
|
# Parse a package file and copy the specified files for a component
|
|
|
|
# from the given source directory into the given destination directory
|
|
|
|
# for packaging by the install builder.
|
|
|
|
#
|
1999-09-28 03:02:06 +04:00
|
|
|
# Todo:
|
|
|
|
# - port to MacPerl
|
|
|
|
# - change warn()s to die()s to enforce updating package files.
|
|
|
|
# - change var names to standard form
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
# load modules
|
1999-09-08 03:30:45 +04:00
|
|
|
use Cwd;
|
|
|
|
use File::Basename;
|
|
|
|
use File::Copy;
|
|
|
|
use File::Find;
|
|
|
|
use File::Path;
|
1999-09-10 02:24:51 +04:00
|
|
|
use File::stat;
|
1999-09-09 04:25:25 +04:00
|
|
|
use Getopt::Long;
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
# initialize variables
|
1999-09-08 03:30:45 +04:00
|
|
|
$saved_cwd = cwd();
|
1999-09-09 23:22:34 +04:00
|
|
|
$component = ""; # current component being copied
|
2000-04-29 00:32:23 +04:00
|
|
|
%components = (); # list of components to copy
|
1999-09-09 23:22:34 +04:00
|
|
|
$PD = ""; # file Path Delimiter ( /, \, or :)
|
|
|
|
$altdest = ""; # alternate file destination
|
1999-09-15 04:27:37 +04:00
|
|
|
$line = ""; # line being processed
|
1999-09-28 03:02:06 +04:00
|
|
|
$srcdir = ""; # root directory being copied from
|
|
|
|
$destdir = ""; # root directory being copied to
|
1999-09-09 23:22:34 +04:00
|
|
|
$package = ""; # file listing files to copy
|
1999-09-15 04:27:37 +04:00
|
|
|
$os = ""; # os type (MacOS, MSDOS, Unix)
|
1999-09-09 23:22:34 +04:00
|
|
|
$verbose = 0; # shorthand for --debug 1
|
|
|
|
$lineno = 0; # line # of package file for error text
|
|
|
|
$debug = 0; # controls amount of debug output
|
1999-09-28 03:02:06 +04:00
|
|
|
$dirflag = 0; # flag: are we copying a directory?
|
1999-09-09 23:22:34 +04:00
|
|
|
$help = 0; # flag: if set, print usage
|
1999-09-09 04:25:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
# get command line options
|
2000-04-29 00:32:23 +04:00
|
|
|
$return = GetOptions(
|
|
|
|
"source|s=s", \$srcdir,
|
1999-09-15 04:27:37 +04:00
|
|
|
"destination|d=s", \$destdir,
|
1999-09-09 04:25:25 +04:00
|
|
|
"file|f=s", \$package,
|
|
|
|
"os|o=s", \$os,
|
2000-04-29 00:32:23 +04:00
|
|
|
"component|c=s", \@components,
|
1999-09-09 04:25:25 +04:00
|
|
|
"help|h", \$help,
|
|
|
|
"debug=i", \$debug,
|
1999-09-09 23:22:34 +04:00
|
|
|
"verbose|v", \$verbose,
|
2001-01-23 18:53:12 +03:00
|
|
|
"flat|l", \$flat,
|
1999-09-09 04:25:25 +04:00
|
|
|
"<>", \&do_badargument
|
|
|
|
);
|
|
|
|
|
|
|
|
# set debug level
|
1999-09-09 23:22:34 +04:00
|
|
|
if ($verbose && !($debug)) {
|
|
|
|
$debug = 1;
|
|
|
|
} elsif ($debug != 0) {
|
|
|
|
$debug = abs ($debug);
|
|
|
|
($debug >= 2) && print "debug level: $debug\n";
|
1999-09-09 04:25:25 +04:00
|
|
|
}
|
|
|
|
|
1999-09-09 23:22:34 +04:00
|
|
|
# check usage
|
1999-09-09 04:25:25 +04:00
|
|
|
if (! $return)
|
|
|
|
{
|
|
|
|
die "Error: couldn't parse command line options. See \'$0 --help' for options.\nExiting...\n";
|
|
|
|
} else {
|
|
|
|
check_arguments();
|
|
|
|
}
|
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
|
|
|
|
#
|
|
|
|
# main loop
|
|
|
|
#
|
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
open (MANIFEST,"<$package") ||
|
|
|
|
die "Error: couldn't open file $package for reading: $!. Exiting...\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
|
|
|
|
LINE: while (<MANIFEST>) {
|
1999-09-15 04:27:37 +04:00
|
|
|
$line = "";
|
1999-09-08 03:30:45 +04:00
|
|
|
$altdest = "";
|
|
|
|
$lineno++;
|
|
|
|
|
|
|
|
s/\;.*//; # it's a comment, kill it.
|
|
|
|
s/^\s+//; # nuke leading whitespace
|
|
|
|
s/\s+$//; # nuke trailing whitespace
|
|
|
|
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 2) && print "\n";
|
|
|
|
($debug >= 8) && print "line $lineno:$_\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
|
|
|
|
# it's a blank line, skip it.
|
|
|
|
/^$/ && do {
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 10) && print "blank line.\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
next LINE;
|
1999-09-10 04:11:54 +04:00
|
|
|
};
|
1999-09-08 03:30:45 +04:00
|
|
|
|
|
|
|
# it's a new component
|
|
|
|
/^\[/ && do {
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 10) && print "component.\n";
|
2000-04-29 00:32:23 +04:00
|
|
|
$component = $_;
|
1999-09-08 03:30:45 +04:00
|
|
|
do_component ();
|
|
|
|
next LINE;
|
1999-09-10 04:11:54 +04:00
|
|
|
};
|
1999-09-08 03:30:45 +04:00
|
|
|
|
|
|
|
# make sure a component is defined before doing any copies or deletes.
|
2000-04-29 00:32:23 +04:00
|
|
|
if (( $component eq "" ) && ($components eq "" )) {
|
1999-09-09 04:25:25 +04:00
|
|
|
die "Error: item $_ outside a component ($package, $lineno). Exiting...\n";
|
2000-04-29 00:32:23 +04:00
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
|
2000-04-29 00:32:23 +04:00
|
|
|
# skip line if we're only copying specific components and outside
|
|
|
|
# those components
|
|
|
|
if (( $component eq "" ) && ($components ne "" )) {
|
|
|
|
($debug >= 10) && print "Not in specifed component. Skipping $_\n";
|
|
|
|
next LINE;
|
|
|
|
}
|
1999-09-28 03:02:06 +04:00
|
|
|
if ($line eq "") {
|
|
|
|
$line = $_; # if $line not set, set it.
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($os ne "MSDOS") { # hack - need to fix for dos
|
|
|
|
$line =~ s/^$PD//; # strip any leading path delimiter
|
|
|
|
}
|
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
# delete the file or directory following the '-'
|
|
|
|
/^-/ && do {
|
1999-09-28 03:02:06 +04:00
|
|
|
$line =~ s/^-//; # strip leading '-'
|
|
|
|
($debug >= 10) && print "delete: $destdir$PD$component$PD$line\n";
|
|
|
|
do_delete ("$destdir", "$component", "$line");
|
1999-09-08 03:30:45 +04:00
|
|
|
next LINE;
|
1999-09-10 04:11:54 +04:00
|
|
|
};
|
1999-09-08 03:30:45 +04:00
|
|
|
|
|
|
|
# file/directory being copied to different target location
|
|
|
|
/\,/ && do {
|
|
|
|
/.*\,.*\,.*/ &&
|
1999-09-09 04:25:25 +04:00
|
|
|
die "Error: multiple commas not allowed ($package, $lineno): $_.\n";
|
1999-09-28 03:02:06 +04:00
|
|
|
($line, $altdest) = split (/\s*\,\s*/, $line, 2);
|
|
|
|
$line =~ s/$PD*$//; # strip any trailing path delimiters
|
1999-09-09 23:22:34 +04:00
|
|
|
$altdest =~ s/$PD*$//; # strip any trailing delimiter
|
1999-09-28 03:02:06 +04:00
|
|
|
($debug >= 10) && print "relocate: $line => $altdest.\n";
|
|
|
|
};
|
1999-09-08 03:30:45 +04:00
|
|
|
|
|
|
|
# if it has wildcards, do recursive copy.
|
|
|
|
/(?:\*|\?)/ && do {
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 10) && print "wildcard copy.\n";
|
1999-10-27 04:03:54 +04:00
|
|
|
if ($os eq "MacOS") {
|
|
|
|
if (/:\*$/) {
|
|
|
|
($debug >= 4) && print "Mac and wildcard is \":*\" so strip and copy entire directory.\n";
|
|
|
|
$line =~ s/:\*$//; # Mac doesn't like wildcards, so strip off any ":*" at the end of the line
|
|
|
|
# and copy the whole directory.
|
|
|
|
do_copydir ("$srcdir$PD$line");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
do_wildcard ("$srcdir$PD$line");
|
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
next LINE;
|
|
|
|
};
|
|
|
|
|
|
|
|
# if it's a single file, copy it.
|
1999-09-15 04:27:37 +04:00
|
|
|
( -f "$srcdir$PD$line" ) && do {
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 10) && print "file copy.\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
do_copyfile ();
|
|
|
|
next LINE;
|
|
|
|
};
|
|
|
|
|
1999-09-15 04:27:37 +04:00
|
|
|
# if it's a directory, do recursive copy.
|
|
|
|
(-d "$srcdir$PD$line") && do {
|
|
|
|
($debug >= 10) && print "directory copy.\n";
|
1999-09-28 03:02:06 +04:00
|
|
|
do_copydir ("$srcdir$PD$line");
|
1999-09-15 04:27:37 +04:00
|
|
|
next LINE;
|
|
|
|
};
|
|
|
|
|
|
|
|
# if we hit this, it's either a file in the package file that is
|
|
|
|
# not in the src directory, or it is not a valid entry.
|
1999-09-28 03:02:06 +04:00
|
|
|
warn "Warning: package error or possible missing file: $line ($package, $lineno).\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
|
|
|
|
} # LINE
|
|
|
|
|
|
|
|
close (MANIFEST);
|
|
|
|
chdir ($saved_cwd);
|
|
|
|
|
|
|
|
exit (0);
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Delete the given file or directory
|
|
|
|
#
|
|
|
|
sub do_delete
|
|
|
|
{
|
1999-09-28 03:02:06 +04:00
|
|
|
my ($targetpath) = $_[0];
|
|
|
|
my ($targetcomp) = $_[1];
|
|
|
|
my ($targetfile) = $_[2];
|
2001-01-23 18:53:12 +03:00
|
|
|
if ($flat) {
|
|
|
|
my ($target) = "$targetpath$PD$targetfile";
|
|
|
|
} else {
|
|
|
|
my ($target) = "$targetpath$PD$targetcomp$PD$targetfile";
|
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 2) && print "do_delete():\n";
|
1999-09-28 03:02:06 +04:00
|
|
|
($debug >= 1) && print "-$targetfile\n";
|
1999-09-09 04:25:25 +04:00
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( -f $target ) {
|
|
|
|
(! -w $target ) &&
|
1999-09-09 04:25:25 +04:00
|
|
|
die "Error: delete failed: $target not writeable ($package, $component, $lineno). Exiting...\n";
|
1999-09-28 03:02:06 +04:00
|
|
|
($debug >= 4) && print " unlink($target)\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
unlink ($target) ||
|
|
|
|
die "Error: unlink() failed: $!. Exiting...\n";
|
1999-09-28 03:02:06 +04:00
|
|
|
} elsif ( -d $target ) {
|
|
|
|
(! -w $target ) &&
|
1999-09-09 04:25:25 +04:00
|
|
|
die "Error: delete failed: $target not writeable ($package, $component, $lineno). Exiting...\n";
|
1999-09-28 03:02:06 +04:00
|
|
|
($debug >= 4) && print " rmtree($target)\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
rmtree ($target, 0, 0) ||
|
|
|
|
die "Error: rmtree() failed: $!. Exiting...\n";
|
|
|
|
} else {
|
2000-03-17 00:16:08 +03:00
|
|
|
warn "Warning: delete failed: $target is not a file or directory ($package, $component, $lineno).\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Copy an individual file from the srcdir to the destdir.
|
1999-09-28 03:02:06 +04:00
|
|
|
#
|
1999-09-08 03:30:45 +04:00
|
|
|
# This is called by both the individual and batch/recursive copy routines,
|
1999-09-28 03:02:06 +04:00
|
|
|
# using $dirflag to check if called from do_copydir. Batch copy can pass in
|
|
|
|
# directories, so be sure to check first and break if it isn't a file.
|
|
|
|
#
|
1999-09-08 03:30:45 +04:00
|
|
|
sub do_copyfile
|
|
|
|
{
|
1999-09-28 03:02:06 +04:00
|
|
|
my ($destpath) = ""; # destination directory path
|
2001-01-23 18:53:12 +03:00
|
|
|
my ($destpathcomp) = ""; # ditto, but possibly including component dir
|
1999-09-28 03:02:06 +04:00
|
|
|
my ($destname) = ""; # destination file name
|
|
|
|
my ($destsuffix) = ""; # destination file name suffix
|
|
|
|
my ($altpath) = ""; # alternate destination directory path
|
|
|
|
my ($altname) = ""; # alternate destination file name
|
|
|
|
my ($altsuffix) = ""; # alternate destination file name suffix
|
|
|
|
my ($srcpath) = ""; # source file directory path
|
|
|
|
my ($srcname) = ""; # source file name
|
|
|
|
my ($srcsuffix) = ""; # source file name suffix
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 2) && print "do_copyfile():\n";
|
1999-09-09 04:25:25 +04:00
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
# set srcname correctly depending on how called
|
|
|
|
if ( $dirflag ) {
|
|
|
|
($srcname, $srcpath, $srcsuffix) = fileparse("$File::Find::name", '\..*?$');
|
1999-09-08 03:30:45 +04:00
|
|
|
} else {
|
1999-09-28 03:02:06 +04:00
|
|
|
($srcname, $srcpath, $srcsuffix) = fileparse("$srcdir$PD$line", '\..*?$');
|
|
|
|
}
|
|
|
|
|
|
|
|
($debug >= 4) && print " fileparse(src): $srcpath $srcname $srcsuffix\n";
|
|
|
|
|
|
|
|
# return if srcname is a directory from do_copydir
|
|
|
|
if ( -d "$srcpath$srcname$srcsuffix" ) {
|
|
|
|
($debug >= 10) && print " return: $srcpath$srcname$srcsuffix is a directory\n";
|
|
|
|
return;
|
1999-09-08 03:30:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# set the destination path, if alternate destination given, use it.
|
2001-01-23 18:53:12 +03:00
|
|
|
if ($flat) {
|
|
|
|
$destpathcomp = "$destdir";
|
|
|
|
} else {
|
|
|
|
$destpathcomp = "$destdir$PD$component";
|
|
|
|
}
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( $altdest ne "" ) {
|
|
|
|
if ( $dirflag ) { # directory copy to altdest
|
2001-01-23 18:53:12 +03:00
|
|
|
($destname, $destpath, $destsuffix) = fileparse("$destpathcomp$PD$altdest$PD$File::Find::name", '\..*?$');
|
1999-09-28 03:02:06 +04:00
|
|
|
# Todo: add MSDOS hack
|
|
|
|
$destpath =~ s/$srcdir$PD$line$PD//; # rm info added by find
|
1999-09-09 23:22:34 +04:00
|
|
|
($debug >= 5) &&
|
1999-09-28 03:02:06 +04:00
|
|
|
print " dir copy to altdest: $destpath $destname $destsuffix\n";
|
|
|
|
} else { # single file copy to altdest
|
2001-01-23 18:53:12 +03:00
|
|
|
($destname, $destpath, $destsuffix) = fileparse("$destpathcomp$PD$altdest", '\..*?$');
|
1999-09-09 23:22:34 +04:00
|
|
|
($debug >= 5) &&
|
1999-09-28 03:02:06 +04:00
|
|
|
print " file copy to altdest: $destpath $destname $destsuffix\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
} else {
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( $dirflag ) { # directory copy, no altdest
|
2001-01-23 18:53:12 +03:00
|
|
|
($destname, $destpath, $destsuffix) = fileparse("$destpathcomp$PD$File::Find::name", '\..*?$');
|
1999-09-10 03:57:08 +04:00
|
|
|
|
|
|
|
# avert your eyes now, butt-ugly hack
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( $os eq "MSDOS" ) {
|
|
|
|
$destpath =~ s/\\/\//g;
|
1999-09-10 03:57:08 +04:00
|
|
|
$srcdir =~ s/\\/\//g;
|
|
|
|
$PD = "/";
|
1999-09-28 03:02:06 +04:00
|
|
|
$destpath =~ s/$srcdir$PD//g;
|
|
|
|
$destpath =~ s/\//\\/g;
|
1999-09-10 04:18:24 +04:00
|
|
|
$srcdir =~ s/\//\\/g;
|
1999-09-10 03:57:08 +04:00
|
|
|
$PD = "\\";
|
|
|
|
} else {
|
1999-09-28 03:02:06 +04:00
|
|
|
$destpath =~ s/$srcdir$PD//;
|
1999-09-10 03:57:08 +04:00
|
|
|
}
|
|
|
|
# end stupid MSDOS hack
|
|
|
|
|
1999-09-09 23:22:34 +04:00
|
|
|
($debug >= 5) &&
|
1999-09-28 03:02:06 +04:00
|
|
|
print " dir copy w/o altdest: $destpath $destname $destsuffix\n";
|
|
|
|
} else { # single file copy, no altdest
|
2001-01-23 18:53:12 +03:00
|
|
|
($destname, $destpath, $destsuffix) = fileparse("$destpathcomp$PD$line", '\..*?$');
|
1999-09-09 23:22:34 +04:00
|
|
|
($debug >= 5) &&
|
1999-09-28 03:02:06 +04:00
|
|
|
print " file copy w/o altdest: $destpath $destname $destsuffix\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
}
|
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
# create the destination path if it doesn't exist
|
|
|
|
if (! -d "$destpath" ) {
|
|
|
|
($debug >= 5) && print " mkpath($destpath)\n";
|
|
|
|
mkpath ($destpath, 0, 0755) ||
|
1999-09-08 03:30:45 +04:00
|
|
|
die "Error: mkpath() failed: $!. Exiting...\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
# path exists, source and destination known, time to copy
|
|
|
|
if ((-f "$srcpath$srcname$srcsuffix") && (-r "$srcpath$srcname$srcsuffix")) {
|
|
|
|
if ( $debug >= 1 ) {
|
|
|
|
if ( $dirflag ) {
|
|
|
|
print "$destname$destsuffix\n"; # from unglob
|
1999-09-09 23:22:34 +04:00
|
|
|
} else {
|
1999-09-28 03:02:06 +04:00
|
|
|
print "$line\n"; # from single file
|
1999-09-09 23:22:34 +04:00
|
|
|
}
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( $debug >= 3 ) {
|
|
|
|
print " copy\t$srcpath$srcname$srcsuffix =>\n\t\t$destpath$destname$destsuffix\n";
|
1999-09-09 23:22:34 +04:00
|
|
|
}
|
|
|
|
}
|
1999-09-28 03:02:06 +04:00
|
|
|
copy ("$srcpath$srcname$srcsuffix", "$destpath$destname$destsuffix") ||
|
|
|
|
die "Error: copy of file $srcpath$srcname$srcsuffix failed ($package, $component, $lineno): $!. Exiting...\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
|
|
|
|
# if this is unix, set the dest file permissions
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( $os eq "Unix" ) {
|
1999-09-10 02:24:51 +04:00
|
|
|
# read permissions
|
1999-09-28 03:02:06 +04:00
|
|
|
$st = stat("$srcpath$srcname$srcsuffix") ||
|
|
|
|
die "Error: can't stat $srcpath$srcname$srcsuffix: $! Exiting...\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
# set permissions
|
1999-09-28 03:02:06 +04:00
|
|
|
($debug >= 2) && print " chmod ".$st->mode." $destpath$destname$destsuffix\n";
|
|
|
|
chmod ($st->mode, "$destpath$destname$destsuffix") ||
|
|
|
|
warn "Warning: chmod of $destpath$destname$destsuffix failed: $!. Exiting...\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
}
|
1999-09-28 03:02:06 +04:00
|
|
|
} else {
|
1999-10-27 04:03:54 +04:00
|
|
|
warn "Error: file $srcpath$srcname$srcsuffix is not a file or is not readable ($package, $component, $lineno).\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
}
|
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
#
|
1999-09-28 03:02:06 +04:00
|
|
|
# Expand any wildcards and copy files and/or directories
|
|
|
|
#
|
|
|
|
# todo: pass individual files to do_copyfile, not do_copydir
|
1999-09-08 03:30:45 +04:00
|
|
|
#
|
1999-09-28 03:02:06 +04:00
|
|
|
sub do_wildcard
|
1999-09-08 03:30:45 +04:00
|
|
|
{
|
|
|
|
my ($entry) = $_[0];
|
1999-09-28 03:02:06 +04:00
|
|
|
my (@list) = ();
|
|
|
|
my ($item) = "";
|
|
|
|
|
|
|
|
($debug >= 2) && print "do_wildcard():\n";
|
|
|
|
|
|
|
|
if ( $entry =~ /(?:\*|\?)/ ) { # it's a wildcard,
|
1999-10-27 04:03:54 +04:00
|
|
|
if ($os eq "MacOS") {
|
|
|
|
warn "Warning: globbing on Mac not supported.\nWorkaround is to copy entire directory.\n";
|
|
|
|
@list = <$entry>;
|
|
|
|
} else {
|
|
|
|
@list = glob($entry); # expand it
|
|
|
|
}
|
1999-09-28 03:02:06 +04:00
|
|
|
($debug >= 4) && print " glob: $entry => @list\n";
|
|
|
|
|
|
|
|
foreach $item ( @list ) { # now copy each item in list
|
|
|
|
if ( -f $item ) {
|
|
|
|
($debug >= 10) && print " do_copyfile: $item\n";
|
|
|
|
|
|
|
|
# glob adds full path to item like find() in copydir so
|
|
|
|
# take advantage of existing code in copyfile by using
|
|
|
|
# $dirflag and $File::Find::name.
|
|
|
|
|
|
|
|
$File::Find::name = $item;
|
|
|
|
$dirflag = 1;
|
|
|
|
do_copyfile();
|
|
|
|
$dirflag = 0;
|
|
|
|
$File::Find::name = "";
|
|
|
|
} elsif ( -d $item ) {
|
|
|
|
($debug >= 10) && print " do_copydir($item)\n";
|
|
|
|
do_copydir ($item);
|
|
|
|
} else {
|
|
|
|
warn "Warning: $item is not a file or directory ($package, $component, $lineno). Skipped...\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
#
|
|
|
|
# Recursively copy directories specified.
|
|
|
|
#
|
|
|
|
sub do_copydir
|
|
|
|
{
|
|
|
|
my ($entry) = $_[0];
|
1999-09-09 04:25:25 +04:00
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
$dirflag = 1; # flag indicating directory copy in progress
|
|
|
|
|
|
|
|
($debug >= 2) && print "do_copydir():\n";
|
|
|
|
|
|
|
|
if (! -d "$entry" ) {
|
|
|
|
warn "Warning: $entry is not a directory ($package, $component, $lineno). Skipped...\n";
|
1999-09-10 02:24:51 +04:00
|
|
|
}
|
1999-09-28 03:02:06 +04:00
|
|
|
|
|
|
|
($debug >= 4) && print " find($entry)\n";
|
|
|
|
|
|
|
|
find (\&do_copyfile, $entry);
|
|
|
|
|
|
|
|
$dirflag = 0;
|
1999-09-08 03:30:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Handle new component
|
|
|
|
#
|
|
|
|
sub do_component
|
|
|
|
{
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 2) && print "do_component():\n";
|
1999-09-09 04:25:25 +04:00
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
( $component =~ /^\[.*(?:\s|\[|\])+.*\]/ ) && # no brackets or ws
|
|
|
|
die "Error: malformed component $component. Exiting...\n";
|
|
|
|
$component =~ s/^\[(.*)\]/$1/; # strip []
|
|
|
|
|
2000-04-29 00:32:23 +04:00
|
|
|
if ( $components ne "") {
|
|
|
|
if ( $components =~ /$component/ ) {
|
|
|
|
($debug >= 10) && print "Component $component is in $components.\n";
|
|
|
|
} else {
|
|
|
|
($debug >= 10) && print "Component $component not in $components.\n";
|
|
|
|
$component = "";
|
|
|
|
return; # named specific components and this isn't it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-09 23:22:34 +04:00
|
|
|
if ($debug >= 1) {
|
|
|
|
print "[$component]\n";
|
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
# create component directory
|
2001-01-23 18:53:12 +03:00
|
|
|
if (!$flat) {
|
|
|
|
if ( -d "$destdir$PD$component" ) {
|
|
|
|
warn "Warning: component directory \"$component\" already exists in \"$destdir\".\n";
|
|
|
|
} else {
|
|
|
|
($debug >= 4) && print " mkdir $destdir$PD$component\n";
|
|
|
|
mkdir ("$destdir$PD$component", 0755) ||
|
|
|
|
die "Error: couldn't create component directory \"$component\": $!. Exiting...\n";
|
|
|
|
}
|
1999-09-10 02:24:51 +04:00
|
|
|
}
|
1999-09-08 03:30:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check that arguments to script are valid.
|
|
|
|
#
|
|
|
|
sub check_arguments
|
|
|
|
{
|
1999-09-09 04:25:25 +04:00
|
|
|
my ($exitval) = 0;
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 2) && print "check_arguments():\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
# if --help print usage
|
|
|
|
if ($help) {
|
|
|
|
print_usage();
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
# make sure required variables are set:
|
|
|
|
# check source directory
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( $srcdir eq "" ) {
|
1999-09-09 04:25:25 +04:00
|
|
|
print "Error: source directory (--source) not specified.\n";
|
|
|
|
$exitval += 8;
|
1999-09-28 03:02:06 +04:00
|
|
|
} elsif ((! -d $srcdir) || (! -r $srcdir)) {
|
1999-09-09 04:25:25 +04:00
|
|
|
print "Error: source directory \"$srcdir\" is not a directory or is unreadable.\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
$exitval = 1;
|
|
|
|
}
|
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
# check destination directory
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( $destdir eq "" ) {
|
1999-09-09 04:25:25 +04:00
|
|
|
print "Error: destination directory (--destination) not specified.\n";
|
|
|
|
$exitval += 8;
|
1999-09-28 03:02:06 +04:00
|
|
|
} elsif ((! -d $destdir) || (! -w $destdir)) {
|
1999-09-09 04:25:25 +04:00
|
|
|
print "Error: destination directory \"$destdir\" is not a directory or is not writeable.\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
$exitval += 2;
|
|
|
|
}
|
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
# check destdir not a subdir of srcdir
|
|
|
|
# hack - workaround for bug 14558 that should be fixed eventually.
|
|
|
|
if (0) { # todo - write test
|
|
|
|
print "Error: destination directory must not be subdirectory of the source directory.\n";
|
|
|
|
$exitval += 32;
|
|
|
|
}
|
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
# check package file
|
1999-09-28 03:02:06 +04:00
|
|
|
if ( $package eq "" ) {
|
1999-09-09 04:25:25 +04:00
|
|
|
print "Error: package file (--file) not specified.\n";
|
|
|
|
$exitval += 8;
|
|
|
|
} elsif (!(-f $package) || !(-r $package)) {
|
|
|
|
print "Error: package file \"$package\" is not a file or is unreadable.\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
$exitval += 4;
|
|
|
|
}
|
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
# check OS == {mac|unix|dos}
|
|
|
|
if ($os eq "") {
|
|
|
|
print "Error: OS type (--os) not specified.\n";
|
|
|
|
$exitval += 8;
|
|
|
|
} elsif ( $os =~ /mac/i ) {
|
|
|
|
$os = "MacOS";
|
1999-09-09 23:22:34 +04:00
|
|
|
$PD = ":";
|
1999-09-10 04:11:54 +04:00
|
|
|
fileparse_set_fstype ($os);
|
1999-09-09 04:25:25 +04:00
|
|
|
} elsif ( $os =~ /dos/i ) {
|
|
|
|
$os = "MSDOS";
|
1999-09-09 23:22:34 +04:00
|
|
|
$PD = "\\";
|
1999-09-10 04:11:54 +04:00
|
|
|
fileparse_set_fstype ($os);
|
1999-09-15 04:27:37 +04:00
|
|
|
} elsif ( $os =~ /unix/i ) {
|
|
|
|
$os = "Unix"; # can be anything but MacOS, MSDOS, or VMS
|
1999-09-09 23:22:34 +04:00
|
|
|
$PD = "/";
|
1999-09-10 04:11:54 +04:00
|
|
|
fileparse_set_fstype ($os);
|
1999-09-09 04:25:25 +04:00
|
|
|
} else {
|
|
|
|
print "Error: OS type \"$os\" unknown.\n";
|
|
|
|
$exitval += 16;
|
|
|
|
}
|
|
|
|
|
2000-04-29 00:32:23 +04:00
|
|
|
# turn components array into a string for regexp
|
|
|
|
if ( @components > 0 ) {
|
|
|
|
$components = join (",",@components);
|
|
|
|
} else {
|
|
|
|
$components = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($debug > 4) {
|
|
|
|
print ("source dir:\t$srcdir\ndest dir:\t$destdir\npackage:\t$package\nOS:\t$os\ncomponents:\t$components\n");
|
|
|
|
}
|
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
if ($exitval) {
|
1999-09-15 04:27:37 +04:00
|
|
|
print "See \'$0 --help\' for more information.\n";
|
1999-09-08 03:30:45 +04:00
|
|
|
print "Exiting...\n";
|
|
|
|
exit ($exitval);
|
|
|
|
}
|
2000-04-29 00:32:23 +04:00
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
#
|
|
|
|
# This is called by GetOptions when there are extra command line arguments
|
|
|
|
# it doesn't understand.
|
|
|
|
#
|
|
|
|
sub do_badargument
|
|
|
|
{
|
|
|
|
warn "Warning: unknown command line option specified: @_.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
#
|
|
|
|
# display usage information
|
|
|
|
#
|
|
|
|
sub print_usage
|
|
|
|
{
|
1999-09-10 04:11:54 +04:00
|
|
|
($debug >= 2) && print "print_usage():\n";
|
1999-09-09 04:25:25 +04:00
|
|
|
|
1999-09-08 03:30:45 +04:00
|
|
|
print <<EOC
|
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
$0
|
|
|
|
Copy files from the source directory to component directories
|
|
|
|
in the destination directory as specified by the package file.
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
Options:
|
1999-09-15 04:27:37 +04:00
|
|
|
-s, --source <source directory>
|
1999-09-09 04:25:25 +04:00
|
|
|
Specifies the directory from which to copy the files
|
1999-09-15 04:27:37 +04:00
|
|
|
specified in the file passed via --file.
|
1999-09-09 04:25:25 +04:00
|
|
|
Required.
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-15 04:27:37 +04:00
|
|
|
-d, --destination <destination directory>
|
1999-09-09 04:25:25 +04:00
|
|
|
Specifies the directory in which to create the component
|
|
|
|
directories and copy the files specified in the file passed
|
1999-09-15 04:27:37 +04:00
|
|
|
via --file.
|
1999-09-09 04:25:25 +04:00
|
|
|
Required.
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-28 03:02:06 +04:00
|
|
|
NOTE: Source and destination directories must be absolute paths.
|
|
|
|
Relative paths will NOT work. Also, the destination directory
|
|
|
|
must NOT be a subdirectory of the source directory.
|
|
|
|
|
1999-09-15 04:27:37 +04:00
|
|
|
-f, --file <package file>
|
1999-09-09 04:25:25 +04:00
|
|
|
Specifies the file listing the components to be created in
|
|
|
|
the destination directory and the files to copy from the
|
|
|
|
source directory to each component directory in the
|
1999-09-15 04:27:37 +04:00
|
|
|
destination directory.
|
1999-09-09 04:25:25 +04:00
|
|
|
Required.
|
|
|
|
|
1999-09-15 04:27:37 +04:00
|
|
|
-o, --os [dos|mac|unix]
|
|
|
|
Specifies which type of system this is. Used for parsing
|
|
|
|
file specifications from the package file.
|
1999-09-09 04:25:25 +04:00
|
|
|
Required.
|
|
|
|
|
2000-04-29 00:32:23 +04:00
|
|
|
-c, --component <component name>
|
|
|
|
Specifies a specific component in the package file to copy
|
|
|
|
rather than copying all the components in the package file.
|
|
|
|
Can be used more than once for multiple components (e.g.
|
|
|
|
"-c browser -c mail" to copy mail and news only).
|
|
|
|
Optional.
|
|
|
|
|
2001-01-23 18:53:12 +03:00
|
|
|
-l, --flat
|
|
|
|
Suppresses creation of components dirs, but stuffes everything
|
|
|
|
directly into the package destination dir. This is useful
|
|
|
|
for creating tarballs.
|
|
|
|
|
1999-09-15 04:27:37 +04:00
|
|
|
-h, --help
|
|
|
|
Prints this information.
|
1999-09-09 04:25:25 +04:00
|
|
|
Optional.
|
|
|
|
|
|
|
|
--debug [1-10]
|
|
|
|
Controls verbosity of debugging output, 10 being most verbose.
|
1999-09-09 23:22:34 +04:00
|
|
|
1 : same as --verbose.
|
|
|
|
2 : includes function calls.
|
|
|
|
3 : includes source and destination for each copy.
|
1999-09-09 04:25:25 +04:00
|
|
|
Optional.
|
1999-09-08 03:30:45 +04:00
|
|
|
|
1999-09-15 04:27:37 +04:00
|
|
|
-v, --verbose
|
|
|
|
Print component names and files copied/deleted.
|
1999-09-09 23:22:34 +04:00
|
|
|
Optional.
|
|
|
|
|
|
|
|
|
1999-09-09 04:25:25 +04:00
|
|
|
e.g.
|
|
|
|
|
1999-09-09 23:22:34 +04:00
|
|
|
$0 --os unix --source /builds/mozilla/dist --destination /h/lithium/install --file packages-win --os unix --verbose
|
1999-09-09 04:25:25 +04:00
|
|
|
|
|
|
|
Note: options can be specified by either a leading '--' or '-'.
|
|
|
|
|
|
|
|
EOC
|
1999-09-08 03:30:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# EOF
|