summaryrefslogtreecommitdiff
path: root/scripts/vpkg-provides.sh
blob: c15f080f13a8401dd38e5e5a163371fa1f991fd5 (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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!/bin/sh

#
# Original Author: Tim Mooney (mooney@plains.NoDak.edu)
# Improvements by: Ken Estes <kestes@staff.mail.com>
# 
# This file is distributed under the terms of the GNU General Public License
#

# vpkg-provides.sh is part of RPM, the Red Hat Package Manager.

# vpkg-provides.sh searches a list of directories (based on what OS
# it's being executed on) for shared libraries and interpreter files
# that have been installed by some packaging system other than RPM.
# It then generates a spec file that can be used to build a "virtual
# package" that provides all of these things without actually
# installing any files.  The spec file in effect tells rpm what it
# needs to know about operating system files which are not under rpm
# control.  This makes it much easier to use RPM on non-Linux systems.

# By default the script also generates a %verifyscript (with hard
# coded $shlib_dirs, $ignore_dirs values) which will check that the
# checksum of each file in the directories searched has not changed
# since the package was built.

# Comments: This script is a quick hack.  A better solution is to use the
# vendor's package management commands to actually query what's installed, and
# build one or more spec files based on that.  This is something
# I intend to write, probably in perl, but the need for something like this
# first effort was great, so I didn't want to wait until the better solution
# was done.

# The complete specfile will be sent to stdout.

# you will need to create a spec_header for the virtual package.  This
# header will provide such specfile information as:
#
#  Summary: 
#  Name: 
#  Version: 
#  Release: 
#  Copyright: 
#  Group: 
#  Source: 


# most of the command line arguments have defaults

usage="usage: $0 --spec_header '/path/to/os-base-header.spec' \n"
usage="$usage\t[--find_provides '/path/to/find-provides']\n"
usage="$usage\t[--shlib_dirs 'dirs:which:contain:shared:libs']\n"
usage="$usage\t[--ignore_dirs 'grep-E|pattern|of|paths|to|ignore']\n"

# these two should be unnessary as the regular dependency analysis
# should take care of interpreters as well as shared libraries.

usage="$usage\t[--interp_dirs 'dirs:which:contain:interpreters']\n"
usage="$usage\t[--interps 'files:to:assume:are:installed']\n"
usage="$usage\t[--no_verify]\n"


# this command may not be portable to all OS's, does something else
# work? can this be set in the case $osname statement?

sum_cmd="xargs cksum"

date=`date`
hostname=`uname -n`

# if some subdirectories of the system directories needs to be ignored
# (eg /usr/local is a subdirectory of /usr but should not be part of
# the virtual package) then call this script with ignore_dirs set to a
# valid grep -E pattern which discribes the directories to ignored.

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bsd
export PATH


#
# The (OS independent) default values.
#
spec_header='/usr/lib/rpm/os-base-header.spec';
interps="sh:csh:ksh:dtksh:wish:tclsh:perl:awk:gawk:nawk:oawk"
find_provides='/usr/lib/rpm/find-provides';

    # no file names begin with this character so it is a good default
    # for dirs to ignore.  

ignore_dirs="@"


osname=`uname -s`
if test $? -ne 0 || test X$osname = X ; then
	echo "I can't determine what platform this is.  Exiting"
	exit 1
fi


#
# Set OS dependent defaults
#
case $osname in
	OSF1)
		shlib_dirs='/shlib:/usr/shlib:/usr/dt/lib:/usr/opt'
		interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/bin/posix'
		;;
	HP-UX)
		shlib_dirs='/usr/shlib:/usr/dt/lib:/opt'
		shlib_dirs="$shlib_dirs:/usr/bms:/usr/obam:/usr/sam"
		interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/bin/posix'
		;;
	AIX)
		shlib_dirs='/usr/lib:/usr/ccs/lib:/usr/dt/lib:/usr/lpp:/usr/opt'
		interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin'
		;;
	SunOS)
		shlib_dirs='/etc/lib:/etc/vx:/opt:/usr/lib:/usr/ccs/lib:/usr/dt/lib'
		shlib_dirs="$shlib_dirs:/usr/4lib:/usr/openwin/lib:/usr/snadm/lib"
		shlib_dirs="$shlib_dirs:/usr/ucblib:/usr/xpg4/lib"
		interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/xpg4/bin'
		;;
	IRIX|IRIX64)
		shlib_dirs='/lib:/usr/lib:/usr/lib32:/usr/lib64'
		# Irix always makes me laugh...
		shlib_dirs="$shlib_dirs:/usr/ToolTalk:/usr/xfsm:/usr/SpeedShop"
		shlib_dirs="$shlib_dirs:/usr/sgitcl:/usr/SGImeeting:/usr/pcp/lib"
		shlib_dirs="$shlib_dirs:/usr/Motif-2.1"
		interp_dirs='/bin:/usr/bin:/sbin:/usr/sbin:/usr/dt/bin'
		;;
	*)
		echo "I'm sorry.  I haven't been configured yet to work on $osname."
		echo "Please poke around your system and try figure out what directories"
		echo "I should be searching for shared libraries.  Once you have this"
		echo "information, email it to rpm-list@redhat.com, so that your OS"
		echo "will be supported by some future version of this script."
		echo ""
		echo "Thanks!"
		echo
		exit 2
		;;
esac


# allow the user to change defaults with the command line arguments.

# 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
	--spec_header)
		spec_header=$1
		shift
		;;
	--ignore_dirs)
		ignore_dirs=$1
		shift
		;;
	--find_provides)
		find_provides=$1
		shift
		;;
	--shlib_dirs)
		shlib_dirs=$1
		shift
		;;
	--interp_dirs)
		interp_dirs=$1
		shift
		;;
	--interps)
		interps=$1
		shift
		;;
	--no_verify)
		no_verify=1
		;;
	--help)
		echo $usage
		exit 0
		;;
	*)
		echo "$0: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
		exit 1
		;;
	esac
done


# consistancy checks on the arguments

if [ ! -f $spec_header ]; then
	echo "You must pass me the full path to the partial spec file"
	echo "as my first argument, since this file does not appear in the"
	echo "default location of $default_spec_header"
	echo
	echo $usage
	echo
	exit 9
fi


if [ ! -f $find_provides ]; then
	echo "You must pass me the full path to the find-provides script as my"
	echo "second argument, since find-provides does not appear in the"
	echo "default location of $default_find_provides"
	echo
	echo $usage
	echo
	exit 9
fi



provides_tmp=${TMPDIR:-/tmp}/provides.$$
if test -f $provides_tmp ; then
	echo "$provides_tmp already exists.  Exiting."
	exit 11
fi

#
# iterate through all the directories in shlib_dirs, looking for shared
# libraries
#
for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
do
	find $d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $find_provides >> $provides_tmp
done

sum_tmp=${TMPDIR:-/tmp}/sum.$$
if test -f $sum_tmp ; then
	echo "$sum_tmp already exists.  Exiting."
	exit 11
fi

#
# iterate through all the directories in shlib_dirs, record the sum
#
for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
do
	find $d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $sum_cmd >> $sum_tmp
done


#
# output the initial part of the spec file
#
cat $spec_header

#
# output the 'Provides: ' part of the spec file
#
{
    #
    # Output the shared libraries
    #
    for f in `cat $provides_tmp | sort -u`
    do
	echo "Provides: $f"
    done

    #
    # Output the available shell interpreters
    #
    for d in `echo $interp_dirs | sed -e 's/:/ /g'`
    do
	for f in `echo $interps | sed -e 's/:/ /g'`
	do
		if test -f $d/$f ; then
			echo "Provides: $d/$f"
		fi
	done
    done
} | sed -e 's/%/%%/g'

#
# Output the discription of the spec file
#

cat <<_EIEIO_


%description
This is a virtual RPM package.  It contains no actual files.  It uses the
\`Provides' token from RPM 3.x and later to list many of the shared libraries
and interpreters that are part of the base operating system and associated
OS packages for $osname.

This virtual package was constructed based on the vendor/system software
installed on the '$osname' machine named '$hostname', as of the date
'$date'.

Input to the script:

                spec_header=$spec_header
                ignore_dirs=$ignore_dirs
                find_provides=$find_provides
                shlib_dirs=$shlib_dirs
                interp_dirs=$interp_dirs
                interps=$interps

_EIEIO_

#
# Output the build sections of the spec file
#

echo '%prep'
echo '# nothing to do'
echo '%build'
echo '# nothing to do'
echo '%install'
echo '# nothing to do'
echo '%clean'
echo '# nothing to do'

if [ -z "${no_verify}" ]; then

#
# Output the optional verify section of the spec file
#

cat <<_EIEIO_

%verifyscript

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bsd
export PATH

sum_current_tmp=\${TMPDIR:-/tmp}/rpm.sum.current.\$\$
if test -f \$sum_current_tmp ; then
	echo "\$sum_current_tmp already exists.  Exiting."
	exit 11
fi

sum_package_tmp=\${TMPDIR:-/tmp}/rpm.sum.package.\$\$
if test -f \$sum_package_tmp ; then
	echo "\$sum_package_tmp already exists.  Exiting."
	exit 11
fi

for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
do
	find \$d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $sum_cmd >> \$sum_current_tmp
done

cat >\$sum_package_tmp <<_EOF_
_EIEIO_

# the contents of the temporary file are hardcoded into the verify
# script so that the file can be reproduced at verification time.

cat $sum_tmp | sed -e 's/%/%%/g'

cat <<_EIEIO_
_EOF_


cmp \$sum_package_tmp \$sum_current_tmp 

if [ \$? -ne 0 ]; then
	echo"Differences found by: cmp \$sum_package_tmp \$sum_current_tmp"
	exit \$?
fi

_EIEIO_

# end optional verify section
fi

#
# Output the files section of the spec file
#

echo '%files'
echo '# no files in a virtual package'

exit 0