-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopycmd.sh
More file actions
51 lines (47 loc) · 1.38 KB
/
copycmd.sh
File metadata and controls
51 lines (47 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#
#*****************************************************
#Author: huwei
#QQ: 115185849
#Date: 2020-05-20
#FileName: copycmd.sh
#Description:
#URL: http://nanyuzuo.xin/hexo
#Copyright (c):2020 All rights reserved
#****************************************************
copy_cmd() {
local cmd_destdir=$destdir$(dirname $(which $1))
if [ ! -d $cmd_destdir ];then
mkdir -pv $cmd_destdir
fi
cp -v $(which $1) $cmd_destdir
}
copy_libfile() {
ldd $(which $1) |grep -oE "/.* " | while read libfile
do
local lib_destdir=$destdir$(dirname $libfile)
local lib_destfile=$destdir$libfile
if [ -e $lib_destfile ];then
continue
elif [ -d $lib_destdir ];then
cp -v $libfile $lib_destdir
else
mkdir -pv $lib_destdir
cp -v $libfile $lib_destdir
fi
done
}
destdir=/mnt/root
if [ ! -d $destdir ];then
mkdir $destdir
fi
while true;do
echo -ne "\e[33mPlease input a execute command:\e[0m"
read cmd
if [ "$cmd" == quit ];then
exit
fi
which $cmd &> /dev/null || { echo $cmd not exist;continue; }
copy_cmd $cmd
copy_libfile $cmd
done