📄 dllcopy.sh.txt
字号:
#!/bin/sh
###########################################################
# This is a script for copying the lib related to the ldd #
# It is my first shell script,so maybe it is poor in #
# quality. Especially its design is confuse and hard to #
# understood. #
# The program flow : #
# 1. The script first use pipe to store the lib link #
# message that ldd command displays in the file named #
# ldd.tmp. #
# 2. cat it to var x. #
# 3. use the case to switch,judge by the head of x #
# 4. judge whether the file is a link or not #
# 5. 4-->y,get the linked file go to 4,copy the first #
# file #
# 6. 4-->n,copy the first file judge in 4 #
# 7. End #
# #
# If you have any problem or advice, you can mail to me #
# I will try my best to answer the question imediately! #
# Thank you for reading! #
# #
# Author: lookou #
# Email : lookou@gmail.com lxx@cs.hit.edu.cn #
# HIT IBM Tech Center Linux Workgroup #
###########################################################
function cplink()
{
# Three posible forms
# lrwxrwxrwx 1 root root 13 May 4 2005 /lib/libc.so.6 -> libc-2.3.3.so
# -rwxr-xr-x 1 root root 1573232 Oct 28 2003 /lib/libc-2.3.2.so
# lrwxrwxrwx 1 root root 14 May 4 2005 /lib/tls/librt.so.1 -> librt-2.3.3.so
if ! [ -z $rrlink ];then # $rrlink is a two or more layer link
if [ -e $rrlink ]&&[ -n $rrlink ];then
ls -l /$rrlink > ll.txt #get the link file
read line < ll.txt
linkdirname=${line#*/}
linkdirname=${linkdirname%/*}
linkdirname=$linkdirname/
rm ll.txt
elif [ -e /lib/$rrlink ]&&[ -n $rrlink ];then
ls -l /lib/$rrlink > ll.txt #get the link file
read line < ll.txt
rm ll.txt
fi
fi
filename=${line#*/} #cut head the first form will be:lib/libc.so.6 -> libc-2.3.3.so
filename=${filename%% *} #cut tail the first form will be:lib/libc.so.6
filename=/$filename #get the full name of the file :/lib/libc.so.6
if [ -L $filename ];then #if the file is a link file
linkfile=${line##*-> } #get the linked file :libc-2.3.3.so
if [ -e /lib/$linkfile ]&&[ ! -e /tmp/lib/$linkfile ];then
cp -dpR /lib/$linkfile /tmp/lib/$linkfile
fi
if ! [ -e $linkfile ];then
linkfile=$linkdirname$linkfile #connect the linkdir: like /lib/ or /lib/tls/
fi
if [ -e $linkfile ];then #if is a link file, get the relative name and copy it
cp -dpR $linkfile /tmp$linkfile
if [ -L $linkfile ];then # if the linked file is not the final file, it is also a link
rrlink=$linkfile # Copy the link again
cplink
fi
elif [ -L /lib/$linkfile ]&&[ -e /lib/$linkfile ];then # If the link dir is wrong add lib at head
cp -dpR /lib/$linkfile /tmp/lib/$linkfile
rrlink=/lib/$linkfile
cplink
fi
fi
if ! [ -e /tmp/$filename ];then #Copy the link file not the linked!
cp -dpR $filename /tmp/$filename
fi
# clear the variables
linkfile=""
rrlink=""
filename=""
line=""
}
# ldd form:
# librt.so.1 => /lib/tls/librt.so.1 (0x00468000)
ldd $1 > ldd.tmp # store the ldd message
if ! [ -e /tmp/lib/ ];then
mkdir /tmp/lib
fi
for x in $(cat ldd.tmp) # get the message in x
do
case $x in # Create the relate directory
/* ) dir=${x%/*};
dirth=".$dir";
if ! [ -e "$dirth" ];then
mkdir -p $dirth
echo "mkdiring...."
fi
line=$x
cplink
cp -dpR $x /tmp/$x;;
\(*) ;;# The useless form : (0x00468000)
=* ) ;;# The uselsee form : =>
* ) ls -l /lib/$x > ll.txt #get the link file
read line < ll.txt
rm ll.txt
cplink
esac
rm ldd.tmp
done
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -