forked from signalfx/signalfx-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect-libs
executable file
·75 lines (61 loc) · 1.82 KB
/
collect-libs
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
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e
usage() {
echo 'Usage: $1 output_dir binary_path ...'
}
# Find all dependent shared object files for the collectd installation and move
# them into the installation directory
target_path=$1
mkdir -p $target_path
shift
binary_paths=$@
if [[ ${#binary_paths[@]} == 0 ]]
then
usage
exit 1
fi
#echo "First copying given paths to $target_path"
#cp --parents -a -R -L $binary_paths $target_path
echo "Copying dependent libs to $target_path"
find_deps() {
local paths=$@
# Run all of the collectd libs/binaries through ldd and pull out the deps
# We handle libjvm specially so exclude it here.
find $paths -type f -o -type l -and -executable -or -name "*.so*" | \
xargs ldd | \
perl -ne 'print if /.* => (.+) \(0x[0-9a-f]+\)/' | \
perl -pe 's/.* => (.+) \(0x[0-9a-f]+\)/\1/' | \
perl -ne '/^\ s/ || print' | \
perl -ne '/:$/ || print' | \
grep -v libjvm.so | \
sort | uniq
}
all_links() {
local file=$(basename $1)
local dir=$(dirname $1)
echo "${dir}/$file"
while file=$(readlink "${dir}/$file"); do
echo -n " ${dir}/$file"
done
}
libs=$(find_deps $binary_paths)
# Pulling one level of transitive deps is enough for now
transitive_deps=$(find_deps $libs)
for lib in /lib/`uname -m`-linux-gnu/libnss_* /lib/`uname -m`-linux-gnu/libnsl* $libs $transitive_deps
do
cp -a $(all_links $lib) $target_path
echo "Pulled in $lib" # to $new_path"
done
echo "Processed $(wc -w <<< $libs) libraries"
echo "Checking for missing lib dependencies..."
# Look for all of the deps now in the target_path and make sure we have them
new_deps=$(find_deps $target_path | sed -e "s!^$target_path!!")
for dep in $new_deps
do
stat ${target_path}/$(basename ${dep}) >/dev/null
if [[ $? != 0 ]]; then
echo "Missing dependency in target dir: $dep" >&2
exit 1
fi
done
echo "Everything is there!"