Initial commit
This commit is contained in:
+115
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
EXE_PATH="$1"
|
||||
ARTIFACT_PATH="${2:-artifacts}"
|
||||
|
||||
if [ ! -f "$EXE_PATH" ]; then
|
||||
echo "Executable does not exist: $EXE_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$ARTIFACT_PATH"
|
||||
|
||||
declare -A PROCESSED
|
||||
|
||||
is_system_library() {
|
||||
local name
|
||||
name="$(basename "$1")"
|
||||
|
||||
case "$name" in
|
||||
libc.so|libc.so.*)
|
||||
return 0
|
||||
;;
|
||||
|
||||
libm.so|libm.so.*)
|
||||
return 0
|
||||
;;
|
||||
|
||||
libpthread.so|libpthread.so.*)
|
||||
return 0
|
||||
;;
|
||||
|
||||
libdl.so|libdl.so.*)
|
||||
return 0
|
||||
;;
|
||||
|
||||
librt.so|librt.so.*)
|
||||
return 0
|
||||
;;
|
||||
|
||||
ld-linux*.so|ld-linux*.so.*)
|
||||
return 0
|
||||
;;
|
||||
|
||||
libgcc_s.so|libgcc_s.so.*)
|
||||
return 0
|
||||
;;
|
||||
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
get_dependencies() {
|
||||
local binary="$1"
|
||||
|
||||
ldd "$binary" |
|
||||
awk '
|
||||
/=> \// {
|
||||
print $3
|
||||
next
|
||||
}
|
||||
|
||||
/^\// {
|
||||
print $1
|
||||
}
|
||||
' |
|
||||
sort -u
|
||||
}
|
||||
|
||||
copy_dependency() {
|
||||
local dependency="$1"
|
||||
|
||||
local requested_name
|
||||
requested_name="$(basename "$dependency")"
|
||||
|
||||
local resolved_path
|
||||
resolved_path="$(readlink -f "$dependency")"
|
||||
|
||||
local destination
|
||||
destination="$ARTIFACT_PATH/$requested_name"
|
||||
|
||||
if [ ! -f "$destination" ]; then
|
||||
echo "Copying dependency: $dependency"
|
||||
cp "$resolved_path" "$destination"
|
||||
fi
|
||||
}
|
||||
|
||||
copy_dependencies() {
|
||||
local binary="$1"
|
||||
|
||||
while IFS= read -r dependency; do
|
||||
[ -z "$dependency" ] && continue
|
||||
[ ! -f "$dependency" ] && continue
|
||||
|
||||
if [[ -n "${PROCESSED[$dependency]:-}" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
PROCESSED["$dependency"]=1
|
||||
|
||||
if is_system_library "$dependency"; then
|
||||
echo "Skipping Linux system dependency: $dependency"
|
||||
continue
|
||||
fi
|
||||
|
||||
copy_dependency "$dependency"
|
||||
copy_dependencies "$dependency"
|
||||
|
||||
done < <(get_dependencies "$binary")
|
||||
}
|
||||
|
||||
copy_dependencies "$EXE_PATH"
|
||||
Reference in New Issue
Block a user