syspkgdeps revision 1.10
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 68[ $? -ne 0 ] && { echo "Could not create scratch directory." 1>&2 ; exit 1 ; } 69 70PATH_MEMBERSHIP="${SCRATCH}/path-membership" 71PATH_TO_PKGNAME="${SCRATCH}/pathpkg.db" 72PARENT_PKGNAMES="${SCRATCH}/parent-pkgnames" 73PARENT_PATHNAMES="${SCRATCH}/parent-pathnames" 74 75echo "indexing packages by pathnames" 1>&2 76 77list_set_files ${sets} | ${SED} 's/^\.\///' | \ 78${ENV_CMD} PREFIX="${prefix}" ${AWK} '{ 79 if ($1 == ".") { 80 print ENVIRON["PREFIX"] " " $2; 81 } else { 82 print ENVIRON["PREFIX"] $1 " " $2; 83 } 84}' | ${SORT} -k 1 -u > "${PATH_MEMBERSHIP}" 85 86${DB} -q -w -f - btree "${PATH_TO_PKGNAME}" < "${PATH_MEMBERSHIP}" || \ 87 echo "shit" 1>&2 88 89echo "computing parent pathnames" 1>&2 90 91while read pathname pkgname; do 92 # print parent pathname. 93 # (This uses a cheap implementation of dirname from sets.subr.) 94 dirname "${pathname}" 95done < "${PATH_MEMBERSHIP}" > "${PARENT_PATHNAMES}" 96 97echo "selecting parent packages using parent pathnames" 1>&2 98 99${DB} -q -f - btree "${PATH_TO_PKGNAME}" < "${PARENT_PATHNAMES}" | \ 100 ${PASTE} "${PATH_MEMBERSHIP}" - | \ 101 ${AWK} '{ if ($2 != $4) print $2 " " $4; }' | \ 102 ${SORT} -u | \ 103 ${HOST_SH} "${rundir}/culldeps" 104 105if [ $? -ne 0 ]; then 106 echo "error in parent-directory lookup, aborting" 1>&2 107 exit 1 108fi 109