chroot下二进制程序迁移

 

#!/bin/bash

#

#define function
#Copy binary program
cp_bin(){
  cmd_dir=${cmd_path%/*}
  [ ! -d /mnt/sysroot$cmd_dir ] && mkdir -p /mnt/sysroot$cmd_dir &> /dev/null
  if [ ! -e /mnt/sysroot$cmd_path ];then
    cp $cmd_path /mnt/sysroot$cmd_dir
  else
    echo "Command already exists."
  return 1
  fi
}
#Copy shared libraries
cp_lib(){
  while read lib_line;do
  lib_dir=${lib_line%/*}
  [ ! -d /mnt/sysroot$lib_dir ] && mkdir -p /mnt/sysroot$lib_dir &> /dev/null
  if [ ! -e /mnt/sysroot$lib_line ];then
    cp $lib_line /mnt/sysroot$lib_dir
  fi
done < /tmp/cmd_lib

}

#main
read -p "Please enter a name for the executable command:" cmd
cmd=${cmd:=bash}
until [ $cmd == "quit" ];do
  if which $cmd &> /dev/null ;then
    cmd_path=`which $cmd | grep -o "/[^[:space:]]\+$"`
    cp_bin
  elif help $cmd &> /dev/null;then
    echo "This is the bash built-in command."
    read -p "Please enter a name for the executable command:" cmd
    continue
  else
    read -p "Command does not exits,please re_enter,or exit(quit):" cmd
    continue
  fi
  if [ $? -eq 0 ];then
    ldd $cmd_path | grep -o "/[^[:space:]]\+" > /tmp/cmd_lib
    cp_lib
  fi
  read -p "To complete the copy command,continue with the next command,or exit(quit):" cmd
  cmd=${cmd:=bash}
done

 

posted @ 2016-05-08 08:54  sed_'s/M18/黑匣子/'  阅读(251)  评论(0编辑  收藏  举报