-
Notifications
You must be signed in to change notification settings - Fork 9
/
copyMissingLibraries
executable file
·83 lines (65 loc) · 1.72 KB
/
copyMissingLibraries
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
76
77
78
79
80
81
82
83
#!/bin/bash
# Author : Ismael Barros² <[email protected]>
# License : BSD http://en.wikipedia.org/wiki/BSD_license
EXCEPTIONS=libGL.so.1
DESTINATION="$PWD/usr/lib/"
findFiles() {
find "$DESTINATION" -iname "*.so"
find "$DESTINATION" -iname "*.so.*"
for i in $@; do
[ -d "$i" ] && find "$i" -type f -perm /a+x
[ -f "$i" ] && echo "$i"
done
}
extractDependencies() {
#objdump -p "$@" 2>/dev/null | egrep NEEDED | awk '{ print $2 }' | grep -v "$PWD" | egrep "^/" | sort | uniq
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DESTINATION" ldd "$@" | grep "not found" | sort | uniq >&2
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DESTINATION" ldd "$@" 2>/dev/null | grep -v "not a dynamic executable" | grep -v "^\." | grep -v "$PWD" | cut -d" " -f3 | grep "^/" | sort | uniq
}
extractRuntimeDependencies() {
strings "$@" | egrep \\.so
}
mkdir -p "$DESTINATION"
OIFS=$IFS
NIFS=$'\n'
IFS=$NIFS
prev_libs=
while true; do
files=$(findFiles "$@")
libs=$(extractDependencies $files)
#runlibs=$(extractRuntimeDependencies $@)
#if [ -n "$libs" ]; then
#echo "Libraries: $libs"
#fi
#if [ -n "$runlibs" ]; then
#echo "Runtime libraries: $runlibs"
#libs+=" $runlibs"
#fi
for i in $EXCEPTIONS; do
#echo "Ignoring $i"
#libs=${libs//$i/}
for j in $libs; do
[[ "$j" =~ "$i" ]] && {
echo "Ignoring $j"
libs=${libs//$j/}
}
done
done
for i in $libs; do
dest_lib=$DESTINATION/$(basename "$i")
if [ ! -f "$dest_lib" ]; then
if [ -f "$i" ]; then
cp -v "$i" "$dest_lib"
chmod +x "$dest_lib"
else
echo "!! Could not find dependency $i"
fi
fi
done
# If no new libraries have been found, break the loop
if [ "$prev_libs" = "$libs" ]; then
break;
fi
prev_libs=$libs
done
cp -v /lib/ld-linux.so.2 usr/lib/