Make {bounce,warn}_message_file expanded. Bug 2522
[exim.git] / test / src / locate.pl
CommitLineData
50936073 1#!/usr/bin/env perl
cee3d4ab
HSHR
2
3use 5.010;
50936073
HSHR
4use strict;
5use warnings;
6use File::Find;
7use Cwd;
8
9my @dirs = grep { /^\// && -d } split(/:/, $ENV{PATH}), qw(
10 /bin
11 /usr/bin
12 /usr/sbin
66387a73 13 /usr/lib
50936073
HSHR
14 /usr/libexec
15 /usr/local/bin
16 /usr/local/sbin
17 /usr/local
18 /opt
19);
20
21my %path = map { $_ => locate($_, @dirs) } @ARGV;
22
23mkdir 'bin.sys'
24 or die "bin.sys: $!"
25 if not -d 'bin.sys';
26
27foreach my $tool (keys %path) {
28 next if not defined $path{$tool};
29 print "$tool $path{$tool}\n";
30
31 unlink "bin.sys/$tool";
32 symlink $path{$tool}, "bin.sys/$tool"
33 or warn "bin.sys/$tool -> $path{$tool}: $!\n";
34}
35
36sub locate {
37 my ($tool, @dirs) = @_;
38
39 # use die to break out of the find as soon
40 # as we found it
41 my $cwd = cwd;
42 eval {
43 find(
44 sub {
cee3d4ab
HSHR
45 return $File::Find::prune = 1 unless -r -x -r;
46 return unless $tool eq $_ and -x and -f _;
50936073
HSHR
47 die { found => $File::Find::name };
48 },
49 @dirs
50 );
51 };
52 chdir $cwd;
53
54 return (ref $@ eq ref {} and $@->{found}) ? $@->{found} : undef;
55}