分类:
2006-06-08 20:36:31
#!/bin/sh
#This is a scripe that copy the library file about a command.
#Auther:wangyao
#Mail:wangyao@cs.hit.edu.cn
# ipconfigme@gmail.com
#Usage: cplib /bin/login /tmp
function cplib()
{
#mkdir that store the libfile
if [ ! -e $DestDir$LibDir ];then
mkdir -p $DestDir$LibDir
fi
if [ -e $libfile ];then
if [ ! -L $libfile ];then
cp -a $libfile $DestDir$LibDir #copy the file to the destdir
return #if the file is not link ,exit the funtion
elif [ -L $libfile ];then
#lrwxrwxrwx 1 root root 15 2006-03-27 21:23 /lib/libblkid.so.1 -> libblkid.so.1.0
cp -a $libfile $DestDir$LibDir #copy the link
libfile=$LibDir/`ls -l $libfile | awk '{print $10;}'` #get the link file's name
echo $libfile
#cp -a $LibDir/$linkfile $DestDir/$LibDir
cplib #Use the cplib funtion by recursion.
else
echo "No found the file!"
fi
fi
}
Binname=$1
DestDir=$2
if [ ! -e $DestDir ];then
mkdir -p $DestDir
fi
#Get the library file through ldd command.
ldd $Binname > lddfile # store the ldd message
# linux-gate.so.1 => (0xffffe000)
# /lib/ld-linux.so.2 (0x80000000)
for file in $(cat lddfile);do # get the message in file
case $file in # Create the relate directory
/* ) libfile=$file
LibDir=${libfile%/*}
cplib;;
(* ) ;;# The useless form : (0x00468000)
=* ) ;;# The uselsee form : =>
* ) libfile=/lib/$file
LibDir=${libfile%/*}
cplib;;
esac
done
rm lddfile