Merge "allow rpm to custom systemd installation" into tizen
[platform/upstream/rpm.git] / scripts / vpkg-provides.sh
1 #!/bin/sh
2
3 #
4 # Original Author: Tim Mooney (mooney@plains.NoDak.edu)
5 # Improvements by: Ken Estes <kestes@staff.mail.com>
6
7 # This file is distributed under the terms of the GNU General Public License
8 #
9
10 # vpkg-provides.sh is part of RPM, the Red Hat Package Manager.
11
12 # vpkg-provides.sh searches a list of directories (based on what OS
13 # it's being executed on) for shared libraries and interpreter files
14 # that have been installed by some packaging system other than RPM.
15 # It then generates a spec file that can be used to build a "virtual
16 # package" that provides all of these things without actually
17 # installing any files.  The spec file in effect tells rpm what it
18 # needs to know about operating system files which are not under rpm
19 # control.  This makes it much easier to use RPM on non-Linux systems.
20
21 # By default the script also generates a %verifyscript (with hard
22 # coded $shlib_dirs, $ignore_dirs values) which will check that the
23 # checksum of each file in the directories searched has not changed
24 # since the package was built.
25
26 # Comments: This script is a quick hack.  A better solution is to use the
27 # vendor's package management commands to actually query what's installed, and
28 # build one or more spec files based on that.  This is something
29 # I intend to write, probably in perl, but the need for something like this
30 # first effort was great, so I didn't want to wait until the better solution
31 # was done.
32
33 # The complete specfile will be sent to stdout.
34
35 # you will need to create a spec_header for the virtual package.  This
36 # header will provide such specfile information as:
37 #
38 #  Summary: 
39 #  Name: 
40 #  Version: 
41 #  Release: 
42 #  Copyright: 
43 #  Group: 
44 #  Source: 
45
46
47 # most of the command line arguments have defaults
48
49 usage="usage: $0 --spec_header '/path/to/os-base-header.spec' \n"
50 usage="$usage\t[--find_provides '/path/to/find-provides']\n"
51 usage="$usage\t[--shlib_dirs 'dirs:which:contain:shared:libs']\n"
52 usage="$usage\t[--ignore_dirs 'grep-E|pattern|of|paths|to|ignore']\n"
53
54 # these two should be unnessary as the regular dependency analysis
55 # should take care of interpreters as well as shared libraries.
56
57 usage="$usage\t[--interp_dirs 'dirs:which:contain:interpreters']\n"
58 usage="$usage\t[--interps 'files:to:assume:are:installed']\n"
59 usage="$usage\t[--no_verify]\n"
60
61
62 # this command may not be portable to all OS's, does something else
63 # work? can this be set in the case $osname statement?
64
65 sum_cmd="xargs cksum"
66
67 date=`date`
68 hostname=`uname -n`
69
70 # if some subdirectories of the system directories needs to be ignored
71 # (eg /usr/local is a subdirectory of /usr but should not be part of
72 # the virtual package) then call this script with ignore_dirs set to a
73 # valid grep -E pattern which discribes the directories to ignored.
74
75 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bsd
76 export PATH
77
78
79 #
80 # The (OS independent) default values.
81 #
82 spec_header='/usr/lib/rpm/os-base-header.spec';
83 interps="sh:csh:ksh:dtksh:wish:tclsh:perl:awk:gawk:nawk:oawk"
84 find_provides='/usr/lib/rpm/find-provides';
85
86     # no file names begin with this character so it is a good default
87     # for dirs to ignore.  
88
89 ignore_dirs="@"
90
91
92 osname=`uname -s`
93 if test $? -ne 0 || test X$osname = X ; then
94         echo "I can't determine what platform this is.  Exiting"
95         exit 1
96 fi
97
98
99 #
100 # Set OS dependent defaults
101 #
102 case $osname in
103         OSF1)
104                 shlib_dirs='/shlib:/usr/shlib:/usr/dt/lib:/usr/opt'
105                 interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/bin/posix'
106                 ;;
107         HP-UX)
108                 shlib_dirs='/usr/shlib:/usr/dt/lib:/opt'
109                 shlib_dirs="$shlib_dirs:/usr/bms:/usr/obam:/usr/sam"
110                 interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/bin/posix'
111                 ;;
112         AIX)
113                 shlib_dirs='/usr/lib:/usr/ccs/lib:/usr/dt/lib:/usr/lpp:/usr/opt'
114                 interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin'
115                 ;;
116         SunOS)
117                 shlib_dirs='/etc/lib:/etc/vx:/opt:/usr/lib:/usr/ccs/lib:/usr/dt/lib'
118                 shlib_dirs="$shlib_dirs:/usr/4lib:/usr/openwin/lib:/usr/snadm/lib"
119                 shlib_dirs="$shlib_dirs:/usr/ucblib:/usr/xpg4/lib"
120                 interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/xpg4/bin'
121                 ;;
122         IRIX|IRIX64)
123                 shlib_dirs='/lib:/usr/lib:/usr/lib32:/usr/lib64'
124                 # Irix always makes me laugh...
125                 shlib_dirs="$shlib_dirs:/usr/ToolTalk:/usr/xfsm:/usr/SpeedShop"
126                 shlib_dirs="$shlib_dirs:/usr/sgitcl:/usr/SGImeeting:/usr/pcp/lib"
127                 shlib_dirs="$shlib_dirs:/usr/Motif-2.1"
128                 interp_dirs='/bin:/usr/bin:/sbin:/usr/sbin:/usr/dt/bin'
129                 ;;
130         *)
131                 echo "I'm sorry.  I haven't been configured yet to work on $osname."
132                 echo "Please poke around your system and try figure out what directories"
133                 echo "I should be searching for shared libraries.  Once you have this"
134                 echo "information, email it to rpm-list@redhat.com, so that your OS"
135                 echo "will be supported by some future version of this script."
136                 echo ""
137                 echo "Thanks!"
138                 echo
139                 exit 2
140                 ;;
141 esac
142
143
144 # allow the user to change defaults with the command line arguments.
145
146 # Loop over all args
147
148 while :
149 do
150
151 # Break out if there are no more args
152         case $# in
153         0)
154                 break
155                 ;;
156         esac
157
158 # Get the first arg, and shuffle
159         option=$1
160         shift
161
162 # Make all options have two hyphens
163         orig_option=$option     # Save original for error messages
164         case $option in
165         --*) ;;
166         -*) option=-$option ;;
167         esac
168
169
170         case $option in
171         --spec_header)
172                 spec_header=$1
173                 shift
174                 ;;
175         --ignore_dirs)
176                 ignore_dirs=$1
177                 shift
178                 ;;
179         --find_provides)
180                 find_provides=$1
181                 shift
182                 ;;
183         --shlib_dirs)
184                 shlib_dirs=$1
185                 shift
186                 ;;
187         --interp_dirs)
188                 interp_dirs=$1
189                 shift
190                 ;;
191         --interps)
192                 interps=$1
193                 shift
194                 ;;
195         --no_verify)
196                 no_verify=1
197                 ;;
198         --help)
199                 echo $usage
200                 exit 0
201                 ;;
202         *)
203                 echo "$0: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
204                 exit 1
205                 ;;
206         esac
207 done
208
209
210 # consistancy checks on the arguments
211
212 if [ ! -f $spec_header ]; then
213         echo "You must pass me the full path to the partial spec file"
214         echo "as my first argument, since this file does not appear in the"
215         echo "default location of $default_spec_header"
216         echo
217         echo $usage
218         echo
219         exit 9
220 fi
221
222
223 if [ ! -f $find_provides ]; then
224         echo "You must pass me the full path to the find-provides script as my"
225         echo "second argument, since find-provides does not appear in the"
226         echo "default location of $default_find_provides"
227         echo
228         echo $usage
229         echo
230         exit 9
231 fi
232
233
234
235 provides_tmp=${TMPDIR:-/tmp}/provides.$$
236 if test -f $provides_tmp ; then
237         echo "$provides_tmp already exists.  Exiting."
238         exit 11
239 fi
240
241 #
242 # iterate through all the directories in shlib_dirs, looking for shared
243 # libraries
244 #
245 for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
246 do
247         find $d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $find_provides >> $provides_tmp
248 done
249
250 sum_tmp=${TMPDIR:-/tmp}/sum.$$
251 if test -f $sum_tmp ; then
252         echo "$sum_tmp already exists.  Exiting."
253         exit 11
254 fi
255
256 #
257 # iterate through all the directories in shlib_dirs, record the sum
258 #
259 for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
260 do
261         find $d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $sum_cmd >> $sum_tmp
262 done
263
264
265 #
266 # output the initial part of the spec file
267 #
268 cat $spec_header
269
270 #
271 # output the 'Provides: ' part of the spec file
272 #
273 {
274     #
275     # Output the shared libraries
276     #
277     for f in `cat $provides_tmp | sort -u`
278     do
279         echo "Provides: $f"
280     done
281
282     #
283     # Output the available shell interpreters
284     #
285     for d in `echo $interp_dirs | sed -e 's/:/ /g'`
286     do
287         for f in `echo $interps | sed -e 's/:/ /g'`
288         do
289                 if test -f $d/$f ; then
290                         echo "Provides: $d/$f"
291                 fi
292         done
293     done
294 } | sed -e 's/%/%%/g'
295
296 #
297 # Output the discription of the spec file
298 #
299
300 cat <<_EIEIO_
301
302
303 %description
304 This is a virtual RPM package.  It contains no actual files.  It uses the
305 \`Provides' token from RPM 3.x and later to list many of the shared libraries
306 and interpreters that are part of the base operating system and associated
307 OS packages for $osname.
308
309 This virtual package was constructed based on the vendor/system software
310 installed on the '$osname' machine named '$hostname', as of the date
311 '$date'.
312
313 Input to the script:
314
315                 spec_header=$spec_header
316                 ignore_dirs=$ignore_dirs
317                 find_provides=$find_provides
318                 shlib_dirs=$shlib_dirs
319                 interp_dirs=$interp_dirs
320                 interps=$interps
321
322 _EIEIO_
323
324 #
325 # Output the build sections of the spec file
326 #
327
328 echo '%prep'
329 echo '# nothing to do'
330 echo '%build'
331 echo '# nothing to do'
332 echo '%install'
333 echo '# nothing to do'
334 echo '%clean'
335 echo '# nothing to do'
336
337 if [ -z "${no_verify}" ]; then
338
339 #
340 # Output the optional verify section of the spec file
341 #
342
343 cat <<_EIEIO_
344
345 %verifyscript
346
347 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bsd
348 export PATH
349
350 sum_current_tmp=\${TMPDIR:-/tmp}/rpm.sum.current.\$\$
351 if test -f \$sum_current_tmp ; then
352         echo "\$sum_current_tmp already exists.  Exiting."
353         exit 11
354 fi
355
356 sum_package_tmp=\${TMPDIR:-/tmp}/rpm.sum.package.\$\$
357 if test -f \$sum_package_tmp ; then
358         echo "\$sum_package_tmp already exists.  Exiting."
359         exit 11
360 fi
361
362 for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
363 do
364         find \$d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $sum_cmd >> \$sum_current_tmp
365 done
366
367 cat >\$sum_package_tmp <<_EOF_
368 _EIEIO_
369
370 # the contents of the temporary file are hardcoded into the verify
371 # script so that the file can be reproduced at verification time.
372
373 cat $sum_tmp | sed -e 's/%/%%/g'
374
375 cat <<_EIEIO_
376 _EOF_
377
378
379 cmp \$sum_package_tmp \$sum_current_tmp 
380
381 if [ \$? -ne 0 ]; then
382         echo"Differences found by: cmp \$sum_package_tmp \$sum_current_tmp"
383         exit \$?
384 fi
385
386 _EIEIO_
387
388 # end optional verify section
389 fi
390
391 #
392 # Output the files section of the spec file
393 #
394
395 echo '%files'
396 echo '# no files in a virtual package'
397
398 exit 0