#!/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
时间: 2024-10-08 00:34:41