Commit 0e00573c authored by Roman Haefeli's avatar Roman Haefeli
Browse files

add more checks and make it arch aware (use different search paths on different archs)

parent 18c02c88
#!/bin/sh
#
# creates local copies of all dependencies (dynamic libraries)
# and sets RUNPATH to $ORIGIN on each so they will find
# each other.
#
# usage: $0 <binary>
#
# Author: Roman Haefeli <reduzent@gmail.com>
extfile="$1"
LD_LIBRARY_PATH="$HOME/.local/lib:/usr/local/lib64:/usr/lib/x86_64-linux-gnu"
case $1 in
"")
echo "Usage: /bin/sh ${0} <binary>"
exit
;;
*)
binary_file=$1
;;
esac
# List of libraries that we do not include into our packaging
# becaue we think they will be installed on any system
LD_EXCLUDE_LIST="linux-vdso\.so.*
libc.so\.*
ld-linux-.*\.so.*
......@@ -13,8 +31,8 @@ libgcc_s\.so.*
libpcre\.so.*"
# Check dependencies
cmdlist="awk grep ldd patchelf"
for cmd in $cmlist
cmdlist="awk grep ldd patchelf uname"
for cmd in $cmdlist
do
if ! which $cmd > /dev/null
then
......@@ -23,6 +41,30 @@ do
fi
done
# Set LD_LIBRARY_PATH depending on arch
ARCH=$(uname -m)
case $ARCH in
"x86_64")
LD_LIBRARY_PATH="$HOME/.local/lib:/usr/local/lib64:/usr/lib/x86_64-linux-gnu"
;;
"i686")
LD_LIBRARY_PATH="$HOME/.local/lib:/usr/local/lib:/usr/lib/i386-linux-gnu"
;;
"armv7l")
LD_LIBRARY_PATH="$HOME/.local/lib:/usr/local/lib:/usr/lib/arm-linux-gnueabihf"
;;
*)
echo "Arch '$ARCH' not (yet) supported. Please file a bug report"
exit 1
esac
# Check if we can read from given file
if ! ldd $binary_file > /dev/null 2>&1
then
echo "Can't read '${binary_file}'. Is it a binary file?" > /dev/stderr
exit 1
fi
library_in_exclude_list() {
# arg1: library name
# returns 0 if arg1 is found in exclude list, otherwise 1
......@@ -42,6 +84,8 @@ library_in_exclude_list() {
}
search_make_local_copy() {
# look for given library in all library paths
# and make a local copy of it
# arg1: name of the library to make a local copy of
found=false
IFSold=$IFS
......@@ -59,7 +103,10 @@ search_make_local_copy() {
}
make_local_copy_and_set_rpath() {
ldd $extfile | while read ldd_line
# make a local copy of all linked libraries of given binary
# and set RUNPATH to $ORIGIN (exclude "standard" libraries)
# arg1: binary to check
ldd $1 | while read ldd_line
do
libname=$(echo "$ldd_line" | awk '{ print $1 }')
libpath=$(echo "$ldd_line" | awk '{ print $3 }')
......@@ -83,9 +130,12 @@ make_local_copy_and_set_rpath() {
}
find_missing() {
# find libraries that are shown as 'not found' in ldd and
# create a local copy of them.
# arg1: binary file to check for missing links
while true
do
ldd_output=$(ldd ${extfile})
ldd_output=$(ldd ${1})
if echo "$ldd_output" | grep '=> not found' > /dev/null
then
next_missing=$(echo "$ldd_output" | grep '=> not found' | head -n1 | awk '{print $1}')
......@@ -96,6 +146,8 @@ find_missing() {
done
}
find_missing
make_local_copy_and_set_rpath
find_missing $binary_file
make_local_copy_and_set_rpath $binary_file
# clean after ourselves
rm $0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment