#!/bin/sh

# grepl_pkg
# This script searches the bom files in /Library/Receipts
# for the component name given as a command line argument.
# It will show the name of the pkg that contained that component.
#
# Example of use:
# grepl_pkg /Applications/Safari
#
# Cameron Hayne (macdev@hayne.net), Sept 2004
#              revised for Leopard, June 2008
 
name=$1
cd /Library/Receipts
if [ -d boms ]; then  # the 'boms' directory is new with Leopard
    for bom in boms/*.bom; do
        lsbom $bom | grep -q "$name"
        if [ $? = 0 ]; then
            echo "$bom"
        fi
    done
fi
for pkg in *.pkg; do
    find "$pkg" -name '*.bom' -print0 | xargs -0 lsbom | grep -q "$name"
    if [ $? = 0 ]; then
        echo "$pkg"
    fi
done

