Skip to content

Instantly share code, notes, and snippets.

@enten
Created February 28, 2015 13:28
Show Gist options
  • Save enten/67725d0670c4958518c0 to your computer and use it in GitHub Desktop.
Save enten/67725d0670c4958518c0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Author : Hemanth.HM, Steven ENTEN
# Email : hemanth[dot]hm[at]gmail[dot]com, steven[at]enten[dot]fr
# License : GNU GPLv3
#
function useage()
{
cat << EOU
Useage: bash $0 <path to the binary> <path to the rootfs where copy the dependencies>
EOU
exit 1
}
#Validate the inputs
[[ $# < 2 ]] && useage
#Check if the paths are vaild
[[ ! -e $1 ]] && echo "Not a vaild input $1" && exit 1
[[ -d $2 ]] || echo "No such directory $2 creating..."&& mkdir -p "$2"
#Get the library dependencies
echo "Collecting the shared library dependencies for $1..."
deps=$(ldd $1 | awk 'BEGIN{ORS=" "}$1\
~/^\//{print $1}$3~/^\//{print $3}'\
| sed 's/,$/\n/')
echo "Copying the dependencies to $2"
#Copy the deps
for dep in $deps
do
dcc="${dep%/*}"
echo -n "Copying $dep to $2${dcc} : "
[ ! -d $2${dcc} ] && mkdir -p $2${dcc}
if ! cp -f $dep $2${dcc} >/dev/null 2>&1 ; then
echo "KO"
else
echo "ok"
fi
done
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment