csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
#!/bin/sh
2ff057
2ff057
#
2ff057
# Original Author: Tim Mooney (mooney@plains.NoDak.edu)
2ff057
# Improvements by: Ken Estes <kestes@staff.mail.com>
2ff057
# 
2ff057
# This file is distributed under the terms of the GNU General Public License
2ff057
#
2ff057
2ff057
# vpkg-provides.sh is part of RPM, the Red Hat Package Manager.
2ff057
2ff057
# vpkg-provides.sh searches a list of directories (based on what OS
2ff057
# it's being executed on) for shared libraries and interpreter files
2ff057
# that have been installed by some packaging system other than RPM.
2ff057
# It then generates a spec file that can be used to build a "virtual
2ff057
# package" that provides all of these things without actually
2ff057
# installing any files.  The spec file in effect tells rpm what it
2ff057
# needs to know about operating system files which are not under rpm
2ff057
# control.  This makes it much easier to use RPM on non-Linux systems.
2ff057
2ff057
# By default the script also generates a %verifyscript (with hard
2ff057
# coded $shlib_dirs, $ignore_dirs values) which will check that the
2ff057
# checksum of each file in the directories searched has not changed
2ff057
# since the package was built.
2ff057
2ff057
# Comments: This script is a quick hack.  A better solution is to use the
2ff057
# vendor's package management commands to actually query what's installed, and
2ff057
# build one or more spec files based on that.  This is something
2ff057
# I intend to write, probably in perl, but the need for something like this
2ff057
# first effort was great, so I didn't want to wait until the better solution
2ff057
# was done.
2ff057
2ff057
# The complete specfile will be sent to stdout.
2ff057
2ff057
# you will need to create a spec_header for the virtual package.  This
2ff057
# header will provide such specfile information as:
2ff057
#
2ff057
#  Summary: 
2ff057
#  Name: 
2ff057
#  Version: 
2ff057
#  Release: 
2ff057
#  Copyright: 
2ff057
#  Group: 
2ff057
#  Source: 
2ff057
2ff057
2ff057
# most of the command line arguments have defaults
2ff057
2ff057
usage="usage: $0 --spec_header '/path/to/os-base-header.spec' \n"
2ff057
usage="$usage\t[--find_provides '/path/to/find-provides']\n"
2ff057
usage="$usage\t[--shlib_dirs 'dirs:which:contain:shared:libs']\n"
2ff057
usage="$usage\t[--ignore_dirs 'grep-E|pattern|of|paths|to|ignore']\n"
2ff057
2ff057
# these two should be unnecessary as the regular dependency analysis
2ff057
# should take care of interpreters as well as shared libraries.
2ff057
2ff057
usage="$usage\t[--interp_dirs 'dirs:which:contain:interpreters']\n"
2ff057
usage="$usage\t[--interps 'files:to:assume:are:installed']\n"
2ff057
usage="$usage\t[--no_verify]\n"
2ff057
2ff057
2ff057
# this command may not be portable to all OS's, does something else
2ff057
# work? can this be set in the case $osname statement?
2ff057
2ff057
sum_cmd="xargs cksum"
2ff057
2ff057
date=`date`
2ff057
hostname=`uname -n`
2ff057
2ff057
# if some subdirectories of the system directories need to be ignored
2ff057
# (eg /usr/local is a subdirectory of /usr but should not be part of
2ff057
# the virtual package) then call this script with ignore_dirs set to a
2ff057
# valid grep -E pattern which describes the directories to ignore.
2ff057
2ff057
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bsd
2ff057
export PATH
2ff057
2ff057
2ff057
#
2ff057
# The (OS independent) default values.
2ff057
#
2ff057
spec_header='/usr/lib/rpm/os-base-header.spec';
2ff057
interps="sh:csh:ksh:dtksh:wish:tclsh:perl:awk:gawk:nawk:oawk"
2ff057
find_provides='/usr/lib/rpm/find-provides';
2ff057
2ff057
    # no file names begin with this character so it is a good default
2ff057
    # for dirs to ignore.  
2ff057
2ff057
ignore_dirs="@"
2ff057
2ff057
2ff057
osname=`uname -s`
2ff057
if test $? -ne 0 || test X$osname = X ; then
2ff057
	echo "I can't determine what platform this is.  Exiting"
2ff057
	exit 1
2ff057
fi
2ff057
2ff057
2ff057
#
2ff057
# Set OS dependent defaults
2ff057
#
2ff057
case $osname in
2ff057
	OSF1)
2ff057
		shlib_dirs='/shlib:/usr/shlib:/usr/dt/lib:/usr/opt'
2ff057
		interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/bin/posix'
2ff057
		;;
2ff057
	HP-UX)
2ff057
		shlib_dirs='/usr/shlib:/usr/dt/lib:/opt'
2ff057
		shlib_dirs="$shlib_dirs:/usr/bms:/usr/obam:/usr/sam"
2ff057
		interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/bin/posix'
2ff057
		;;
2ff057
	AIX)
2ff057
		shlib_dirs='/usr/lib:/usr/ccs/lib:/usr/dt/lib:/usr/lpp:/usr/opt'
2ff057
		interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin'
2ff057
		;;
2ff057
	SunOS)
2ff057
		shlib_dirs='/etc/lib:/etc/vx:/opt:/usr/lib:/usr/ccs/lib:/usr/dt/lib'
2ff057
		shlib_dirs="$shlib_dirs:/usr/4lib:/usr/openwin/lib:/usr/snadm/lib"
2ff057
		shlib_dirs="$shlib_dirs:/usr/ucblib:/usr/xpg4/lib"
2ff057
		interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/xpg4/bin'
2ff057
		;;
2ff057
	IRIX|IRIX64)
2ff057
		shlib_dirs='/lib:/usr/lib:/usr/lib32:/usr/lib64'
2ff057
		# Irix always makes me laugh...
2ff057
		shlib_dirs="$shlib_dirs:/usr/ToolTalk:/usr/xfsm:/usr/SpeedShop"
2ff057
		shlib_dirs="$shlib_dirs:/usr/sgitcl:/usr/SGImeeting:/usr/pcp/lib"
2ff057
		shlib_dirs="$shlib_dirs:/usr/Motif-2.1"
2ff057
		interp_dirs='/bin:/usr/bin:/sbin:/usr/sbin:/usr/dt/bin'
2ff057
		;;
2ff057
	*)
2ff057
		echo "I'm sorry.  I haven't been configured yet to work on $osname."
2ff057
		echo "Please poke around your system and try figure out what directories"
2ff057
		echo "I should be searching for shared libraries.  Once you have this"
2ff057
		echo "information, email it to rpm-list@redhat.com, so that your OS"
2ff057
		echo "will be supported by some future version of this script."
2ff057
		echo ""
2ff057
		echo "Thanks!"
2ff057
		echo
2ff057
		exit 2
2ff057
		;;
2ff057
esac
2ff057
2ff057
2ff057
# allow the user to change defaults with the command line arguments.
2ff057
2ff057
# Loop over all args
2ff057
2ff057
while :
2ff057
do
2ff057
2ff057
# Break out if there are no more args
2ff057
	case $# in
2ff057
	0)
2ff057
		break
2ff057
		;;
2ff057
	esac
2ff057
2ff057
# Get the first arg, and shuffle
2ff057
	option=$1
2ff057
	shift
2ff057
2ff057
# Make all options have two hyphens
2ff057
	orig_option=$option	# Save original for error messages
2ff057
	case $option in
2ff057
	--*) ;;
2ff057
	-*) option=-$option ;;
2ff057
	esac
2ff057
2ff057
2ff057
	case $option in
2ff057
	--spec_header)
2ff057
		spec_header=$1
2ff057
		shift
2ff057
		;;
2ff057
	--ignore_dirs)
2ff057
		ignore_dirs=$1
2ff057
		shift
2ff057
		;;
2ff057
	--find_provides)
2ff057
		find_provides=$1
2ff057
		shift
2ff057
		;;
2ff057
	--shlib_dirs)
2ff057
		shlib_dirs=$1
2ff057
		shift
2ff057
		;;
2ff057
	--interp_dirs)
2ff057
		interp_dirs=$1
2ff057
		shift
2ff057
		;;
2ff057
	--interps)
2ff057
		interps=$1
2ff057
		shift
2ff057
		;;
2ff057
	--no_verify)
2ff057
		no_verify=1
2ff057
		;;
2ff057
	--help)
2ff057
		echo $usage
2ff057
		exit 0
2ff057
		;;
2ff057
	*)
2ff057
		echo "$0: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
2ff057
		exit 1
2ff057
		;;
2ff057
	esac
2ff057
done
2ff057
2ff057
2ff057
# consistency checks on the arguments
2ff057
2ff057
if [ ! -f $spec_header ]; then
2ff057
	echo "You must pass me the full path to the partial spec file"
2ff057
	echo "as my first argument, since this file does not appear in the"
2ff057
	echo "default location of $default_spec_header"
2ff057
	echo
2ff057
	echo $usage
2ff057
	echo
2ff057
	exit 9
2ff057
fi
2ff057
2ff057
2ff057
if [ ! -f $find_provides ]; then
2ff057
	echo "You must pass me the full path to the find-provides script as my"
2ff057
	echo "second argument, since find-provides does not appear in the"
2ff057
	echo "default location of $default_find_provides"
2ff057
	echo
2ff057
	echo $usage
2ff057
	echo
2ff057
	exit 9
2ff057
fi
2ff057
2ff057
2ff057
2ff057
provides_tmp=${TMPDIR:-/tmp}/provides.$$
2ff057
if test -f $provides_tmp ; then
2ff057
	echo "$provides_tmp already exists.  Exiting."
2ff057
	exit 11
2ff057
fi
2ff057
2ff057
#
2ff057
# iterate through all the directories in shlib_dirs, looking for shared
2ff057
# libraries
2ff057
#
2ff057
for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
2ff057
do
2ff057
	find $d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $find_provides >> $provides_tmp
2ff057
done
2ff057
2ff057
sum_tmp=${TMPDIR:-/tmp}/sum.$$
2ff057
if test -f $sum_tmp ; then
2ff057
	echo "$sum_tmp already exists.  Exiting."
2ff057
	exit 11
2ff057
fi
2ff057
2ff057
#
2ff057
# iterate through all the directories in shlib_dirs, record the sum
2ff057
#
2ff057
for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
2ff057
do
2ff057
	find $d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $sum_cmd >> $sum_tmp
2ff057
done
2ff057
2ff057
2ff057
#
2ff057
# output the initial part of the spec file
2ff057
#
2ff057
cat $spec_header
2ff057
2ff057
#
2ff057
# output the 'Provides: ' part of the spec file
2ff057
#
2ff057
{
2ff057
    #
2ff057
    # Output the shared libraries
2ff057
    #
2ff057
    for f in `cat $provides_tmp | sort -u`
2ff057
    do
2ff057
	echo "Provides: $f"
2ff057
    done
2ff057
2ff057
    #
2ff057
    # Output the available shell interpreters
2ff057
    #
2ff057
    for d in `echo $interp_dirs | sed -e 's/:/ /g'`
2ff057
    do
2ff057
	for f in `echo $interps | sed -e 's/:/ /g'`
2ff057
	do
2ff057
		if test -f $d/$f ; then
2ff057
			echo "Provides: $d/$f"
2ff057
		fi
2ff057
	done
2ff057
    done
2ff057
} | sed -e 's/%/%%/g'
2ff057
2ff057
#
2ff057
# Output the description of the spec file
2ff057
#
2ff057
2ff057
cat <<_EIEIO_
2ff057
2ff057
2ff057
%description
2ff057
This is a virtual RPM package.  It contains no actual files.  It uses the
2ff057
\`Provides' token from RPM 3.x and later to list many of the shared libraries
2ff057
and interpreters that are part of the base operating system and associated
2ff057
OS packages for $osname.
2ff057
2ff057
This virtual package was constructed based on the vendor/system software
2ff057
installed on the '$osname' machine named '$hostname', as of the date
2ff057
'$date'.
2ff057
2ff057
Input to the script:
2ff057
2ff057
                spec_header=$spec_header
2ff057
                ignore_dirs=$ignore_dirs
2ff057
                find_provides=$find_provides
2ff057
                shlib_dirs=$shlib_dirs
2ff057
                interp_dirs=$interp_dirs
2ff057
                interps=$interps
2ff057
2ff057
_EIEIO_
2ff057
2ff057
#
2ff057
# Output the build sections of the spec file
2ff057
#
2ff057
2ff057
echo '%prep'
2ff057
echo '# nothing to do'
2ff057
echo '%build'
2ff057
echo '# nothing to do'
2ff057
echo '%install'
2ff057
echo '# nothing to do'
2ff057
echo '%clean'
2ff057
echo '# nothing to do'
2ff057
2ff057
if [ -z "${no_verify}" ]; then
2ff057
2ff057
#
2ff057
# Output the optional verify section of the spec file
2ff057
#
2ff057
2ff057
cat <<_EIEIO_
2ff057
2ff057
%verifyscript
2ff057
2ff057
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bsd
2ff057
export PATH
2ff057
2ff057
sum_current_tmp=\${TMPDIR:-/tmp}/rpm.sum.current.\$\$
2ff057
if test -f \$sum_current_tmp ; then
2ff057
	echo "\$sum_current_tmp already exists.  Exiting."
2ff057
	exit 11
2ff057
fi
2ff057
2ff057
sum_package_tmp=\${TMPDIR:-/tmp}/rpm.sum.package.\$\$
2ff057
if test -f \$sum_package_tmp ; then
2ff057
	echo "\$sum_package_tmp already exists.  Exiting."
2ff057
	exit 11
2ff057
fi
2ff057
2ff057
for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
2ff057
do
2ff057
	find \$d -type f -print 2>/dev/null | grep -E -v \'$ignore_dirs\' | $sum_cmd >> \$sum_current_tmp
2ff057
done
2ff057
2ff057
cat >\$sum_package_tmp <<_EOF_
2ff057
_EIEIO_
2ff057
2ff057
# the contents of the temporary file are hardcoded into the verify
2ff057
# script so that the file can be reproduced at verification time.
2ff057
2ff057
cat $sum_tmp | sed -e 's/%/%%/g'
2ff057
2ff057
cat <<_EIEIO_
2ff057
_EOF_
2ff057
2ff057
2ff057
cmp \$sum_package_tmp \$sum_current_tmp 
2ff057
2ff057
if [ \$? -ne 0 ]; then
2ff057
	echo"Differences found by: cmp \$sum_package_tmp \$sum_current_tmp"
2ff057
	exit \$?
2ff057
fi
2ff057
2ff057
_EIEIO_
2ff057
2ff057
# end optional verify section
2ff057
fi
2ff057
2ff057
#
2ff057
# Output the files section of the spec file
2ff057
#
2ff057
2ff057
echo '%files'
2ff057
echo '# no files in a virtual package'
2ff057
2ff057
exit 0