-
Notifications
You must be signed in to change notification settings - Fork 5
/
ldd_cp.sh
43 lines (34 loc) · 826 Bytes
/
ldd_cp.sh
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
#!/bin/bash
if [ $# != 2 ] ; then
echo "Usage: $0 PATH_TO_BINARY TARGET_FOLDER"
exit 1
fi
PATH_TO_BINARY="$1"
TARGET_FOLDER="$2"
if [ ! -f "$PATH_TO_BINARY" ] ; then
echo "The file '$PATH_TO_BINARY' was not found. Aborting!"
exit 1
fi
if [ ! -d "$TARGET_FOLDER" ] ; then
echo "No such directory '$TARGET_FOLDER'. Aborting!"
exit 1
fi
copy_link_and_file ()
{
local file=$1
local dir=$2
cp -dv --parents "$file" "$dir"
local link="$file"
while [ -h "$link" ] ; do
link=`readlink -f $link`
cp -dv --parents "$link" "$dir";
done
}
echo "---> copy binary itself"
copy_link_and_file "$PATH_TO_BINARY" "$TARGET_FOLDER"
echo "---> copy libraries"
for lib in `ldd "$PATH_TO_BINARY" | cut -d'>' -f2 | awk '{print $1}'` ; do
if [[ $lib =~ .*lib.* ]] ; then
copy_link_and_file "$lib" "$TARGET_FOLDER"
fi
done