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