Linux Shell busybox 脚本安装工具

2019-07-13 09:20发布

构建linux系统,需要加入busybox工具,但又不想影响原有同名程序,为便于安装 BusyBox到指定系统目录,写了个bash shell脚本。 立贴是怕自己以后找不到,欢迎大家使用。 脚本名称随意,我用 bb-cp.sh 第一个参数指向一个busybox 临时安装目录, 第二个参数指向系统文件所在路径 如果已经存在同名执行文件,就不再创建软连接,保留原有程序,例如,已经有util-linux版本的 lsmod,就不会用busybox版本的覆盖它。 第一个目录只存放busybox有关执行文件+软链接文件,要生成这种目录,只要在编译安装busybox时指定一个空文件夹就可以   mkdir -p /tmp/bb make CONFIG_PREFIX=/tmp/bb install 此处参考了busybox文档 http://www.tin.org/bin/man.cgi?section=1&topic=busybox   After the compile has finished, you should use 'make install' to install BusyBox. This will install the 'bin/busybox' binary, in the target directory specified by CONFIG_PREFIX. CONFIG_PREFIX can be set when configuring BusyBox, or you can specify an alternative location at install time (i.e., with a command line like 'make CONFIG_PREFIX=/tmp/foo install'). If you enabled any applet installation scheme (either as symlinks or hardlinks), these will also be installed in the location pointed to by CONFIG_PREFIX.   #!/bin/bash if [ $# -lt 2 ]; then echo "Usage:" echo " $0 " echo "" exit 1 fi BB_PATH=$1 II_PATH=$2 if [ ! -x "${BB_PATH}/bin/busybox" ]; then echo "Error! can not find ${BB_PATH}/bin/busybox. ${BB_PATH} is invalid." echo "" echo "Usage:" echo " $0 " echo "" exit 1 fi mkdir -p ${II_PATH}/bin/ cp -a ${BB_PATH}/bin/busybox ${II_PATH}/bin/ for folder in bin sbin usr/bin usr/sbin; do src=${BB_PATH}/${folder} dst=${II_PATH}/${folder} mkdir -p ${dst} for app in ${src}/*; do if [ ! -e ${dst}/${app##*/} ]; then echo "cp -a ${app} ${dst}/" cp -a ${app} ${dst}/ else echo "${dst}/${app##*/} was existed. no action" fi done read -p " $dst work completed. press any key to continue..." WAIT done