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