Skip to content

Instantly share code, notes, and snippets.

@willangley
Created April 24, 2020 13:40
Show Gist options
  • Save willangley/7baa25360d29465afa6b7f102c03831a to your computer and use it in GitHub Desktop.
Save willangley/7baa25360d29465afa6b7f102c03831a to your computer and use it in GitHub Desktop.
find_package_files.bash: Shows files installed by package PKGID that are currently present on the system.
#!/bin/bash
# Copyright 2020 Google LLC.
# SPDX-License-Identifier: Apache-2.0
function usage {
cat <<EOF
Usage:
$(basename $0) PKGID
Shows files installed by package PKGID that are currently present on the system.
EOF
exit 2
}
function find_package_files {
PKGID="$1"
PKGUTIL_INFO=$(mktemp)
pkgutil --pkg-info-plist "$PKGID" >"$PKGUTIL_INFO.plist" || exit $?
VOLUME=$(defaults read "$PKGUTIL_INFO" volume)
LOCATION=$(defaults read "$PKGUTIL_INFO" install-location)
pkgutil --files "$PKGID" | while read file
do
if [ -f "$VOLUME$LOCATION/$file" ]; then
echo "$VOLUME$LOCATION/$file"
fi
done
}
[ -z "$1" ] && { usage; }
find_package_files "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment