开始试着修改initrd做miniLinux,需要向其中添加命令,慢慢完善。但是用ldd命令查看哪些大串的库再拷贝实在是纠结~

自动实现一下:

描述:

  输入命令后,自动寻找命令位置,将命令拷到对应根位置后,并且查询到所需的库文件,逐一的拷贝到定义好的位置。

    第二次修改给脚本添加了了参数,实现了可以在脚本中调用,并且直接传 递命令选项给脚本的功能;但是用户使用的时候可以指定以交互式方式进行;
  缺陷:能够实现的拷贝有局限,由于对/lib、/usr/lib、 /usr/local/lib几个位置区分比较麻烦,
现在脚本还进能实现拷贝/lib下的库到对应威之下的功能;有时间了会不断改进;
  1. #!/bin/bash
  2. #Author: Mo
  3. #Descripution: auto copy libs to specify site.
  4. #Date & Time: 2011-03-10-20:04:31
    #Version : 1.2.1
    #

    sysroot=/mnt/sysroot
    file=`mktemp /tmp/lddtmp.XXXX`

    mytrap() {
    rm -rf ${file}
    echo -e "\nQuit........\n "
    exit 1
    }
    trap "mytrap" SIGINT

  5. #read -p "Input your command: " comm
    while getopts ':s:u' SWITCH;do
    case $SWITCH in
    s) comm=$OPTARG
    echo "$OPTARG"
    ;;
    u) read -p "Input your command: " comm
    ;;
    \?) echo -e "Unknown option...\nUSAG: ./autolib.sh [-u]|[-s command]."
    exit 1
    ;;
    esac
    done

    if ! which $comm &>/dev/null ;then
    echo -e "\033[31mNo command:\033[0m ${comm}"
    exit 1
    else
    cpath=`which --skip-alias ${comm}`
    ldd ${cpath} | grep ".*[[:space:]]/.*[[:space:]]" | sed "s@.*[[:space:]]\(/.*[[:space:]]\)(.*)@\1@g" > ${file}

    #cp command
    cp -u ${cpath} ${sysroot}${cpath}
    sync

    #cp libs
    #NOTICE: this shell below can onlp copy libs from directory /lib , ro it may case problem;
    while read LINE ;do
    if [ -h $LINE ];then
    orglib=`ls -l $LINE | awk '{printf $11}'`
    /bin/cp -d $LINE "${sysroot}/lib"
    /bin/cp -d /lib/${orglib} "${sysroot}/lib"
    sync
    else
    /bin/cp -d $LINE "${sysroot}/lib"
    fi
    done < ${file}
    sync;sync

    echo -e "Path: " ${cpath} "\nAll have synced."
    fi

    #do some cleaning...
    rm -f ${file}

    wait
    echo "Copy has done."