1 1.1 dyoung #!/bin/sh 2 1.1 dyoung # 3 1.1 dyoung # syspkgdeps [-a arch] [-m machine] [-s setsdir] [-p prefix] sets 4 1.1 dyoung # 5 1.1 dyoung # Compute naive package dependencies based on file & directory 6 1.1 dyoung # nesting. E.g., if pkg P contains /foo/bar and Q contains /foo, 7 1.1 dyoung # then Q is considered a dependency of P. 8 1.1 dyoung # 9 1.1 dyoung 10 1.1 dyoung #set -u 11 1.1 dyoung 12 1.1 dyoung # 13 1.1 dyoung # set defaults and import setlist subroutines 14 1.1 dyoung # 15 1.7 apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 16 1.7 apb . "${rundir}/sets.subr" 17 1.7 apb 18 1.1 dyoung 19 1.3 lukem usage() 20 1.3 lukem { 21 1.3 lukem cat 1>&2 <<USAGE 22 1.3 lukem Usage: ${0##*/} [-a arch] [-m machine] [-s setsdir] [-p prefix] setname [...] 23 1.4 lukem -a arch set arch (e.g, m68k, mips, powerpc) [$MACHINE_ARCH] 24 1.4 lukem -m machine set machine (e.g, amiga, i386, macppc) [$MACHINE] 25 1.3 lukem -s setsdir directory to find sets [$setsdir] 26 1.3 lukem -p prefix prefix for created plist [$prefix] 27 1.3 lukem setname [...] sets to find dependencies for 28 1.3 lukem USAGE 29 1.3 lukem exit 1 30 1.1 dyoung } 31 1.1 dyoung 32 1.1 dyoung # parse arguments 33 1.3 lukem while getopts a:m:ps: ch; do 34 1.3 lukem case ${ch} in 35 1.3 lukem a) 36 1.4 lukem MACHINE_ARCH=${OPTARG} 37 1.4 lukem MACHINE_CPU=$(arch_to_cpu ${OPTARG}) 38 1.1 dyoung ;; 39 1.3 lukem m) 40 1.4 lukem MACHINE=${OPTARG} 41 1.1 dyoung ;; 42 1.3 lukem p) 43 1.3 lukem prefix=${OPTARG} 44 1.1 dyoung ;; 45 1.3 lukem s) 46 1.3 lukem setsdir=${OPTARG} 47 1.1 dyoung ;; 48 1.3 lukem *) 49 1.1 dyoung usage 50 1.1 dyoung ;; 51 1.1 dyoung esac 52 1.1 dyoung done 53 1.3 lukem shift $((${OPTIND} - 1)) 54 1.1 dyoung if [ $# -lt 1 ]; then 55 1.1 dyoung usage 56 1.1 dyoung fi 57 1.1 dyoung 58 1.1 dyoung sets=$@ 59 1.1 dyoung 60 1.1 dyoung # TBD clean up 61 1.8 apb SCRATCH=$(${MKTEMP} -d /var/tmp/$(basename $0).XXXXXX) 62 1.1 dyoung 63 1.1 dyoung [ $? -ne 0 ] && { echo "Could not create scratch directory." 1>&2 ; exit 1 ; } 64 1.1 dyoung 65 1.1 dyoung PATH_MEMBERSHIP=$SCRATCH/path-membership 66 1.1 dyoung PATH_TO_PKGNAME=$SCRATCH/pathpkg.db 67 1.1 dyoung PARENT_PKGNAMES=$SCRATCH/parent-pkgnames 68 1.1 dyoung PARENT_PATHNAMES=$SCRATCH/parent-pathnames 69 1.1 dyoung 70 1.1 dyoung echo "indexing packages by pathnames" 1>&2 71 1.1 dyoung 72 1.8 apb list_set_files $sets | ${SED} 's/^\.\///' | \ 73 1.8 apb ${ENV_CMD} PREFIX=$prefix ${AWK} '{ 74 1.1 dyoung if ($1 == ".") { 75 1.1 dyoung print ENVIRON["PREFIX"] " " $2; 76 1.1 dyoung } else { 77 1.1 dyoung print ENVIRON["PREFIX"] $1 " " $2; 78 1.1 dyoung } 79 1.8 apb }' | ${SORT} -k 1 -u > $PATH_MEMBERSHIP 80 1.1 dyoung 81 1.8 apb $DB -q -w -f - btree $PATH_TO_PKGNAME < $PATH_MEMBERSHIP || echo "shit" 1>&2 82 1.1 dyoung 83 1.1 dyoung echo "computing parent pathnames" 1>&2 84 1.1 dyoung 85 1.1 dyoung while read pathname pkgname; do 86 1.1 dyoung # print parent pathname 87 1.5 erh echo ${pathname%/*} 88 1.1 dyoung done < $PATH_MEMBERSHIP > $PARENT_PATHNAMES 89 1.1 dyoung 90 1.1 dyoung echo "selecting parent packages using parent pathnames" 1>&2 91 1.1 dyoung 92 1.8 apb $DB -q -f - btree $PATH_TO_PKGNAME < $PARENT_PATHNAMES | \ 93 1.8 apb ${PASTE} $PATH_MEMBERSHIP - | \ 94 1.8 apb ${AWK} '{ if ($2 != $4) print $2 " " $4; }' | \ 95 1.8 apb ${SORT} -u | \ 96 1.8 apb $rundir/culldeps 97 1.1 dyoung 98 1.1 dyoung if [ $? -ne 0 ]; then 99 1.1 dyoung echo "error in parent-directory lookup, aborting" 1>&2 100 1.1 dyoung exit 1 101 1.1 dyoung fi 102