sub import {
my $pkg = shift;
foreach (@_) {
#print STDERR "importing: $_\n";
$Program_Paths{ $_ } = 0;
}
my( $home, @PATH, @missing );
$home = cwd() or die "Can't save cwd";
my $H = [ $home, 1 ];
@PATH = split /:/, $ENV{'PATH'};
foreach (@PATH) {
s|/?$|/|; # Append / to each path
}
# For each program, check there is an executable
foreach my $program (keys %Program_Paths) {
# Deal with paths
if ($program =~ m|/|) {
my $path = $program;
# Deal with tildes
$path =~ s{^~([^/]*)}{ $1 ? (getpwnam($1))[7]
: (getpwuid($>))[7] }e;
$Program_Paths{ $program } = $real;
}
}
# Or search through all paths
else {
foreach my $path (@PATH) {
if (my $real =
_is_prog( $H, $path, $program )) {
$Program_Paths{ $program } = $real;
last;
}
}
}
}
_go_home( $H ); # Return to home directory
# Make a list of all missing programs
foreach my $program (keys %Program_Paths) {
push( @missing, $program ) unless $Program_Paths{ $program };
}
# Give informative death message if programs weren't found
if (@missing) {
throw("Unable to locate the following programs as '". (getpwuid($<))[0]. "' on host '". hostname(). "' :\t".
join ( " --> " , @missing )) ;
}
}