|
最近在自行构建Linux系统的时候,需要拷贝一些命令的动态链接库。就写了一个脚本。
以前没有写过什么脚本,有什么地方不太合适的,请大家指出,便于以后我改正
- #!/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
复制代码
匹配的地方想用awk来做,不过没有弄出来,只好采用了一种比较笨的方法,如果有哪位大虾搞定了,也贴出来。 |
|