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 : ${TOOL_DB=db} 13 DB="${TOOL_DB} -q" 14 15 # 16 # set defaults and import setlist subroutines 17 # 18 . ./sets.subr 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:ps: 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 62 # TBD clean up 63 SCRATCH=$(mktemp -d /var/tmp/$(basename $0).XXXXXX) 64 65 [ $? -ne 0 ] && { echo "Could not create scratch directory." 1>&2 ; exit 1 ; } 66 67 PATH_MEMBERSHIP=$SCRATCH/path-membership 68 PATH_TO_PKGNAME=$SCRATCH/pathpkg.db 69 PARENT_PKGNAMES=$SCRATCH/parent-pkgnames 70 PARENT_PATHNAMES=$SCRATCH/parent-pathnames 71 72 echo "indexing packages by pathnames" 1>&2 73 74 list_set_files $sets | sed 's/^\.\///' | \ 75 env PREFIX=$prefix awk '{ 76 if ($1 == ".") { 77 print ENVIRON["PREFIX"] " " $2; 78 } else { 79 print ENVIRON["PREFIX"] $1 " " $2; 80 } 81 }' | sort -k 1 -u > $PATH_MEMBERSHIP 82 83 $DB -w -f - btree $PATH_TO_PKGNAME < $PATH_MEMBERSHIP || echo "shit" 1>&2 84 85 echo "computing parent pathnames" 1>&2 86 87 while read pathname pkgname; do 88 # print parent pathname 89 dirname $pathname 90 done < $PATH_MEMBERSHIP > $PARENT_PATHNAMES 91 92 echo "selecting parent packages using parent pathnames" 1>&2 93 94 $DB -f - btree $PATH_TO_PKGNAME < $PARENT_PATHNAMES | \ 95 paste $PATH_MEMBERSHIP - | \ 96 awk '{ if ($2 != $4) print $2 " " $4; }' | sort -u | ./culldeps 97 98 if [ $? -ne 0 ]; then 99 echo "error in parent-directory lookup, aborting" 1>&2 100 exit 1 101 fi 102