二进制程序及其依赖库的移植脚本

#!/bin/bash
#
#指定移植目录 DEST
=/mnt/sysroot
#依赖库文件拷贝 libcp() { LIBPATH
=${1%/*} [ ! -d $DEST$LIBPATH ] && mkdir -p $DEST$LIBPATH [ ! -e $DEST${1} ] && cp $1 $DEST$LIBPATH && echo "copy lib $1 finished." } #程序本身的拷贝 bincp() { CMDPATH=${1%/*} [ ! -d $DEST$CMDPATH ] && mkdir -p $DEST$CMDPATH [ ! -e $DEST${1} ] && cp $1 $DEST$CMDPATH for LIB in `ldd $1 | grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{1,\}"`; do libcp $LIB done } #定义传递参数 read -p "Your command: " CMD until [ $CMD == 'q' ]; do ! which $CMD &> /dev/null && echo "Wrong command" && read -p "Input again:" CMD && continue COMMAND=` which $CMD | grep -v "^alias" | grep -o "[^[:space:]]\{1,\}"` bincp $COMMAND echo "copy $COMMAND finished." read -p "Continue: " CMD done

 

#!/bin/bash  
#  
target=/mnt/sysroot  
clearCmd() {  
if which $cmd &> /dev/null; then  
cmdPath=`which --skip-alias $cmd`  
else  
echo "No such command"  
return 5  
fi  
}  
cmdCopy() {  
cmdDir=`dirname $1`  
[ -d ${target}${cmdDir} ] || mkdir -p ${target}${cmdDir}  
[ -f ${target}${1} ] || cp $1 ${target}${cmdDir}  
}  
libCopy() {  
for lib in `ldd $1 | grep -o "/[^[:space:]]\{1,\}"`; do  
libDir=`dirname $lib`  
[ -d ${target}${libDir} ] || mkdir -p ${target}${libDir}  
[ -f ${target}${lib} ] || cp $lib ${target}${libDir}  
done  
}  
while true; do  
read -p "Enter a command: " cmd  
if [ "$cmd" == 'quit' ] ;then  
echo "quit"  
exit 0  
fi  
clearCmd $cmd  
[ $? -eq 5 ] && continue  
cmdCopy $cmdPath  
libCopy $cmdPath  
done  

 

转载于:https://www.cnblogs.com/sysk/p/4786475.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值