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 [ $? -ne 0 ] && { echo "Could not create scratch directory." 1>&2 ; exit 1 ; } 69 70 PATH_MEMBERSHIP="${SCRATCH}/path-membership" 71 PATH_TO_PKGNAME="${SCRATCH}/pathpkg.db" 72 PARENT_PKGNAMES="${SCRATCH}/parent-pkgnames" 73 PARENT_PATHNAMES="${SCRATCH}/parent-pathnames" 74 75 echo "indexing packages by pathnames" 1>&2 76 77 list_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 89 echo "computing parent pathnames" 1>&2 90 91 while read pathname pkgname; do 92 # print parent pathname. 93 # (This uses a cheap implementation of dirname from sets.subr.) 94 dirname "${pathname}" 95 done < "${PATH_MEMBERSHIP}" > "${PARENT_PATHNAMES}" 96 97 echo "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 105 if [ $? -ne 0 ]; then 106 echo "error in parent-directory lookup, aborting" 1>&2 107 exit 1 108 fi 109