while [ $# -gt 0 ]; do # Until you run out of parameters... case "$1" in --make) ACTION=make ;; --check-and-use) ACTION=check-and-use ;; --help) echo "Options:" echo " --make [Make a dependency package]" echo " --check-and-use [Check and use dependent packages]" echo " --help [show help]" exit ;; *) echo >&2 'copyDependencies.sh:' $"unrecognized option" "\`$1'" echo >&2 $"Try \`copyDependencies.sh --help' for more information." exit 1 ;; esac shift # Check next set of parameters. done
#ldconfig -p列出当前部署环境的动态库,如果没有则将动态库拷贝到APPDEP目录 for filename in "$APPDEPALL/"* ; do basefilename=`basename "$filename"` ldre=`ldconfig -p | grep "/$basefilename\$"` if [ -z "$ldre" ]; then echo copy "$basefilename" to "$APPDEP/" \cp -L -n "$filename" "$APPDEP/" fi done
#有时虽然有同名的动态库,但是两个库的版本信息不一致导致程序不能启动,这是需要通过一下命令检测版本信息,如果缺少版本信息则将动态库拷贝到APPDEP目录 #以下命令参考了rpm的find-requires脚本,路径是/usr/lib/rpm/find-requires whereisobjdump=`whereis objdump` if [ ! "$whereisobjdump" = "objdump:" ]; then for checkobj in "$APPDIR/server/bin/mgserver" "$APPDIR/webserverextensions/apache2/bin/httpd" ; do reqverinfos=`objdump -p "$checkobj" | awk 'BEGIN { START=0; LIBNAME=""; } /^[ ]{0,}required from .*:$/ { START=1; } (START==1) && /required from / { sub(/:/, "", $3); LIBNAME=$3; } (START==1) && (LIBNAME!="") && ($4!="") { print LIBNAME" ----- "$4; } '` echo "$reqverinfos" | while read reqverinfo do LIBNAME=`echo $reqverinfo | awk -F " ----- " '{print $1}'` VERSION=`echo $reqverinfo | awk -F " ----- " '{print $2}'` if [ ! X"$LIBNAME" = X -a ! X"$VERSION" = X -a ! -f "$APPDEP/$LIBNAME" ]; then ldre=`ldconfig -p | grep "/$LIBNAME\$" | awk -F " => " '{print $2}'` findre=`strings "$ldre" | grep "^$VERSION\$"` if [ -z "$findre" ]; then echo copy "$LIBNAME" to $APPDEP/ \cp -L -n "$APPDEPALL/$LIBNAME" "$APPDEP/" fi fi done done else echo "objdump executable file not found, please check the dynamic library version information by yourself" fi