#!/bin/sh

files=""
ports=""
for f in $(find /opt/local/bin -type f) $(find /opt/local/lib -name \*.dylib); do
    if [[ ! -L $f ]] && otool -L $f | grep -q 'libpng1[24]'; then
        files+="\n$f"
        ports+="\n$(port provides $f | cut -d ' ' -f 5)"
    fi
done
for f in $(find /opt/local/lib -name \*.la); do
    if grep -q 'libpng1[24]' $f; then
        files+="\n$f"
        ports+="\n$(port provides $f | cut -d ' ' -f 5)"
    fi
done

if [[ -n "$files" ]]; then
    echo "Files with old libpng references are:"
    echo $files
    echo
    echo "and are provided by these ports:"
    echo $ports | sort -u
else
    echo "No files with old libpng references found."
fi
