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 12prog="${0##*/}" 13rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 14. "${rundir}/sets.subr" 15 16# 17# set defaults 18# 19prefix=/ 20 21usage() 22{ 23 cat 1>&2 <<USAGE 24Usage: ${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 30USAGE 31 exit 1 32} 33 34# parse arguments 35while 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 54done 55shift $((${OPTIND} - 1)) 56if [ $# -lt 1 ]; then 57 usage 58fi 59 60sets="$*" 61case "${sets}" in 62all) sets="${nlists}" ;; 63esac 64 65# TBD clean up 66SCRATCH="$(${MKTEMP} -d "/var/tmp/${prog}.XXXXXX")" 67 68if [ $? -ne 0 ]; then 69 echo >&2 "${prog}: Could not create scratch directory." 70 exit 1 71fi 72 73PATH_MEMBERSHIP="${SCRATCH}/path-membership" 74PATH_TO_PKGNAME="${SCRATCH}/pathpkg.db" 75PARENT_PKGNAMES="${SCRATCH}/parent-pkgnames" 76PARENT_PATHNAMES="${SCRATCH}/parent-pathnames" 77 78echo >&2 "${prog}: indexing packages by pathnames" 79 80list_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 91if [ $? -ne 0 ]; then 92 echo >&2 "${prog}: error creating database, aborting" 93 exit 1 94fi 95 96echo >&2 "${prog}: computing parent pathnames" 97 98while read pathname pkgname; do 99 # print parent pathname. 100 # (This uses a cheap implementation of dirname from sets.subr.) 101 dirname "${pathname}" 102done < "${PATH_MEMBERSHIP}" > "${PARENT_PATHNAMES}" 103 104echo >&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 112if [ $? -ne 0 ]; then 113 echo >&2 "${prog}: error in parent-directory lookup, aborting" 114 exit 1 115fi 116