summaryrefslogtreecommitdiff
path: root/scripts/find-prov.pl
blob: f430c50fbc4ec53a85755998fb28093bc8ab30a3 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/sh

# This script reads filenames from STDIN and outputs any relevant provides
# information that needs to be included in the package.

PATH=/usr/bin:/usr/ccs/bin:/usr/sbin:/sbin:/usr/local/bin;
export PATH;

javadeps_args='--provides --rpmformat --keywords --starprov'


IGNORE_DEPS="@"
BUILDROOT="/"



# Loop over all args

while :
do

# Break out if there are no more args
	case $# in
	0)
		break
		;;
	esac

# Get the first arg, and shuffle
	option=$1
	shift

# Make all options have two hyphens
	orig_option=$option	# Save original for error messages
	case $option in
	--*) ;;
	-*) option=-$option ;;
	esac


	case $option in
	--buildroot)
		BUILDROOT=$1
		shift
		;;
	--ignore_deps)
		IGNORE_DEPS=$1
		shift
		;;
	--help)
		echo $usage
		exit 0
		;;
	*)
		echo "$0: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
		exit 1
		;;
	esac
done







for file in `cat -`
do

# this section is for processing based on the interpreter specified in
# the '#!' line.

case `get_magic $file` in 

bash)
    print_deps --identifier executable $file
    print_deps --identifier executable --basename $file
;;

sh)
    print_deps --identifier executable $file
    print_deps --identifier executable --basename $file
;;

perl)
    perl.prov $file;
;;

wish)
    print_deps --identifier tcl $file
    print_deps --identifier tcl --basename $file
;;


esac


# this section is for processing based on filename matching.  It is
# crude but needed as many library types have no easily identifiable
# '#!' line

case $file in 

# We can not count on finding a SONAME in third party Libraries though
# they tend to include softlinks with the correct SONMAE name.  We
# must assume anything with a *\.so* and is of type 'dynamic lib' is a
# library.  This scriptlet works because 'file' follows soft links.


*lib*.so*)
    /usr/ucb/file -L $file 2>/dev/null | \
	grep "ELF.*dynamic lib" | cut -d: -f1 | \
    	xargs -n 1 basename | print_deps --identifier so;

    # keep this for backward compatibility till we have converted
    # everything.

    /usr/ucb/file -L $file 2>/dev/null | \
	grep "ELF.*dynamic lib" | cut -d: -f1 | \
    	xargs -n 1 basename;
;;

# Java jar files are just a special kind of zip files.
# Sun OS 5.5.1 does not understand zip archives, it calls them 'data'
# Sun OS 5.6 has this line in /etc/magic
# 0       string          PK\003\004      ZIP archive

*.jar)

    unzip -p $file |\
    javadeps $javadeps_args -;

;;

# there are enough jar files out there with zip extensions that we
# need to have a separate entry

*.zip)

    unzip -p $file |\
    javadeps $javadeps_args -;

;;

# Java Class files
# Sun OS 5.6 has this line in /etc/magic
# 0       string          \312\376\272\276        java class file

*.class) 

    javadeps $javadeps_args $file;

;;



# Perl libraries are hard to detect.  Use file endings.

*.pl) 

    perl.prov $file;

    # pl files are often required using the .pl extension
    # so provide that name as well

    print_deps --identifier perl --basename $file
;;

*.pm) 

    perl.prov $file;
;;

*.ph)

    # ph files do not use the package name inside the file.
    # perlmodlib  documentation says:

    #       the .ph files made by h2ph will probably end up as
    #       extension modules made by h2xs.

    # so do not expend much effort on these.

    print_deps --identifier perl --basename $file

;;

# tcl libraries are hard to detect.  Use file endings.

*.tcl) 

    print_deps --identifier tcl $file
    print_deps --identifier tcl --basename $file
;;



*)

    # Dependencies for html documenets are a bit ill defined. Lets try
    # using file endings like the browsers do.
    # precise globbing is hard so I use egrep instead of the case statement.

hfile=`basename $file | egrep '\.((cgi)|(ps)|(pdf)|(png)|(jpg)|(gif)|(tiff)|(tif)|(xbm)|(html)|(htm)|(shtml)|(jhtml))$'`;

	if [ "${hfile}" != "" ]
	then
	print_deps --identifier http --basename $file
	fi

	# all files are candidates for being an executable.  Let the
	# magic.prov script figure out what should be considered
	# execuables.

	magic.prov  --buildroot=$BUILDROOT $file

;;


esac

done | sort -u | egrep -v \'$IGNORE_DEPS\'