Home | History | Annotate | Line # | Download | only in sets
syspkgdeps revision 1.9
      1  1.1  dyoung #!/bin/sh
      2  1.1  dyoung #
      3  1.1  dyoung # syspkgdeps [-a arch] [-m machine] [-s setsdir] [-p prefix] sets
      4  1.1  dyoung #
      5  1.1  dyoung # Compute naive package dependencies based on file & directory
      6  1.1  dyoung # nesting. E.g., if pkg P contains /foo/bar and Q contains /foo,
      7  1.1  dyoung # then Q is considered a dependency of P.
      8  1.1  dyoung #
      9  1.1  dyoung 
     10  1.1  dyoung #set -u
     11  1.1  dyoung 
     12  1.1  dyoung #
     13  1.1  dyoung # set defaults and import setlist subroutines
     14  1.1  dyoung #
     15  1.7     apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     16  1.7     apb . "${rundir}/sets.subr"
     17  1.7     apb 
     18  1.1  dyoung 
     19  1.3   lukem usage()
     20  1.3   lukem {
     21  1.3   lukem 	cat 1>&2 <<USAGE
     22  1.3   lukem Usage: ${0##*/} [-a arch] [-m machine] [-s setsdir] [-p prefix] setname [...]
     23  1.9     apb 	-a arch		set arch (e.g, m68k, mips, powerpc)	[${MACHINE_ARCH}]
     24  1.9     apb 	-m machine	set machine (e.g, amiga, i386, macppc)	[${MACHINE}]
     25  1.9     apb 	-s setsdir	directory to find sets			[${setsdir}]
     26  1.9     apb 	-p prefix	prefix for created plist		[${prefix}]
     27  1.3   lukem 	setname [...]	sets to find dependencies for
     28  1.3   lukem USAGE
     29  1.3   lukem 	exit 1
     30  1.1  dyoung }
     31  1.1  dyoung 
     32  1.1  dyoung # parse arguments
     33  1.3   lukem while getopts a:m:ps: ch; do
     34  1.3   lukem 	case ${ch} in
     35  1.3   lukem 	a)
     36  1.9     apb 		MACHINE_ARCH="${OPTARG}"
     37  1.9     apb 		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
     38  1.1  dyoung 		;;
     39  1.3   lukem 	m)
     40  1.9     apb 		MACHINE="${OPTARG}"
     41  1.1  dyoung 		;;
     42  1.3   lukem 	p)
     43  1.9     apb 		prefix="${OPTARG}"
     44  1.1  dyoung 		;;
     45  1.3   lukem 	s)
     46  1.9     apb 		setsdir="${OPTARG}"
     47  1.1  dyoung 		;;
     48  1.3   lukem 	*)
     49  1.1  dyoung 		usage
     50  1.1  dyoung 		;;
     51  1.1  dyoung 	esac
     52  1.1  dyoung done
     53  1.3   lukem shift $((${OPTIND} - 1))
     54  1.1  dyoung if [ $# -lt 1 ]; then
     55  1.1  dyoung 	usage
     56  1.1  dyoung fi
     57  1.1  dyoung 
     58  1.9     apb sets="$*"
     59  1.1  dyoung 
     60  1.1  dyoung # TBD clean up
     61  1.9     apb SCRATCH="$(${MKTEMP} -d "/var/tmp/${0##*/}.XXXXXX")"
     62  1.1  dyoung 
     63  1.1  dyoung [ $? -ne 0 ] && { echo "Could not create scratch directory." 1>&2 ; exit 1 ; }
     64  1.1  dyoung 
     65  1.9     apb PATH_MEMBERSHIP="${SCRATCH}/path-membership"
     66  1.9     apb PATH_TO_PKGNAME="${SCRATCH}/pathpkg.db"
     67  1.9     apb PARENT_PKGNAMES="${SCRATCH}/parent-pkgnames"
     68  1.9     apb PARENT_PATHNAMES="${SCRATCH}/parent-pathnames"
     69  1.1  dyoung 
     70  1.1  dyoung echo "indexing packages by pathnames" 1>&2
     71  1.1  dyoung 
     72  1.9     apb list_set_files ${sets} | ${SED} 's/^\.\///' | \
     73  1.9     apb ${ENV_CMD} PREFIX="${prefix}" ${AWK} '{
     74  1.1  dyoung 	if ($1 == ".") {
     75  1.1  dyoung 		print ENVIRON["PREFIX"] " " $2;
     76  1.1  dyoung 	} else {
     77  1.1  dyoung 		print ENVIRON["PREFIX"] $1 " " $2;
     78  1.1  dyoung 	}
     79  1.9     apb }' | ${SORT} -k 1 -u > "${PATH_MEMBERSHIP}"
     80  1.1  dyoung 
     81  1.9     apb ${DB} -q -w -f - btree "${PATH_TO_PKGNAME}" < "${PATH_MEMBERSHIP}" || \
     82  1.9     apb 	echo "shit" 1>&2
     83  1.1  dyoung 
     84  1.1  dyoung echo "computing parent pathnames" 1>&2
     85  1.1  dyoung 
     86  1.1  dyoung while read pathname pkgname; do
     87  1.1  dyoung 	# print parent pathname
     88  1.9     apb 	echo "${pathname%/*}"
     89  1.9     apb done < "${PATH_MEMBERSHIP}" > "${PARENT_PATHNAMES}"
     90  1.1  dyoung 
     91  1.1  dyoung echo "selecting parent packages using parent pathnames" 1>&2
     92  1.1  dyoung 
     93  1.9     apb ${DB} -q -f - btree "${PATH_TO_PKGNAME}" < "${PARENT_PATHNAMES}" | \
     94  1.9     apb 	${PASTE} "${PATH_MEMBERSHIP}" - | \
     95  1.8     apb 	${AWK} '{ if ($2 != $4) print $2 " " $4; }' | \
     96  1.8     apb 	${SORT} -u | \
     97  1.9     apb 	"${rundir}/culldeps"
     98  1.1  dyoung 
     99  1.1  dyoung if [ $? -ne 0 ]; then
    100  1.1  dyoung 	echo "error in parent-directory lookup, aborting" 1>&2
    101  1.1  dyoung 	exit 1
    102  1.1  dyoung fi
    103