NetBSD/distrib/sets/syspkgdeps
apb 0bee96eab7 Ensure that (almost) all shell variables in distrib/sets/* scripts are
used with curly braces and quotes, as in "${var}".

Also ensure that command substitution is quoted, as in "$(command)", and
convert `command` to $(command).

Reviewed by agc
2006-01-03 18:31:09 +00:00

103 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
#
# syspkgdeps [-a arch] [-m machine] [-s setsdir] [-p prefix] sets
#
# Compute naive package dependencies based on file & directory
# nesting. E.g., if pkg P contains /foo/bar and Q contains /foo,
# then Q is considered a dependency of P.
#
#set -u
#
# set defaults and import setlist subroutines
#
rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
. "${rundir}/sets.subr"
usage()
{
cat 1>&2 <<USAGE
Usage: ${0##*/} [-a arch] [-m machine] [-s setsdir] [-p prefix] setname [...]
-a arch set arch (e.g, m68k, mips, powerpc) [${MACHINE_ARCH}]
-m machine set machine (e.g, amiga, i386, macppc) [${MACHINE}]
-s setsdir directory to find sets [${setsdir}]
-p prefix prefix for created plist [${prefix}]
setname [...] sets to find dependencies for
USAGE
exit 1
}
# parse arguments
while getopts a:m:ps: ch; do
case ${ch} in
a)
MACHINE_ARCH="${OPTARG}"
MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
;;
m)
MACHINE="${OPTARG}"
;;
p)
prefix="${OPTARG}"
;;
s)
setsdir="${OPTARG}"
;;
*)
usage
;;
esac
done
shift $((${OPTIND} - 1))
if [ $# -lt 1 ]; then
usage
fi
sets="$*"
# TBD clean up
SCRATCH="$(${MKTEMP} -d "/var/tmp/${0##*/}.XXXXXX")"
[ $? -ne 0 ] && { echo "Could not create scratch directory." 1>&2 ; exit 1 ; }
PATH_MEMBERSHIP="${SCRATCH}/path-membership"
PATH_TO_PKGNAME="${SCRATCH}/pathpkg.db"
PARENT_PKGNAMES="${SCRATCH}/parent-pkgnames"
PARENT_PATHNAMES="${SCRATCH}/parent-pathnames"
echo "indexing packages by pathnames" 1>&2
list_set_files ${sets} | ${SED} 's/^\.\///' | \
${ENV_CMD} PREFIX="${prefix}" ${AWK} '{
if ($1 == ".") {
print ENVIRON["PREFIX"] " " $2;
} else {
print ENVIRON["PREFIX"] $1 " " $2;
}
}' | ${SORT} -k 1 -u > "${PATH_MEMBERSHIP}"
${DB} -q -w -f - btree "${PATH_TO_PKGNAME}" < "${PATH_MEMBERSHIP}" || \
echo "shit" 1>&2
echo "computing parent pathnames" 1>&2
while read pathname pkgname; do
# print parent pathname
echo "${pathname%/*}"
done < "${PATH_MEMBERSHIP}" > "${PARENT_PATHNAMES}"
echo "selecting parent packages using parent pathnames" 1>&2
${DB} -q -f - btree "${PATH_TO_PKGNAME}" < "${PARENT_PATHNAMES}" | \
${PASTE} "${PATH_MEMBERSHIP}" - | \
${AWK} '{ if ($2 != $4) print $2 " " $4; }' | \
${SORT} -u | \
"${rundir}/culldeps"
if [ $? -ne 0 ]; then
echo "error in parent-directory lookup, aborting" 1>&2
exit 1
fi