Debian Codegraph @

dist/net-snmp-solaris-build/elfdepend.sh

raw
1 #!/bin/ksh
2 #
3 # elfdepend.sh
4 #
5 # given a path, this scripts searches for ELF binaries and libraries
6 # and generates package dependency file entries according to ther dependencies
7 #
8 # Usage: elfdepend <ELF-binary>|<directory>
9 #
10 # 2002/11 [email protected]
11 #
12 # /var/sadm/install/contents format:
13 #
14 # /dev d none 0775 root sys SUNWcsr SUNWcsd
15 # path type class mode owner group packages
16 # /etc/.login f renamenew 0644 root sys 516 37956 904647695 SUNWcsr
17 # /etc/acct/holidays e preserve 0664 bin bin 289 22090 904647603 SUNWaccr
18 # path type class mode owner group x x x packages
19 # /bin=./usr/bin s none SUNWcsr
20 # path=link type class packages
21 # /devices/pseudo/clone@0:hme c none 11 7 0600 root sys SUNWcsd
22 # path type class x x owner mode packages
23 #
24 # types e (sed), v (volatile) have same format like type f (file)
25 # type l (hardlink) has same format like type s (symlink)
26 #
27 prog=`basename $0`
28 LAST_CHANCE=/opt/OSS/lib
29
30 if [ -d "$1" ] ; then
31 find $1 -type f -exec file {} \;
32 elif [ -x "$1" ] ; then
33 file $1
34 else
35 echo 1>&2 "usage: $0 <directory>|<ELF executable>"
36 exit 1
37 fi | awk '$2 == "ELF" { print }' | cut -d: -f1 |\
38 while read elf
39 do
40 ldd "$elf" | while read lib x path
41 do
42 [ -z "$path" ] && continue
43 if [ "$path" = '(file not found)' ]
44 then
45 if [ -x $LAST_CHANCE/$lib ]
46 then
47 path="$LAST_CHANCE/$lib"
48 else
49 echo "# $prog: $lib $x $path"
50 continue # not found
51 fi
52 fi
53 echo "$path"
54 # need symlink handling here - see /usr/platform/SUNW,*/lib/*
55 done
56 done | sort -u | while read libpath other
57 do
58 [ "$libpath" = "#" ] && echo "$libpath $other" && continue # error message
59 set -- `grep "^$libpath[ =]" /var/sadm/install/contents | head -1`
60 path=$1; type=$2
61 case $type in
62 f) # file
63 shift 9 # first package
64 ;;
65 s|l) # link
66 shift 3 # first package
67 ;;
68 '') # not found
69 echo "# $prog: $libpath is not associated with any package"
70 continue
71 ;;
72 *) # dubious file type
73 echo "# $prog: path $1 has dubious file type $2"
74 continue
75 ;;
76 esac
77 set -- `echo $1 | tr : ' '`
78 echo $1 # strip off classes
79 done | sort -u | while read pkg other
80 do
81 if [ "$pkg" = "#" ] ; then # error message
82 echo 1>&2 "$other" # goes to stderr
83 continue
84 fi
85 eval `pkgparam -v $pkg PKG NAME`
86 printf "P %-15s%s\n" "$PKG" "$NAME"
87 done