-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-pg-shared-libs.pl
executable file
·66 lines (58 loc) · 1.48 KB
/
copy-pg-shared-libs.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl
use strict;
use File::Copy;
sub get_binaries($) {
my $bin_dir = shift;
$bin_dir =~ s!/$!!;
opendir my $dir , $bin_dir || die "Cannot open directory $bin_dir";
my @files;
while(my $file = readdir($dir)) {
my $full = "$bin_dir/$file";
if (-f $full && -x $full) {
push(@files, $full);
}
}
closedir $dir;
return @files;
}
sub libraries_for($) {
my $full_path = shift;
my %libs = ();
my @lines = `ldd $full_path`;
foreach my $line (@lines) {
chomp($line);
my @tokens = split(/=>/, $line);
my $name = str_trim($tokens[0]);
my $path = $name;
if (@tokens > 1) {
$path = $tokens[1];
}
$path = str_trim($path);
$path =~ s!\s+.*!!;
$name =~ s!\s+.*!!;
if ($path =~ m!^/!) {
$libs{$name} = $path;
}
}
return %libs;
}
sub str_trim {
my $line = $_[0];
$line =~ s/^\s+//;
$line =~ s/\s+$//;
return $line;
}
my $pg_bin_dir = '/opt/postgres/bin';
my @binaries = get_binaries($pg_bin_dir);
my %libs = ();
foreach my $binary (@binaries) {
my %bin_libs = libraries_for($binary);
%libs = (%libs, %bin_libs);
}
my $dest_dir = '/opt/postgres-shared-libs';
mkdir($dest_dir) unless (-d $dest_dir);
foreach my $name (sort (keys %libs)) {
my $path = $libs{$name};
print("copying $path to $dest_dir\n");
copy($path, $dest_dir) || die "Cannot copy $path to $dest_dir - $!\n";
}