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