syspkgdeps revision 1.9
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#
15rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
16. "${rundir}/sets.subr"
17
18
19usage()
20{
21	cat 1>&2 <<USAGE
22Usage: ${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
28USAGE
29	exit 1
30}
31
32# parse arguments
33while 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
52done
53shift $((${OPTIND} - 1))
54if [ $# -lt 1 ]; then
55	usage
56fi
57
58sets="$*"
59
60# TBD clean up
61SCRATCH="$(${MKTEMP} -d "/var/tmp/${0##*/}.XXXXXX")"
62
63[ $? -ne 0 ] && { echo "Could not create scratch directory." 1>&2 ; exit 1 ; }
64
65PATH_MEMBERSHIP="${SCRATCH}/path-membership"
66PATH_TO_PKGNAME="${SCRATCH}/pathpkg.db"
67PARENT_PKGNAMES="${SCRATCH}/parent-pkgnames"
68PARENT_PATHNAMES="${SCRATCH}/parent-pathnames"
69
70echo "indexing packages by pathnames" 1>&2
71
72list_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}" || \
82	echo "shit" 1>&2
83
84echo "computing parent pathnames" 1>&2
85
86while read pathname pkgname; do
87	# print parent pathname
88	echo "${pathname%/*}"
89done < "${PATH_MEMBERSHIP}" > "${PARENT_PATHNAMES}"
90
91echo "selecting parent packages using parent pathnames" 1>&2
92
93${DB} -q -f - btree "${PATH_TO_PKGNAME}" < "${PARENT_PATHNAMES}" | \
94	${PASTE} "${PATH_MEMBERSHIP}" - | \
95	${AWK} '{ if ($2 != $4) print $2 " " $4; }' | \
96	${SORT} -u | \
97	"${rundir}/culldeps"
98
99if [ $? -ne 0 ]; then
100	echo "error in parent-directory lookup, aborting" 1>&2
101	exit 1
102fi
103