| | 1 | #!/bin/bash |
|---|
| | 2 | |
|---|
| | 3 | # |
|---|
| | 4 | # Auto-generate requirements for executables (both ELF and a.out) and library |
|---|
| | 5 | # sonames, script interpreters, and perl modules. |
|---|
| | 6 | # |
|---|
| | 7 | |
|---|
| | 8 | ulimit -c 0 |
|---|
| | 9 | |
|---|
| | 10 | # |
|---|
| | 11 | # --- Set needed to 0 for traditional find-requires behavior. |
|---|
| | 12 | needed=1 |
|---|
| | 13 | if [ X"$1" = Xldd ]; then |
|---|
| | 14 | needed=0 |
|---|
| | 15 | elif [ X"$1" = Xobjdump ]; then |
|---|
| | 16 | needed=1 |
|---|
| | 17 | fi |
|---|
| | 18 | |
|---|
| | 19 | # |
|---|
| | 20 | # --- Grab the file manifest and classify files. |
|---|
| | 21 | #filelist=`sed "s/['\"]/\\\&/g"` |
|---|
| | 22 | filelist=`sed "s/[]['\"*?{}]/\\\\\&/g"` |
|---|
| | 23 | exelist=`echo $filelist | xargs -r file | egrep -v ":.* (commands|script) " | \ |
|---|
| | 24 | grep ":.*executable" | cut -d: -f1` |
|---|
| | 25 | scriptlist=`echo $filelist | xargs -r file | \ |
|---|
| | 26 | egrep ":.* (commands|script) " | cut -d: -f1` |
|---|
| | 27 | liblist=`echo $filelist | xargs -r file | \ |
|---|
| | 28 | grep ":.*shared object" | cut -d : -f1` |
|---|
| | 29 | |
|---|
| | 30 | interplist= |
|---|
| | 31 | perllist= |
|---|
| | 32 | pythonlist= |
|---|
| | 33 | tcllist= |
|---|
| | 34 | |
|---|
| | 35 | # |
|---|
| | 36 | # --- Alpha does not mark 64bit dependencies |
|---|
| | 37 | case `uname -m` in |
|---|
| | 38 | alpha*) mark64="" ;; |
|---|
| | 39 | *) mark64="()(64bit)" ;; |
|---|
| | 40 | esac |
|---|
| | 41 | |
|---|
| | 42 | if [ "$needed" -eq 0 ]; then |
|---|
| | 43 | # |
|---|
| | 44 | # --- Executable dependency sonames. |
|---|
| | 45 | for f in $exelist; do |
|---|
| | 46 | [ -r $f -a -x $f ] || continue |
|---|
| | 47 | lib64=`if file -L $f 2>/dev/null | \ |
|---|
| | 48 | grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi` |
|---|
| | 49 | ldd $f | awk '/=>/ { |
|---|
| | 50 | if ($1 !~ /libNoVersion.so/ && $1 !~ /4[um]lib.so/ && $1 !~ /libredhat-kernel.so/) { |
|---|
| | 51 | gsub(/'\''"/,"\\&",$1); |
|---|
| | 52 | printf "%s'$lib64'\n", $1 |
|---|
| | 53 | } |
|---|
| | 54 | }' |
|---|
| | 55 | done | xargs -r -n 1 basename | sort -u |
|---|
| | 56 | |
|---|
| | 57 | # |
|---|
| | 58 | # --- Library dependency sonames. |
|---|
| | 59 | for f in $liblist; do |
|---|
| | 60 | [ -r $f ] || continue |
|---|
| | 61 | lib64=`if file -L $f 2>/dev/null | \ |
|---|
| | 62 | grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi` |
|---|
| | 63 | ldd $f | awk '/=>/ { |
|---|
| | 64 | if ($1 !~ /libNoVersion.so/ && $1 !~ /4[um]lib.so/ && $1 !~ /libredhat-kernel.so/) { |
|---|
| | 65 | gsub(/'\''"/,"\\&",$1); |
|---|
| | 66 | printf "%s'$lib64'\n", $1 |
|---|
| | 67 | } |
|---|
| | 68 | }' |
|---|
| | 69 | done | xargs -r -n 1 basename | sort -u |
|---|
| | 70 | fi |
|---|
| | 71 | |
|---|
| | 72 | # |
|---|
| | 73 | # --- Script interpreters. |
|---|
| | 74 | for f in $scriptlist; do |
|---|
| | 75 | [ -r $f -a -x $f ] || continue |
|---|
| | 76 | interp=`head -n 1 $f | sed -e 's/^\#\![ ]*//' | cut -d" " -f1` |
|---|
| | 77 | interplist="$interplist $interp" |
|---|
| | 78 | case $interp in |
|---|
| | 79 | */perl) perllist="$perllist $f" ;; |
|---|
| | 80 | esac |
|---|
| | 81 | done |
|---|
| | 82 | [ -n "$interplist" ] && { echo "$interplist" | tr '[:blank:]' \\n | sort -u ; } |
|---|
| | 83 | |
|---|
| | 84 | # |
|---|
| | 85 | # --- Add perl module files to perllist. |
|---|
| | 86 | for f in $filelist; do |
|---|
| | 87 | [ -r $f -a "${f%.pm}" != "${f}" ] && perllist="$perllist $f" |
|---|
| | 88 | done |
|---|
| | 89 | |
|---|
| | 90 | # |
|---|
| | 91 | # --- Weak symbol versions (from glibc). |
|---|
| | 92 | [ -n "$mark64" ] && mark64="(64bit)" |
|---|
| | 93 | for f in $liblist $exelist ; do |
|---|
| | 94 | [ -r $f ] || continue |
|---|
| | 95 | lib64=`if file -L $f 2>/dev/null | \ |
|---|
| | 96 | grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi` |
|---|
| | 97 | objdump -p $f | awk 'BEGIN { START=0; LIBNAME=""; needed='$needed'; } |
|---|
| | 98 | /^$/ { START=0; } |
|---|
| | 99 | /^Dynamic Section:$/ { START=1; } |
|---|
| | 100 | (START==1) && /NEEDED/ { |
|---|
| | 101 | if (needed) { |
|---|
| | 102 | if ("'$lib64'" != "") { |
|---|
| | 103 | sub(/$/, "()'$lib64'", $2) ; |
|---|
| | 104 | } |
|---|
| | 105 | print $2 ; |
|---|
| | 106 | } |
|---|
| | 107 | } |
|---|
| | 108 | (START==2) && /^[A-Za-z]/ { START=3; } |
|---|
| | 109 | /^Version References:$/ { START=2; } |
|---|
| | 110 | (START==2) && /required from/ { |
|---|
| | 111 | sub(/:/, "", $3); |
|---|
| | 112 | LIBNAME=$3; |
|---|
| | 113 | } |
|---|
| | 114 | (START==2) && (LIBNAME!="") && ($4!="") && (($4~/^GLIBC_*/) || ($4~/^GCC_*/)) { |
|---|
| | 115 | print LIBNAME "(" $4 ")'$lib64'"; |
|---|
| | 116 | } |
|---|
| | 117 | ' |
|---|
| | 118 | done | sort -u |
|---|
| | 119 | |
|---|
| | 120 | # |
|---|
| | 121 | # --- Perl modules. |
|---|
| | 122 | [ -x /usr/lib/rpm/perl.req -a -n "$perllist" ] && \ |
|---|
| | 123 | echo $perllist | tr '[:blank:]' \\n | /usr/lib/rpm/perl.req | sort -u |
|---|
| | 124 | |
|---|
| | 125 | # |
|---|
| | 126 | # --- Python modules. |
|---|
| | 127 | [ -x /usr/lib/rpm/python.req -a -n "$pythonlist" ] && \ |
|---|
| | 128 | echo $pythonlist | tr '[:blank:]' \\n | /usr/lib/rpm/python.req | sort -u |
|---|
| | 129 | |
|---|
| | 130 | # |
|---|
| | 131 | # --- Tcl modules. |
|---|
| | 132 | [ -x /usr/lib/rpm/tcl.req -a -n "$tcllist" ] && \ |
|---|
| | 133 | echo $tcllist | tr '[:blank:]' \\n | /usr/lib/rpm/tcl.req | sort -u |
|---|
| | 134 | |
|---|
| | 135 | exit 0 |