-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure_nativetools
executable file
·40 lines (34 loc) · 1.21 KB
/
configure_nativetools
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
#!/usr/bin/env bash
set -eufo pipefail
mkdir /native_bin
if [ "$#" -gt 0 ]; then
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends patchelf "$@"
dpkg -L "$@" | grep -F -f <(tr ':' '\n' <<< "$PATH") \
| while read -r file; do
[ -f "$file" ] || continue
new_file="/native_bin/$(basename "$file")"
[ ! -e "$new_file" ] || continue
[ "$new_file" != /native_bin/dpkg ] || continue
if [ -L "$file" ]; then
link_target="$(basename "$(realpath "$file")")"
ln -s "$link_target" "$new_file"
elif interpreter="$(patchelf --print-interpreter "$file" 2> /dev/null)"; then
cp "$file" "$new_file"
new_interpreter="/native_bin/$(basename "$interpreter")"
[ -e "$new_interpreter" ] || cp "$interpreter" "$new_interpreter"
ldd "$new_file" | grep -oP '(?<=\=\> )/[^ ]+' | grep -vF "$interpreter" \
| while read -r lib; do\
new_lib="/native_bin/$(basename "$lib")"
cp "$lib" "$new_lib"
patchelf --set-rpath /native_bin "$new_lib"
echo "$new_lib"
ldd "$new_lib"
done
patchelf --set-interpreter "$new_interpreter" --set-rpath /native_bin "$new_file"
echo "$new_file"
ldd "$new_file"
fi
done
find /native_bin -xtype l -delete
fi
tar cf /output /native_bin