On Sun, Apr 19, 2020 at 01:34:28PM +0100, Chris Rawnsley wrote:
> I am looking for a way to show a package's dependencies. The output
> might look similar to how -R looks in pkg_info(1), e.g.:
>
> Information for inst:python-3.7.4
>
> Directly depends on:
> bzip2-1.0.8
> gettext-runtime-0.20.1p0
> libffi-3.2.1p5
> sqlite3-3.29.0
> xz-5.2.4
>
> Transitively depends on:
> libiconv-1.16p0
>
> Does such a command such as this already exist?
Way out of my league here, but perhaps:
$ pkg_info -S python-3.7.6p1 | tail -n 2 | tr ',' '\n' | grep @
@bzip2-1.0.8
@gettext-runtime-0.20.1p1
@libffi-3.3
@sqlite3-3.31.1p0
@xz-5.2.4p0
Cheers,
Erling
> I guessed that the
> pkg_* tools would have this covered but I was not able to find it
> in the manpages.
>
> In making the above example, I created a proof of concept shell
> script that demonstrates the desired behaviour. It has limitations
> on what package names it can accept, it only works locally and
> probably has numerous other problems :). It is inlined below.
>
> --
> Chris Rawnsley
>
>
> #!/bin/sh
>
> bin=$(basename "$0")
>
> usage() {
> cat <<EOF
> usage: ${bin} pkg-name
> EOF
> }
>
> PKG_DBDIR=${PKG_DBDIR:-/var/db/pkg}
> direct_deps=$(mktemp -t "${bin}.direct_deps.XXXXXX")
> temp_deps=$(mktemp -t "${bin}.temp_deps.XXXXXX")
> all_deps=$(mktemp -t "${bin}.all_deps.XXXXXX")
>
> cleanup() {
> rm -f "${direct_deps}" "${temp_deps}" "${all_deps}"
> }
> trap cleanup INT TERM QUIT
>
> if ! touch "${direct_deps}" "${temp_deps}" "${all_deps}" 2>/dev/null; then
> printf '%s\n' "${bin}: Unable to make temporary files:"
> cleanup; exit 1
> fi
>
> # Does not account for categories, variants or versions...
> pkg_unresolved=$1
> pkg_dir=$(find "${PKG_DBDIR}" -type d -iname "${pkg_unresolved}-*" -print |
> head -1)
>
> if [ -z "${pkg_dir}" ]; then
> printf '%s\n' "${bin}: unable to find package"
> cleanup; exit 1
> fi
>
> pkg=$(basename "${pkg_dir}")
>
> pkg_requiring="${pkg_dir}/+REQUIRING"
> if [ -s "${pkg_requiring}" ]; then
> sort "${pkg_requiring}" | tee "${temp_deps}" >"${direct_deps}"
> fi
>
> while deps=$(comm -23 "${temp_deps}" "${all_deps}" | grep .); do
> printf '%s\n' ${deps} >>"${all_deps}"
> for d in ${deps}; do
> cat "${PKG_DBDIR}/$d/+REQUIRING" >>"${temp_deps}" 2>/dev/null
> done
> sort -uo "${all_deps}" "${all_deps}"
> sort -uo "${temp_deps}" "${temp_deps}"
> done
>
> printf 'Information for inst:%s\n\n' "${pkg}"
>
> printf 'Directly depends on:\n'
> printf '%s\n' $(cat ${direct_deps})
>
> printf '\n'
>
> printf 'Transitively depends on:\n'
>
> printf '%s\n' $(comm -23 "${all_deps}" "${direct_deps}")
>
> cleanup
>